OmniSciDB  fe05a0c208
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
anonymous_namespace{RelAlgDagBuilder.cpp}::anonymous_namespace{RelAlgDagBuilder.cpp} Namespace Reference

Classes

class  RexInputReplacementVisitor
 
class  CoalesceSecondaryProjectVisitor
 

Functions

std::vector< const Rex * > reproject_targets (const RelProject *simple_project, const std::vector< const Rex * > &target_exprs) noexcept
 
bool input_can_be_coalesced (const RelAlgNode *parent_node, const size_t index, const bool first_rex_is_input)
 
bool is_window_function_sum (const RexScalar *rex)
 
bool is_window_function_operator (const RexScalar *rex)
 

Function Documentation

bool anonymous_namespace{RelAlgDagBuilder.cpp}::anonymous_namespace{RelAlgDagBuilder.cpp}::input_can_be_coalesced ( const RelAlgNode parent_node,
const size_t  index,
const bool  first_rex_is_input 
)

Definition at line 1531 of file RelAlgDagBuilder.cpp.

Referenced by anonymous_namespace{RelAlgDagBuilder.cpp}::coalesce_nodes(), and anonymous_namespace{RelAlgDagBuilder.cpp}::anonymous_namespace{RelAlgDagBuilder.cpp}::CoalesceSecondaryProjectVisitor::visitInput().

1533  {
1534  if (auto agg_node = dynamic_cast<const RelAggregate*>(parent_node)) {
1535  if (index == 0 && agg_node->getGroupByCount() > 0) {
1536  return true;
1537  } else {
1538  // Is an aggregated target, only allow the project to be elided if the aggregate
1539  // target is simply passed through (i.e. if the top level expression attached to
1540  // the project node is a RexInput expression)
1541  return first_rex_is_input;
1542  }
1543  }
1544  return first_rex_is_input;
1545 }

+ Here is the caller graph for this function:

bool anonymous_namespace{RelAlgDagBuilder.cpp}::anonymous_namespace{RelAlgDagBuilder.cpp}::is_window_function_operator ( const RexScalar rex)

Definition at line 1590 of file RelAlgDagBuilder.cpp.

References CHECK_EQ, COUNT, RexOperator::getOperand(), RexOperator::getOperator(), is_window_function_sum(), kCAST, kDIVIDE, and RexOperator::size().

Referenced by RelProject::hasWindowFunctionExpr(), anonymous_namespace{RelAlgDagBuilder.cpp}::separate_window_function_expressions(), anonymous_namespace{RelAlgDagBuilder.cpp}::RexWindowFuncReplacementVisitor::should_replace_operand(), anonymous_namespace{RelAlgDagBuilder.cpp}::WindowFunctionDetectionVisitor::visitCase(), and anonymous_namespace{RelAlgDagBuilder.cpp}::WindowFunctionDetectionVisitor::visitOperator().

1590  {
1591  if (dynamic_cast<const RexWindowFunctionOperator*>(rex)) {
1592  return true;
1593  }
1594 
1595  // unwrap from casts, if they exist
1596  const auto rex_cast = dynamic_cast<const RexOperator*>(rex);
1597  if (rex_cast && rex_cast->getOperator() == kCAST) {
1598  CHECK_EQ(rex_cast->size(), size_t(1));
1599  return is_window_function_operator(rex_cast->getOperand(0));
1600  }
1601 
1602  if (is_window_function_sum(rex)) {
1603  return true;
1604  }
1605  // Check for Window Function AVG:
1606  // (CASE WHEN count > 0 THEN sum ELSE 0) / COUNT
1607  const RexOperator* divide_operator = dynamic_cast<const RexOperator*>(rex);
1608  if (divide_operator && divide_operator->getOperator() == kDIVIDE) {
1609  CHECK_EQ(divide_operator->size(), size_t(2));
1610  const auto case_operator =
1611  dynamic_cast<const RexCase*>(divide_operator->getOperand(0));
1612  const auto second_window =
1613  dynamic_cast<const RexWindowFunctionOperator*>(divide_operator->getOperand(1));
1614  if (case_operator && second_window &&
1615  second_window->getKind() == SqlWindowFunctionKind::COUNT) {
1616  if (is_window_function_sum(case_operator)) {
1617  return true;
1618  }
1619  }
1620  }
1621  return false;
1622 }
#define CHECK_EQ(x, y)
Definition: Logger.h:211
size_t size() const
const RexScalar * getOperand(const size_t idx) const
Definition: sqldefs.h:49
SQLOps getOperator() const

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

bool anonymous_namespace{RelAlgDagBuilder.cpp}::anonymous_namespace{RelAlgDagBuilder.cpp}::is_window_function_sum ( const RexScalar rex)

Definition at line 1576 of file RelAlgDagBuilder.cpp.

References SUM_INTERNAL.

Referenced by is_window_function_operator().

1576  {
1577  const auto case_operator = dynamic_cast<const RexCase*>(rex);
1578  if (case_operator && case_operator->branchCount() == 1) {
1579  const auto then_window =
1580  dynamic_cast<const RexWindowFunctionOperator*>(case_operator->getThen(0));
1581  if (then_window && then_window->getKind() == SqlWindowFunctionKind::SUM_INTERNAL) {
1582  return true;
1583  }
1584  }
1585  return false;
1586 }

+ Here is the caller graph for this function:

std::vector<const Rex*> anonymous_namespace{RelAlgDagBuilder.cpp}::anonymous_namespace{RelAlgDagBuilder.cpp}::reproject_targets ( const RelProject simple_project,
const std::vector< const Rex * > &  target_exprs 
)
noexcept

Definition at line 1282 of file RelAlgDagBuilder.cpp.

References CHECK, CHECK_LT, i, and run_benchmark_import::result.

Referenced by anonymous_namespace{RelAlgDagBuilder.cpp}::create_compound().

1284  {
1285  std::vector<const Rex*> result;
1286  for (size_t i = 0; i < simple_project->size(); ++i) {
1287  const auto input_rex = dynamic_cast<const RexInput*>(simple_project->getProjectAt(i));
1288  CHECK(input_rex);
1289  CHECK_LT(static_cast<size_t>(input_rex->getIndex()), target_exprs.size());
1290  result.push_back(target_exprs[input_rex->getIndex()]);
1291  }
1292  return result;
1293 }
size_t size() const override
const RexScalar * getProjectAt(const size_t idx) const
#define CHECK_LT(x, y)
Definition: Logger.h:213
#define CHECK(condition)
Definition: Logger.h:203

+ Here is the caller graph for this function: