OmniSciDB  06b3bd477c
 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 1498 of file RelAlgDagBuilder.cpp.

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

1500  {
1501  if (auto agg_node = dynamic_cast<const RelAggregate*>(parent_node)) {
1502  if (index == 0 && agg_node->getGroupByCount() > 0) {
1503  return true;
1504  } else {
1505  // Is an aggregated target, only allow the project to be elided if the aggregate
1506  // target is simply passed through (i.e. if the top level expression attached to
1507  // the project node is a RexInput expression)
1508  return first_rex_is_input;
1509  }
1510  }
1511  return first_rex_is_input;
1512 }

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

1557  {
1558  if (dynamic_cast<const RexWindowFunctionOperator*>(rex)) {
1559  return true;
1560  }
1561 
1562  // unwrap from casts, if they exist
1563  const auto rex_cast = dynamic_cast<const RexOperator*>(rex);
1564  if (rex_cast && rex_cast->getOperator() == kCAST) {
1565  CHECK_EQ(rex_cast->size(), size_t(1));
1566  return is_window_function_operator(rex_cast->getOperand(0));
1567  }
1568 
1569  if (is_window_function_sum(rex)) {
1570  return true;
1571  }
1572  // Check for Window Function AVG:
1573  // (CASE WHEN count > 0 THEN sum ELSE 0) / COUNT
1574  const RexOperator* divide_operator = dynamic_cast<const RexOperator*>(rex);
1575  if (divide_operator && divide_operator->getOperator() == kDIVIDE) {
1576  CHECK_EQ(divide_operator->size(), size_t(2));
1577  const auto case_operator =
1578  dynamic_cast<const RexCase*>(divide_operator->getOperand(0));
1579  const auto second_window =
1580  dynamic_cast<const RexWindowFunctionOperator*>(divide_operator->getOperand(1));
1581  if (case_operator && second_window &&
1582  second_window->getKind() == SqlWindowFunctionKind::COUNT) {
1583  if (is_window_function_sum(case_operator)) {
1584  return true;
1585  }
1586  }
1587  }
1588  return false;
1589 }
#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 1543 of file RelAlgDagBuilder.cpp.

References SUM_INTERNAL.

Referenced by is_window_function_operator().

1543  {
1544  const auto case_operator = dynamic_cast<const RexCase*>(rex);
1545  if (case_operator && case_operator->branchCount() == 1) {
1546  const auto then_window =
1547  dynamic_cast<const RexWindowFunctionOperator*>(case_operator->getThen(0));
1548  if (then_window && then_window->getKind() == SqlWindowFunctionKind::SUM_INTERNAL) {
1549  return true;
1550  }
1551  }
1552  return false;
1553 }

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

References CHECK(), CHECK_LT, and run_benchmark_import::result.

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

1251  {
1252  std::vector<const Rex*> result;
1253  for (size_t i = 0; i < simple_project->size(); ++i) {
1254  const auto input_rex = dynamic_cast<const RexInput*>(simple_project->getProjectAt(i));
1255  CHECK(input_rex);
1256  CHECK_LT(static_cast<size_t>(input_rex->getIndex()), target_exprs.size());
1257  result.push_back(target_exprs[input_rex->getIndex()]);
1258  }
1259  return result;
1260 }
size_t size() const override
CHECK(cgen_state)
const RexScalar * getProjectAt(const size_t idx) const
#define CHECK_LT(x, y)
Definition: Logger.h:207

+ Here is the call graph for this function:

+ Here is the caller graph for this function: