OmniSciDB  2e3a973ef4
anonymous_namespace{RelAlgDagBuilder.cpp}::anonymous_namespace{RelAlgDagBuilder.cpp} Namespace Reference

Classes

class  CoalesceSecondaryProjectVisitor
 
class  RexInputReplacementVisitor
 

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

◆ input_can_be_coalesced()

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

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

1507  {
1508  if (auto agg_node = dynamic_cast<const RelAggregate*>(parent_node)) {
1509  if (index == 0 && agg_node->getGroupByCount() > 0) {
1510  return true;
1511  } else {
1512  // Is an aggregated target, only allow the project to be elided if the aggregate
1513  // target is simply passed through (i.e. if the top level expression attached to
1514  // the project node is a RexInput expression)
1515  return first_rex_is_input;
1516  }
1517  }
1518  return first_rex_is_input;
1519 }
+ Here is the caller graph for this function:

◆ is_window_function_operator()

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

Definition at line 1564 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().

1564  {
1565  if (dynamic_cast<const RexWindowFunctionOperator*>(rex)) {
1566  return true;
1567  }
1568 
1569  // unwrap from casts, if they exist
1570  const auto rex_cast = dynamic_cast<const RexOperator*>(rex);
1571  if (rex_cast && rex_cast->getOperator() == kCAST) {
1572  CHECK_EQ(rex_cast->size(), size_t(1));
1573  return is_window_function_operator(rex_cast->getOperand(0));
1574  }
1575 
1576  if (is_window_function_sum(rex)) {
1577  return true;
1578  }
1579  // Check for Window Function AVG:
1580  // (CASE WHEN count > 0 THEN sum ELSE 0) / COUNT
1581  const RexOperator* divide_operator = dynamic_cast<const RexOperator*>(rex);
1582  if (divide_operator && divide_operator->getOperator() == kDIVIDE) {
1583  CHECK_EQ(divide_operator->size(), size_t(2));
1584  const auto case_operator =
1585  dynamic_cast<const RexCase*>(divide_operator->getOperand(0));
1586  const auto second_window =
1587  dynamic_cast<const RexWindowFunctionOperator*>(divide_operator->getOperand(1));
1588  if (case_operator && second_window &&
1589  second_window->getKind() == SqlWindowFunctionKind::COUNT) {
1590  if (is_window_function_sum(case_operator)) {
1591  return true;
1592  }
1593  }
1594  }
1595  return false;
1596 }
SQLOps getOperator() const
#define CHECK_EQ(x, y)
Definition: Logger.h:205
Definition: sqldefs.h:49
const RexScalar * getOperand(const size_t idx) const
size_t size() const
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ is_window_function_sum()

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

Definition at line 1550 of file RelAlgDagBuilder.cpp.

References SUM_INTERNAL.

Referenced by is_window_function_operator().

1550  {
1551  const auto case_operator = dynamic_cast<const RexCase*>(rex);
1552  if (case_operator && case_operator->branchCount() == 1) {
1553  const auto then_window =
1554  dynamic_cast<const RexWindowFunctionOperator*>(case_operator->getThen(0));
1555  if (then_window && then_window->getKind() == SqlWindowFunctionKind::SUM_INTERNAL) {
1556  return true;
1557  }
1558  }
1559  return false;
1560 }
+ Here is the caller graph for this function:

◆ reproject_targets()

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

References CHECK, CHECK_LT, and run_benchmark_import::result.

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

1258  {
1259  std::vector<const Rex*> result;
1260  for (size_t i = 0; i < simple_project->size(); ++i) {
1261  const auto input_rex = dynamic_cast<const RexInput*>(simple_project->getProjectAt(i));
1262  CHECK(input_rex);
1263  CHECK_LT(static_cast<size_t>(input_rex->getIndex()), target_exprs.size());
1264  result.push_back(target_exprs[input_rex->getIndex()]);
1265  }
1266  return result;
1267 }
size_t size() const override
const RexScalar * getProjectAt(const size_t idx) const
#define CHECK_LT(x, y)
Definition: Logger.h:207
#define CHECK(condition)
Definition: Logger.h:197
+ Here is the caller graph for this function: