OmniSciDB  471d68cefb
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups 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 1552 of file RelAlgDagBuilder.cpp.

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

1554  {
1555  if (auto agg_node = dynamic_cast<const RelAggregate*>(parent_node)) {
1556  if (index == 0 && agg_node->getGroupByCount() > 0) {
1557  return true;
1558  } else {
1559  // Is an aggregated target, only allow the project to be elided if the aggregate
1560  // target is simply passed through (i.e. if the top level expression attached to
1561  // the project node is a RexInput expression)
1562  return first_rex_is_input;
1563  }
1564  }
1565  return first_rex_is_input;
1566 }

+ 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 1611 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().

1611  {
1612  if (dynamic_cast<const RexWindowFunctionOperator*>(rex)) {
1613  return true;
1614  }
1615 
1616  // unwrap from casts, if they exist
1617  const auto rex_cast = dynamic_cast<const RexOperator*>(rex);
1618  if (rex_cast && rex_cast->getOperator() == kCAST) {
1619  CHECK_EQ(rex_cast->size(), size_t(1));
1620  return is_window_function_operator(rex_cast->getOperand(0));
1621  }
1622 
1623  if (is_window_function_sum(rex)) {
1624  return true;
1625  }
1626  // Check for Window Function AVG:
1627  // (CASE WHEN count > 0 THEN sum ELSE 0) / COUNT
1628  const RexOperator* divide_operator = dynamic_cast<const RexOperator*>(rex);
1629  if (divide_operator && divide_operator->getOperator() == kDIVIDE) {
1630  CHECK_EQ(divide_operator->size(), size_t(2));
1631  const auto case_operator =
1632  dynamic_cast<const RexCase*>(divide_operator->getOperand(0));
1633  const auto second_window =
1634  dynamic_cast<const RexWindowFunctionOperator*>(divide_operator->getOperand(1));
1635  if (case_operator && second_window &&
1636  second_window->getKind() == SqlWindowFunctionKind::COUNT) {
1637  if (is_window_function_sum(case_operator)) {
1638  return true;
1639  }
1640  }
1641  }
1642  return false;
1643 }
#define CHECK_EQ(x, y)
Definition: Logger.h:217
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 1597 of file RelAlgDagBuilder.cpp.

References SUM_INTERNAL.

Referenced by is_window_function_operator().

1597  {
1598  const auto case_operator = dynamic_cast<const RexCase*>(rex);
1599  if (case_operator && case_operator->branchCount() == 1) {
1600  const auto then_window =
1601  dynamic_cast<const RexWindowFunctionOperator*>(case_operator->getThen(0));
1602  if (then_window && then_window->getKind() == SqlWindowFunctionKind::SUM_INTERNAL) {
1603  return true;
1604  }
1605  }
1606  return false;
1607 }

+ 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 1287 of file RelAlgDagBuilder.cpp.

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

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

1289  {
1290  std::vector<const Rex*> result;
1291  for (size_t i = 0; i < simple_project->size(); ++i) {
1292  const auto input_rex = dynamic_cast<const RexInput*>(simple_project->getProjectAt(i));
1293  CHECK(input_rex);
1294  CHECK_LT(static_cast<size_t>(input_rex->getIndex()), target_exprs.size());
1295  result.push_back(target_exprs[input_rex->getIndex()]);
1296  }
1297  return result;
1298 }
size_t size() const override
const RexScalar * getProjectAt(const size_t idx) const
#define CHECK_LT(x, y)
Definition: Logger.h:219
#define CHECK(condition)
Definition: Logger.h:209

+ Here is the caller graph for this function: