OmniSciDB  b24e664e58
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
RelAlgAbstractInterpreter.cpp File Reference
#include "RelAlgAbstractInterpreter.h"
#include "../Shared/sqldefs.h"
#include "CalciteDeserializerUtils.h"
#include "JsonAccessors.h"
#include "RelAlgExecutor.h"
#include "RelAlgOptimizer.h"
#include "RelLeftDeepInnerJoin.h"
#include "Rendering/RenderRelAlgUtils.h"
#include "RexVisitor.h"
#include <rapidjson/stringbuffer.h>
#include <rapidjson/writer.h>
#include <string>
#include <unordered_set>
+ Include dependency graph for RelAlgAbstractInterpreter.cpp:

Go to the source code of this file.

Classes

class  anonymous_namespace{RelAlgAbstractInterpreter.cpp}::RexRebindInputsVisitor
 
struct  std::hash< std::pair< const RelAlgNode *, int > >
 
class  anonymous_namespace{RelAlgAbstractInterpreter.cpp}::anonymous_namespace{RelAlgAbstractInterpreter.cpp}::RexInputReplacementVisitor
 
class  anonymous_namespace{RelAlgAbstractInterpreter.cpp}::RANodeIterator
 
class  anonymous_namespace{RelAlgAbstractInterpreter.cpp}::anonymous_namespace{RelAlgAbstractInterpreter.cpp}::CoalesceSecondaryProjectVisitor
 
class  anonymous_namespace{RelAlgAbstractInterpreter.cpp}::WindowFunctionDetectionVisitor
 
class  anonymous_namespace{RelAlgAbstractInterpreter.cpp}::RexWindowFuncReplacementVisitor
 
class  anonymous_namespace{RelAlgAbstractInterpreter.cpp}::RexInputBackpropagationVisitor
 
class  anonymous_namespace{RelAlgAbstractInterpreter.cpp}::RelAlgAbstractInterpreter
 

Namespaces

 anonymous_namespace{RelAlgAbstractInterpreter.cpp}
 
 std
 
 anonymous_namespace{RelAlgAbstractInterpreter.cpp}::anonymous_namespace{RelAlgAbstractInterpreter.cpp}
 

Functions

std::vector< RexInputanonymous_namespace{RelAlgAbstractInterpreter.cpp}::n_outputs (const RelAlgNode *node, const size_t n)
 
RANodeOutput get_node_output (const RelAlgNode *ra_node)
 
bool anonymous_namespace{RelAlgAbstractInterpreter.cpp}::isRenamedInput (const RelAlgNode *node, const size_t index, const std::string &new_name)
 
std::set< std::pair< const
RelAlgNode *, int > > 
anonymous_namespace{RelAlgAbstractInterpreter.cpp}::get_equiv_cols (const RelAlgNode *node, const size_t which_col)
 
unsigned anonymous_namespace{RelAlgAbstractInterpreter.cpp}::node_id (const rapidjson::Value &ra_node) noexcept
 
std::unique_ptr< RexAbstractInputanonymous_namespace{RelAlgAbstractInterpreter.cpp}::parse_abstract_input (const rapidjson::Value &expr) noexcept
 
std::unique_ptr< RexLiteralanonymous_namespace{RelAlgAbstractInterpreter.cpp}::parse_literal (const rapidjson::Value &expr)
 
std::unique_ptr< const RexScalaranonymous_namespace{RelAlgAbstractInterpreter.cpp}::parse_scalar_expr (const rapidjson::Value &expr, const Catalog_Namespace::Catalog &cat, RelAlgExecutor *ra_executor)
 
std::unique_ptr< const
RexSubQuery
anonymous_namespace{RelAlgAbstractInterpreter.cpp}::parse_subquery (const rapidjson::Value &expr, const Catalog_Namespace::Catalog &cat, RelAlgExecutor *ra_executor)
 
SQLTypeInfo anonymous_namespace{RelAlgAbstractInterpreter.cpp}::parse_type (const rapidjson::Value &type_obj)
 
std::vector< std::unique_ptr
< const RexScalar > > 
anonymous_namespace{RelAlgAbstractInterpreter.cpp}::parse_expr_array (const rapidjson::Value &arr, const Catalog_Namespace::Catalog &cat, RelAlgExecutor *ra_executor)
 
SqlWindowFunctionKind anonymous_namespace{RelAlgAbstractInterpreter.cpp}::parse_window_function_kind (const std::string &name)
 
std::vector< std::unique_ptr
< const RexScalar > > 
anonymous_namespace{RelAlgAbstractInterpreter.cpp}::parse_window_order_exprs (const rapidjson::Value &arr, const Catalog_Namespace::Catalog &cat, RelAlgExecutor *ra_executor)
 
SortDirection anonymous_namespace{RelAlgAbstractInterpreter.cpp}::parse_sort_direction (const rapidjson::Value &collation)
 
NullSortedPosition anonymous_namespace{RelAlgAbstractInterpreter.cpp}::parse_nulls_position (const rapidjson::Value &collation)
 
std::vector< SortFieldanonymous_namespace{RelAlgAbstractInterpreter.cpp}::parse_window_order_collation (const rapidjson::Value &arr, const Catalog_Namespace::Catalog &cat, RelAlgExecutor *ra_executor)
 
RexWindowFunctionOperator::RexWindowBound anonymous_namespace{RelAlgAbstractInterpreter.cpp}::parse_window_bound (const rapidjson::Value &window_bound_obj, const Catalog_Namespace::Catalog &cat, RelAlgExecutor *ra_executor)
 
std::unique_ptr< RexOperatoranonymous_namespace{RelAlgAbstractInterpreter.cpp}::parse_operator (const rapidjson::Value &expr, const Catalog_Namespace::Catalog &cat, RelAlgExecutor *ra_executor)
 
std::unique_ptr< RexCaseanonymous_namespace{RelAlgAbstractInterpreter.cpp}::parse_case (const rapidjson::Value &expr, const Catalog_Namespace::Catalog &cat, RelAlgExecutor *ra_executor)
 
std::vector< std::string > anonymous_namespace{RelAlgAbstractInterpreter.cpp}::strings_from_json_array (const rapidjson::Value &json_str_arr) noexcept
 
std::vector< size_t > anonymous_namespace{RelAlgAbstractInterpreter.cpp}::indices_from_json_array (const rapidjson::Value &json_idx_arr) noexcept
 
std::string anonymous_namespace{RelAlgAbstractInterpreter.cpp}::json_node_to_string (const rapidjson::Value &node) noexcept
 
std::unique_ptr< const RexAgganonymous_namespace{RelAlgAbstractInterpreter.cpp}::parse_aggregate_expr (const rapidjson::Value &expr)
 
JoinType anonymous_namespace{RelAlgAbstractInterpreter.cpp}::to_join_type (const std::string &join_type_name)
 
std::unique_ptr< const RexScalaranonymous_namespace{RelAlgAbstractInterpreter.cpp}::disambiguate_rex (const RexScalar *, const RANodeOutput &)
 
std::unique_ptr< const
RexOperator
anonymous_namespace{RelAlgAbstractInterpreter.cpp}::disambiguate_operator (const RexOperator *rex_operator, const RANodeOutput &ra_output) noexcept
 
std::unique_ptr< const RexCaseanonymous_namespace{RelAlgAbstractInterpreter.cpp}::disambiguate_case (const RexCase *rex_case, const RANodeOutput &ra_output)
 
void anonymous_namespace{RelAlgAbstractInterpreter.cpp}::bind_project_to_input (RelProject *project_node, const RANodeOutput &input) noexcept
 
void anonymous_namespace{RelAlgAbstractInterpreter.cpp}::bind_table_func_to_input (RelTableFunction *table_func_node, const RANodeOutput &input) noexcept
 
void anonymous_namespace{RelAlgAbstractInterpreter.cpp}::bind_inputs (const std::vector< std::shared_ptr< RelAlgNode >> &nodes) noexcept
 
void anonymous_namespace{RelAlgAbstractInterpreter.cpp}::mark_nops (const std::vector< std::shared_ptr< RelAlgNode >> &nodes) noexcept
 
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
 
void anonymous_namespace{RelAlgAbstractInterpreter.cpp}::create_compound (std::vector< std::shared_ptr< RelAlgNode >> &nodes, const std::vector< size_t > &pattern) noexcept
 
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)
 
bool anonymous_namespace{RelAlgAbstractInterpreter.cpp}::anonymous_namespace{RelAlgAbstractInterpreter.cpp}::is_window_function_sum (const RexScalar *rex)
 
bool anonymous_namespace{RelAlgAbstractInterpreter.cpp}::anonymous_namespace{RelAlgAbstractInterpreter.cpp}::is_window_function_operator (const RexScalar *rex)
 
bool anonymous_namespace{RelAlgAbstractInterpreter.cpp}::anonymous_namespace{RelAlgAbstractInterpreter.cpp}::project_has_window_function_input (const RelProject *ra_project)
 
void anonymous_namespace{RelAlgAbstractInterpreter.cpp}::coalesce_nodes (std::vector< std::shared_ptr< RelAlgNode >> &nodes, const std::vector< const RelAlgNode * > &left_deep_joins)
 
void anonymous_namespace{RelAlgAbstractInterpreter.cpp}::separate_window_function_expressions (std::vector< std::shared_ptr< RelAlgNode >> &nodes)
 
int64_t anonymous_namespace{RelAlgAbstractInterpreter.cpp}::get_int_literal_field (const rapidjson::Value &obj, const char field[], const int64_t default_val) noexcept
 
void anonymous_namespace{RelAlgAbstractInterpreter.cpp}::check_empty_inputs_field (const rapidjson::Value &node) noexcept
 
std::shared_ptr< const RelAlgNodeanonymous_namespace{RelAlgAbstractInterpreter.cpp}::ra_interpret (const rapidjson::Value &query_ast, const Catalog_Namespace::Catalog &cat, RelAlgExecutor *ra_executor, const RenderQueryOptions *render_opts)
 
std::shared_ptr< const RelAlgNodedeserialize_ra_dag (const std::string &query_ra, const Catalog_Namespace::Catalog &cat, RelAlgExecutor *ra_executor, const RenderQueryOptions *render_opts)
 
std::string tree_string (const RelAlgNode *ra, const size_t indent)
 

Variables

const unsigned anonymous_namespace{RelAlgAbstractInterpreter.cpp}::FIRST_RA_NODE_ID = 1
 

Function Documentation

std::shared_ptr<const RelAlgNode> deserialize_ra_dag ( const std::string &  query_ra,
const Catalog_Namespace::Catalog cat,
RelAlgExecutor ra_executor,
const RenderQueryOptions render_opts 
)

Definition at line 2175 of file RelAlgAbstractInterpreter.cpp.

References CHECK(), anonymous_namespace{RelAlgAbstractInterpreter.cpp}::ra_interpret(), and RelAlgNode::resetRelAlgFirstId().

Referenced by RelAlgExecutor::executeRelAlgQueryNoRetry().

2179  {
2180  rapidjson::Document query_ast;
2181  query_ast.Parse(query_ra.c_str());
2182  CHECK(!query_ast.HasParseError());
2183  CHECK(query_ast.IsObject());
2185  return ra_interpret(query_ast, cat, ra_executor, render_opts);
2186 }
CHECK(cgen_state)
std::shared_ptr< const RelAlgNode > ra_interpret(const rapidjson::Value &query_ast, const Catalog_Namespace::Catalog &cat, RelAlgExecutor *ra_executor, const RenderQueryOptions *render_opts)
static void resetRelAlgFirstId() noexcept

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

RANodeOutput get_node_output ( const RelAlgNode ra_node)

Definition at line 109 of file RelAlgAbstractInterpreter.cpp.

References CHECK(), CHECK_EQ, get_node_output(), and anonymous_namespace{RelAlgAbstractInterpreter.cpp}::n_outputs().

Referenced by anonymous_namespace{RelAlgAbstractInterpreter.cpp}::bind_inputs(), anonymous_namespace{RelAlgAbstractInterpreter.cpp}::create_compound(), anonymous_namespace{RelAlgExecutor.cpp}::get_left_deep_join_input_sizes(), get_node_output(), RelProject::isIdentity(), anonymous_namespace{QueryPhysicalInputsCollector.cpp}::RexPhysicalInputsVisitor::visitInput(), and anonymous_namespace{QueryPhysicalInputsCollector.cpp}::RexPhysicalInputsVisitor::visitOperator().

109  {
110  RANodeOutput outputs;
111  const auto scan_node = dynamic_cast<const RelScan*>(ra_node);
112  if (scan_node) {
113  // Scan node has no inputs, output contains all columns in the table.
114  CHECK_EQ(size_t(0), scan_node->inputCount());
115  return n_outputs(scan_node, scan_node->size());
116  }
117  const auto project_node = dynamic_cast<const RelProject*>(ra_node);
118  if (project_node) {
119  // Project output count doesn't depend on the input
120  CHECK_EQ(size_t(1), project_node->inputCount());
121  return n_outputs(project_node, project_node->size());
122  }
123  const auto filter_node = dynamic_cast<const RelFilter*>(ra_node);
124  if (filter_node) {
125  // Filter preserves shape
126  CHECK_EQ(size_t(1), filter_node->inputCount());
127  const auto prev_out = get_node_output(filter_node->getInput(0));
128  return n_outputs(filter_node, prev_out.size());
129  }
130  const auto aggregate_node = dynamic_cast<const RelAggregate*>(ra_node);
131  if (aggregate_node) {
132  // Aggregate output count doesn't depend on the input
133  CHECK_EQ(size_t(1), aggregate_node->inputCount());
134  return n_outputs(aggregate_node, aggregate_node->size());
135  }
136  const auto compound_node = dynamic_cast<const RelCompound*>(ra_node);
137  if (compound_node) {
138  // Compound output count doesn't depend on the input
139  CHECK_EQ(size_t(1), compound_node->inputCount());
140  return n_outputs(compound_node, compound_node->size());
141  }
142  const auto join_node = dynamic_cast<const RelJoin*>(ra_node);
143  if (join_node) {
144  // Join concatenates the outputs from the inputs and the output
145  // directly references the nodes in the input.
146  CHECK_EQ(size_t(2), join_node->inputCount());
147  auto lhs_out =
148  n_outputs(join_node->getInput(0), get_node_output(join_node->getInput(0)).size());
149  const auto rhs_out =
150  n_outputs(join_node->getInput(1), get_node_output(join_node->getInput(1)).size());
151  lhs_out.insert(lhs_out.end(), rhs_out.begin(), rhs_out.end());
152  return lhs_out;
153  }
154  const auto table_func_node = dynamic_cast<const RelTableFunction*>(ra_node);
155  if (table_func_node) {
156  // Table Function output count doesn't depend on the input
157  CHECK_EQ(size_t(1), table_func_node->inputCount());
158  return n_outputs(table_func_node, table_func_node->size());
159  }
160  const auto sort_node = dynamic_cast<const RelSort*>(ra_node);
161  if (sort_node) {
162  // Sort preserves shape
163  CHECK_EQ(size_t(1), sort_node->inputCount());
164  const auto prev_out = get_node_output(sort_node->getInput(0));
165  return n_outputs(sort_node, prev_out.size());
166  }
167  const auto logical_values_node = dynamic_cast<const RelLogicalValues*>(ra_node);
168  if (logical_values_node) {
169  CHECK_EQ(size_t(0), logical_values_node->inputCount());
170  return n_outputs(logical_values_node, logical_values_node->size());
171  }
172  CHECK(false);
173  return outputs;
174 }
#define CHECK_EQ(x, y)
Definition: Logger.h:198
std::vector< RexInput > n_outputs(const RelAlgNode *node, const size_t n)
std::vector< RexInput > RANodeOutput
CHECK(cgen_state)
RANodeOutput get_node_output(const RelAlgNode *ra_node)

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

std::string tree_string ( const RelAlgNode ra,
const size_t  indent 
)

Definition at line 2189 of file RelAlgAbstractInterpreter.cpp.

References RelAlgNode::getInput(), RelAlgNode::inputCount(), run_benchmark_import::result, RelAlgNode::toString(), and tree_string().

Referenced by tree_string().

2189  {
2190  std::string result = std::string(indent, ' ') + ra->toString() + "\n";
2191  for (size_t i = 0; i < ra->inputCount(); ++i) {
2192  result += tree_string(ra->getInput(i), indent + 2);
2193  }
2194  return result;
2195 }
const RelAlgNode * getInput(const size_t idx) const
virtual std::string toString() const =0
std::string tree_string(const RelAlgNode *ra, const size_t indent)
const size_t inputCount() const

+ Here is the call graph for this function:

+ Here is the caller graph for this function: