OmniSciDB  343343d194
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
anonymous_namespace{RelAlgAbstractInterpreter.cpp}::anonymous_namespace{RelAlgAbstractInterpreter.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)
 
bool project_has_window_function_input (const RelProject *ra_project)
 

Function Documentation

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

Definition at line 1186 of file RelAlgAbstractInterpreter.cpp.

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

1188  {
1189  if (auto agg_node = dynamic_cast<const RelAggregate*>(parent_node)) {
1190  if (index == 0 && agg_node->getGroupByCount() > 0) {
1191  return true;
1192  } else {
1193  // Is an aggregated target, only allow the project to be elided if the aggregate
1194  // target is simply passed through (i.e. if the top level expression attached to
1195  // the project node is a RexInput expression)
1196  return first_rex_is_input;
1197  }
1198  }
1199  return first_rex_is_input;
1200 }

+ Here is the caller graph for this function:

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

Definition at line 1245 of file RelAlgAbstractInterpreter.cpp.

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

Referenced by project_has_window_function_input(), anonymous_namespace{RelAlgAbstractInterpreter.cpp}::separate_window_function_expressions(), anonymous_namespace{RelAlgAbstractInterpreter.cpp}::RexWindowFuncReplacementVisitor::should_replace_operand(), anonymous_namespace{RelAlgAbstractInterpreter.cpp}::WindowFunctionDetectionVisitor::visitCase(), and anonymous_namespace{RelAlgAbstractInterpreter.cpp}::WindowFunctionDetectionVisitor::visitOperator().

1245  {
1246  if (dynamic_cast<const RexWindowFunctionOperator*>(rex)) {
1247  return true;
1248  }
1249 
1250  // unwrap from casts, if they exist
1251  const auto rex_cast = dynamic_cast<const RexOperator*>(rex);
1252  if (rex_cast && rex_cast->getOperator() == kCAST) {
1253  CHECK_EQ(rex_cast->size(), size_t(1));
1254  return is_window_function_operator(rex_cast->getOperand(0));
1255  }
1256 
1257  if (is_window_function_sum(rex)) {
1258  return true;
1259  }
1260  // Check for Window Function AVG:
1261  // (CASE WHEN count > 0 THEN sum ELSE 0) / COUNT
1262  const RexOperator* divide_operator = dynamic_cast<const RexOperator*>(rex);
1263  if (divide_operator && divide_operator->getOperator() == kDIVIDE) {
1264  CHECK_EQ(divide_operator->size(), size_t(2));
1265  const auto case_operator =
1266  dynamic_cast<const RexCase*>(divide_operator->getOperand(0));
1267  const auto second_window =
1268  dynamic_cast<const RexWindowFunctionOperator*>(divide_operator->getOperand(1));
1269  if (case_operator && second_window &&
1270  second_window->getKind() == SqlWindowFunctionKind::COUNT) {
1271  if (is_window_function_sum(case_operator)) {
1272  return true;
1273  }
1274  }
1275  }
1276  return false;
1277 }
#define CHECK_EQ(x, y)
Definition: Logger.h:195
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{RelAlgAbstractInterpreter.cpp}::anonymous_namespace{RelAlgAbstractInterpreter.cpp}::is_window_function_sum ( const RexScalar rex)

Definition at line 1231 of file RelAlgAbstractInterpreter.cpp.

References SUM_INTERNAL.

Referenced by is_window_function_operator().

1231  {
1232  const auto case_operator = dynamic_cast<const RexCase*>(rex);
1233  if (case_operator && case_operator->branchCount() == 1) {
1234  const auto then_window =
1235  dynamic_cast<const RexWindowFunctionOperator*>(case_operator->getThen(0));
1236  if (then_window && then_window->getKind() == SqlWindowFunctionKind::SUM_INTERNAL) {
1237  return true;
1238  }
1239  }
1240  return false;
1241 }

+ Here is the caller graph for this function:

bool anonymous_namespace{RelAlgAbstractInterpreter.cpp}::anonymous_namespace{RelAlgAbstractInterpreter.cpp}::project_has_window_function_input ( const RelProject ra_project)
inline

Definition at line 1279 of file RelAlgAbstractInterpreter.cpp.

References RelProject::getProjectAt(), is_window_function_operator(), and RelProject::size().

Referenced by anonymous_namespace{RelAlgAbstractInterpreter.cpp}::coalesce_nodes().

1279  {
1280  for (size_t i = 0; i < ra_project->size(); i++) {
1281  if (is_window_function_operator(ra_project->getProjectAt(i))) {
1282  return true;
1283  }
1284  }
1285  return false;
1286 }
size_t size() const override
const RexScalar * getProjectAt(const size_t idx) const

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

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

Definition at line 937 of file RelAlgAbstractInterpreter.cpp.

References CHECK, CHECK_LT, and run-benchmark-import::result.

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

939  {
940  std::vector<const Rex*> result;
941  for (size_t i = 0; i < simple_project->size(); ++i) {
942  const auto input_rex = dynamic_cast<const RexInput*>(simple_project->getProjectAt(i));
943  CHECK(input_rex);
944  CHECK_LT(static_cast<size_t>(input_rex->getIndex()), target_exprs.size());
945  result.push_back(target_exprs[input_rex->getIndex()]);
946  }
947  return result;
948 }
size_t size() const override
const RexScalar * getProjectAt(const size_t idx) const
#define CHECK_LT(x, y)
Definition: Logger.h:197
#define CHECK(condition)
Definition: Logger.h:187

+ Here is the caller graph for this function: