OmniSciDB  85c2d10cdc
 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 1511 of file RelAlgDagBuilder.cpp.

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

1513  {
1514  if (auto agg_node = dynamic_cast<const RelAggregate*>(parent_node)) {
1515  if (index == 0 && agg_node->getGroupByCount() > 0) {
1516  return true;
1517  } else {
1518  // Is an aggregated target, only allow the project to be elided if the aggregate
1519  // target is simply passed through (i.e. if the top level expression attached to
1520  // the project node is a RexInput expression)
1521  return first_rex_is_input;
1522  }
1523  }
1524  return first_rex_is_input;
1525 }

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

1570  {
1571  if (dynamic_cast<const RexWindowFunctionOperator*>(rex)) {
1572  return true;
1573  }
1574 
1575  // unwrap from casts, if they exist
1576  const auto rex_cast = dynamic_cast<const RexOperator*>(rex);
1577  if (rex_cast && rex_cast->getOperator() == kCAST) {
1578  CHECK_EQ(rex_cast->size(), size_t(1));
1579  return is_window_function_operator(rex_cast->getOperand(0));
1580  }
1581 
1582  if (is_window_function_sum(rex)) {
1583  return true;
1584  }
1585  // Check for Window Function AVG:
1586  // (CASE WHEN count > 0 THEN sum ELSE 0) / COUNT
1587  const RexOperator* divide_operator = dynamic_cast<const RexOperator*>(rex);
1588  if (divide_operator && divide_operator->getOperator() == kDIVIDE) {
1589  CHECK_EQ(divide_operator->size(), size_t(2));
1590  const auto case_operator =
1591  dynamic_cast<const RexCase*>(divide_operator->getOperand(0));
1592  const auto second_window =
1593  dynamic_cast<const RexWindowFunctionOperator*>(divide_operator->getOperand(1));
1594  if (case_operator && second_window &&
1595  second_window->getKind() == SqlWindowFunctionKind::COUNT) {
1596  if (is_window_function_sum(case_operator)) {
1597  return true;
1598  }
1599  }
1600  }
1601  return false;
1602 }
#define CHECK_EQ(x, y)
Definition: Logger.h:205
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 1556 of file RelAlgDagBuilder.cpp.

References SUM_INTERNAL.

Referenced by is_window_function_operator().

1556  {
1557  const auto case_operator = dynamic_cast<const RexCase*>(rex);
1558  if (case_operator && case_operator->branchCount() == 1) {
1559  const auto then_window =
1560  dynamic_cast<const RexWindowFunctionOperator*>(case_operator->getThen(0));
1561  if (then_window && then_window->getKind() == SqlWindowFunctionKind::SUM_INTERNAL) {
1562  return true;
1563  }
1564  }
1565  return false;
1566 }

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

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

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

1264  {
1265  std::vector<const Rex*> result;
1266  for (size_t i = 0; i < simple_project->size(); ++i) {
1267  const auto input_rex = dynamic_cast<const RexInput*>(simple_project->getProjectAt(i));
1268  CHECK(input_rex);
1269  CHECK_LT(static_cast<size_t>(input_rex->getIndex()), target_exprs.size());
1270  result.push_back(target_exprs[input_rex->getIndex()]);
1271  }
1272  return result;
1273 }
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: