OmniSciDB  471d68cefb
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
details::RelAlgDispatcher Class Reference
+ Collaboration diagram for details::RelAlgDispatcher:

Public Member Functions

 RelAlgDispatcher (const Catalog_Namespace::Catalog &cat)
 
std::vector< std::shared_ptr
< RelAlgNode > > 
run (const rapidjson::Value &rels, RelAlgDagBuilder &root_dag_builder)
 

Private Member Functions

std::shared_ptr< RelScandispatchTableScan (const rapidjson::Value &scan_ra)
 
std::shared_ptr< RelProjectdispatchProject (const rapidjson::Value &proj_ra, RelAlgDagBuilder &root_dag_builder)
 
std::shared_ptr< RelFilterdispatchFilter (const rapidjson::Value &filter_ra, RelAlgDagBuilder &root_dag_builder)
 
std::shared_ptr< RelAggregatedispatchAggregate (const rapidjson::Value &agg_ra)
 
std::shared_ptr< RelJoindispatchJoin (const rapidjson::Value &join_ra, RelAlgDagBuilder &root_dag_builder)
 
std::shared_ptr< RelSortdispatchSort (const rapidjson::Value &sort_ra)
 
std::shared_ptr< RelModifydispatchModify (const rapidjson::Value &logical_modify_ra)
 
std::shared_ptr< RelTableFunctiondispatchTableFunction (const rapidjson::Value &table_func_ra, RelAlgDagBuilder &root_dag_builder)
 
std::shared_ptr< RelLogicalValuesdispatchLogicalValues (const rapidjson::Value &logical_values_ra)
 
std::shared_ptr< RelLogicalUniondispatchUnion (const rapidjson::Value &logical_union_ra)
 
RelAlgInputs getRelAlgInputs (const rapidjson::Value &node)
 
std::pair< std::string,
std::string > 
getKVOptionPair (std::string &str, size_t &pos)
 
ExplainedQueryHint parseHintString (std::string &hint_string)
 
void getRelAlgHints (const rapidjson::Value &json_node, std::shared_ptr< RelAlgNode > node)
 
std::shared_ptr< const RelAlgNodeprev (const rapidjson::Value &crt_node)
 

Private Attributes

const Catalog_Namespace::Catalogcat_
 
std::vector< std::shared_ptr
< RelAlgNode > > 
nodes_
 

Detailed Description

Definition at line 2236 of file RelAlgDagBuilder.cpp.

Constructor & Destructor Documentation

details::RelAlgDispatcher::RelAlgDispatcher ( const Catalog_Namespace::Catalog cat)
inline

Definition at line 2238 of file RelAlgDagBuilder.cpp.

2238 : cat_(cat) {}
const Catalog_Namespace::Catalog & cat_

Member Function Documentation

std::shared_ptr<RelAggregate> details::RelAlgDispatcher::dispatchAggregate ( const rapidjson::Value &  agg_ra)
inlineprivate

Definition at line 2326 of file RelAlgDagBuilder.cpp.

References CHECK, CHECK_EQ, field(), getRelAlgHints(), getRelAlgInputs(), i, anonymous_namespace{RelAlgDagBuilder.cpp}::indices_from_json_array(), anonymous_namespace{RelAlgDagBuilder.cpp}::parse_aggregate_expr(), and anonymous_namespace{RelAlgDagBuilder.cpp}::strings_from_json_array().

Referenced by run().

2326  {
2327  const auto inputs = getRelAlgInputs(agg_ra);
2328  CHECK_EQ(size_t(1), inputs.size());
2329  const auto fields = strings_from_json_array(field(agg_ra, "fields"));
2330  const auto group = indices_from_json_array(field(agg_ra, "group"));
2331  for (size_t i = 0; i < group.size(); ++i) {
2332  CHECK_EQ(i, group[i]);
2333  }
2334  if (agg_ra.HasMember("groups") || agg_ra.HasMember("indicator")) {
2335  throw QueryNotSupported("GROUP BY extensions not supported");
2336  }
2337  const auto& aggs_json_arr = field(agg_ra, "aggs");
2338  CHECK(aggs_json_arr.IsArray());
2339  std::vector<std::unique_ptr<const RexAgg>> aggs;
2340  for (auto aggs_json_arr_it = aggs_json_arr.Begin();
2341  aggs_json_arr_it != aggs_json_arr.End();
2342  ++aggs_json_arr_it) {
2343  aggs.emplace_back(parse_aggregate_expr(*aggs_json_arr_it));
2344  }
2345  if (agg_ra.HasMember("hints")) {
2346  auto agg_node =
2347  std::make_shared<RelAggregate>(group.size(), aggs, fields, inputs.front());
2348  getRelAlgHints(agg_ra, agg_node);
2349  return agg_node;
2350  }
2351  return std::make_shared<RelAggregate>(group.size(), aggs, fields, inputs.front());
2352  }
std::vector< std::string > strings_from_json_array(const rapidjson::Value &json_str_arr) noexcept
#define CHECK_EQ(x, y)
Definition: Logger.h:217
std::unique_ptr< const RexAgg > parse_aggregate_expr(const rapidjson::Value &expr)
const rapidjson::Value & field(const rapidjson::Value &obj, const char field[]) noexcept
Definition: JsonAccessors.h:31
std::vector< size_t > indices_from_json_array(const rapidjson::Value &json_idx_arr) noexcept
#define CHECK(condition)
Definition: Logger.h:209
void getRelAlgHints(const rapidjson::Value &json_node, std::shared_ptr< RelAlgNode > node)
RelAlgInputs getRelAlgInputs(const rapidjson::Value &node)

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

std::shared_ptr<RelFilter> details::RelAlgDispatcher::dispatchFilter ( const rapidjson::Value &  filter_ra,
RelAlgDagBuilder root_dag_builder 
)
inlineprivate

Definition at line 2315 of file RelAlgDagBuilder.cpp.

References cat_, CHECK, CHECK_EQ, field(), getRelAlgInputs(), anonymous_namespace{RelAlgDagBuilder.cpp}::node_id(), and anonymous_namespace{RelAlgDagBuilder.cpp}::parse_scalar_expr().

Referenced by run().

2316  {
2317  const auto inputs = getRelAlgInputs(filter_ra);
2318  CHECK_EQ(size_t(1), inputs.size());
2319  const auto id = node_id(filter_ra);
2320  CHECK(id);
2321  auto condition =
2322  parse_scalar_expr(field(filter_ra, "condition"), cat_, root_dag_builder);
2323  return std::make_shared<RelFilter>(condition, inputs.front());
2324  }
#define CHECK_EQ(x, y)
Definition: Logger.h:217
const Catalog_Namespace::Catalog & cat_
const rapidjson::Value & field(const rapidjson::Value &obj, const char field[]) noexcept
Definition: JsonAccessors.h:31
#define CHECK(condition)
Definition: Logger.h:209
std::unique_ptr< const RexScalar > parse_scalar_expr(const rapidjson::Value &expr, const Catalog_Namespace::Catalog &cat, RelAlgDagBuilder &root_dag_builder)
unsigned node_id(const rapidjson::Value &ra_node) noexcept
RelAlgInputs getRelAlgInputs(const rapidjson::Value &node)

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

std::shared_ptr<RelJoin> details::RelAlgDispatcher::dispatchJoin ( const rapidjson::Value &  join_ra,
RelAlgDagBuilder root_dag_builder 
)
inlineprivate

Definition at line 2354 of file RelAlgDagBuilder.cpp.

References cat_, CHECK_EQ, field(), getRelAlgHints(), getRelAlgInputs(), json_str(), anonymous_namespace{RelAlgDagBuilder.cpp}::parse_scalar_expr(), and anonymous_namespace{RelAlgDagBuilder.cpp}::to_join_type().

Referenced by run().

2355  {
2356  const auto inputs = getRelAlgInputs(join_ra);
2357  CHECK_EQ(size_t(2), inputs.size());
2358  const auto join_type = to_join_type(json_str(field(join_ra, "joinType")));
2359  auto filter_rex =
2360  parse_scalar_expr(field(join_ra, "condition"), cat_, root_dag_builder);
2361  if (join_ra.HasMember("hints")) {
2362  auto join_node =
2363  std::make_shared<RelJoin>(inputs[0], inputs[1], filter_rex, join_type);
2364  getRelAlgHints(join_ra, join_node);
2365  return join_node;
2366  }
2367  return std::make_shared<RelJoin>(inputs[0], inputs[1], filter_rex, join_type);
2368  }
#define CHECK_EQ(x, y)
Definition: Logger.h:217
JoinType to_join_type(const std::string &join_type_name)
const Catalog_Namespace::Catalog & cat_
const std::string json_str(const rapidjson::Value &obj) noexcept
Definition: JsonAccessors.h:44
const rapidjson::Value & field(const rapidjson::Value &obj, const char field[]) noexcept
Definition: JsonAccessors.h:31
std::unique_ptr< const RexScalar > parse_scalar_expr(const rapidjson::Value &expr, const Catalog_Namespace::Catalog &cat, RelAlgDagBuilder &root_dag_builder)
void getRelAlgHints(const rapidjson::Value &json_node, std::shared_ptr< RelAlgNode > node)
RelAlgInputs getRelAlgInputs(const rapidjson::Value &node)

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

std::shared_ptr<RelLogicalValues> details::RelAlgDispatcher::dispatchLogicalValues ( const rapidjson::Value &  logical_values_ra)
inlineprivate

Definition at line 2506 of file RelAlgDagBuilder.cpp.

References CHECK, CHECK_EQ, field(), json_str(), anonymous_namespace{RelAlgDagBuilder.cpp}::parse_literal(), and anonymous_namespace{RelAlgDagBuilder.cpp}::parse_type().

Referenced by run().

2507  {
2508  const auto& tuple_type_arr = field(logical_values_ra, "type");
2509  CHECK(tuple_type_arr.IsArray());
2510  std::vector<TargetMetaInfo> tuple_type;
2511  for (auto tuple_type_arr_it = tuple_type_arr.Begin();
2512  tuple_type_arr_it != tuple_type_arr.End();
2513  ++tuple_type_arr_it) {
2514  const auto component_type = parse_type(*tuple_type_arr_it);
2515  const auto component_name = json_str(field(*tuple_type_arr_it, "name"));
2516  tuple_type.emplace_back(component_name, component_type);
2517  }
2518  const auto& inputs_arr = field(logical_values_ra, "inputs");
2519  CHECK(inputs_arr.IsArray());
2520  const auto& tuples_arr = field(logical_values_ra, "tuples");
2521  CHECK(tuples_arr.IsArray());
2522 
2523  if (inputs_arr.Size()) {
2524  throw QueryNotSupported("Inputs not supported in logical values yet.");
2525  }
2526 
2527  std::vector<RelLogicalValues::RowValues> values;
2528  if (tuples_arr.Size()) {
2529  for (const auto& row : tuples_arr.GetArray()) {
2530  CHECK(row.IsArray());
2531  const auto values_json = row.GetArray();
2532  if (!values.empty()) {
2533  CHECK_EQ(values[0].size(), values_json.Size());
2534  }
2535  values.emplace_back(RelLogicalValues::RowValues{});
2536  for (const auto& value : values_json) {
2537  CHECK(value.IsObject());
2538  CHECK(value.HasMember("literal"));
2539  values.back().emplace_back(parse_literal(value));
2540  }
2541  }
2542  }
2543 
2544  return std::make_shared<RelLogicalValues>(tuple_type, values);
2545  }
SQLTypeInfo parse_type(const rapidjson::Value &type_obj)
#define CHECK_EQ(x, y)
Definition: Logger.h:217
const std::string json_str(const rapidjson::Value &obj) noexcept
Definition: JsonAccessors.h:44
const rapidjson::Value & field(const rapidjson::Value &obj, const char field[]) noexcept
Definition: JsonAccessors.h:31
std::unique_ptr< RexLiteral > parse_literal(const rapidjson::Value &expr)
#define CHECK(condition)
Definition: Logger.h:209
std::vector< std::unique_ptr< const RexScalar >> RowValues

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

std::shared_ptr<RelModify> details::RelAlgDispatcher::dispatchModify ( const rapidjson::Value &  logical_modify_ra)
inlineprivate

Definition at line 2392 of file RelAlgDagBuilder.cpp.

References cat_, CHECK, CHECK_EQ, RelModify::Delete, field(), getRelAlgInputs(), anonymous_namespace{RelAlgDagBuilder.cpp}::getTableFromScanNode(), json_bool(), anonymous_namespace{RelAlgDagBuilder.cpp}::json_node_to_string(), json_str(), and RelModify::Update.

Referenced by run().

2392  {
2393  const auto inputs = getRelAlgInputs(logical_modify_ra);
2394  CHECK_EQ(size_t(1), inputs.size());
2395 
2396  const auto table_descriptor = getTableFromScanNode(cat_, logical_modify_ra);
2397  if (table_descriptor->isView) {
2398  throw std::runtime_error("UPDATE of a view is unsupported.");
2399  }
2400 
2401  bool flattened = json_bool(field(logical_modify_ra, "flattened"));
2402  std::string op = json_str(field(logical_modify_ra, "operation"));
2403  RelModify::TargetColumnList target_column_list;
2404 
2405  if (op == "UPDATE") {
2406  const auto& update_columns = field(logical_modify_ra, "updateColumnList");
2407  CHECK(update_columns.IsArray());
2408 
2409  for (auto column_arr_it = update_columns.Begin();
2410  column_arr_it != update_columns.End();
2411  ++column_arr_it) {
2412  target_column_list.push_back(column_arr_it->GetString());
2413  }
2414  }
2415 
2416  auto modify_node = std::make_shared<RelModify>(
2417  cat_, table_descriptor, flattened, op, target_column_list, inputs[0]);
2418  switch (modify_node->getOperation()) {
2420  modify_node->applyDeleteModificationsToInputNode();
2421  break;
2422  }
2424  modify_node->applyUpdateModificationsToInputNode();
2425  break;
2426  }
2427  default:
2428  throw std::runtime_error("Unsupported RelModify operation: " +
2429  json_node_to_string(logical_modify_ra));
2430  }
2431 
2432  return modify_node;
2433  }
#define CHECK_EQ(x, y)
Definition: Logger.h:217
const Catalog_Namespace::Catalog & cat_
std::vector< std::string > TargetColumnList
const bool json_bool(const rapidjson::Value &obj) noexcept
Definition: JsonAccessors.h:49
const std::string json_str(const rapidjson::Value &obj) noexcept
Definition: JsonAccessors.h:44
const rapidjson::Value & field(const rapidjson::Value &obj, const char field[]) noexcept
Definition: JsonAccessors.h:31
const TableDescriptor * getTableFromScanNode(const Catalog_Namespace::Catalog &cat, const rapidjson::Value &scan_ra)
#define CHECK(condition)
Definition: Logger.h:209
RelAlgInputs getRelAlgInputs(const rapidjson::Value &node)
std::string json_node_to_string(const rapidjson::Value &node) noexcept

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

std::shared_ptr<RelProject> details::RelAlgDispatcher::dispatchProject ( const rapidjson::Value &  proj_ra,
RelAlgDagBuilder root_dag_builder 
)
inlineprivate

Definition at line 2293 of file RelAlgDagBuilder.cpp.

References cat_, CHECK, CHECK_EQ, field(), getRelAlgHints(), getRelAlgInputs(), anonymous_namespace{RelAlgDagBuilder.cpp}::parse_scalar_expr(), and anonymous_namespace{RelAlgDagBuilder.cpp}::strings_from_json_array().

Referenced by run().

2294  {
2295  const auto inputs = getRelAlgInputs(proj_ra);
2296  CHECK_EQ(size_t(1), inputs.size());
2297  const auto& exprs_json = field(proj_ra, "exprs");
2298  CHECK(exprs_json.IsArray());
2299  std::vector<std::unique_ptr<const RexScalar>> exprs;
2300  for (auto exprs_json_it = exprs_json.Begin(); exprs_json_it != exprs_json.End();
2301  ++exprs_json_it) {
2302  exprs.emplace_back(parse_scalar_expr(*exprs_json_it, cat_, root_dag_builder));
2303  }
2304  const auto& fields = field(proj_ra, "fields");
2305  if (proj_ra.HasMember("hints")) {
2306  auto project_node = std::make_shared<RelProject>(
2307  exprs, strings_from_json_array(fields), inputs.front());
2308  getRelAlgHints(proj_ra, project_node);
2309  return project_node;
2310  }
2311  return std::make_shared<RelProject>(
2312  exprs, strings_from_json_array(fields), inputs.front());
2313  }
std::vector< std::string > strings_from_json_array(const rapidjson::Value &json_str_arr) noexcept
#define CHECK_EQ(x, y)
Definition: Logger.h:217
const Catalog_Namespace::Catalog & cat_
const rapidjson::Value & field(const rapidjson::Value &obj, const char field[]) noexcept
Definition: JsonAccessors.h:31
#define CHECK(condition)
Definition: Logger.h:209
std::unique_ptr< const RexScalar > parse_scalar_expr(const rapidjson::Value &expr, const Catalog_Namespace::Catalog &cat, RelAlgDagBuilder &root_dag_builder)
void getRelAlgHints(const rapidjson::Value &json_node, std::shared_ptr< RelAlgNode > node)
RelAlgInputs getRelAlgInputs(const rapidjson::Value &node)

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

std::shared_ptr<RelSort> details::RelAlgDispatcher::dispatchSort ( const rapidjson::Value &  sort_ra)
inlineprivate

Definition at line 2370 of file RelAlgDagBuilder.cpp.

References CHECK, CHECK_EQ, field(), anonymous_namespace{RelAlgDagBuilder.cpp}::get_int_literal_field(), getRelAlgInputs(), json_i64(), anonymous_namespace{RelAlgDagBuilder.cpp}::parse_nulls_position(), and anonymous_namespace{RelAlgDagBuilder.cpp}::parse_sort_direction().

Referenced by run().

2370  {
2371  const auto inputs = getRelAlgInputs(sort_ra);
2372  CHECK_EQ(size_t(1), inputs.size());
2373  std::vector<SortField> collation;
2374  const auto& collation_arr = field(sort_ra, "collation");
2375  CHECK(collation_arr.IsArray());
2376  for (auto collation_arr_it = collation_arr.Begin();
2377  collation_arr_it != collation_arr.End();
2378  ++collation_arr_it) {
2379  const size_t field_idx = json_i64(field(*collation_arr_it, "field"));
2380  const auto sort_dir = parse_sort_direction(*collation_arr_it);
2381  const auto null_pos = parse_nulls_position(*collation_arr_it);
2382  collation.emplace_back(field_idx, sort_dir, null_pos);
2383  }
2384  auto limit = get_int_literal_field(sort_ra, "fetch", -1);
2385  const auto offset = get_int_literal_field(sort_ra, "offset", 0);
2386  auto ret = std::make_shared<RelSort>(
2387  collation, limit > 0 ? limit : 0, offset, inputs.front());
2388  ret->setEmptyResult(limit == 0);
2389  return ret;
2390  }
#define CHECK_EQ(x, y)
Definition: Logger.h:217
int64_t get_int_literal_field(const rapidjson::Value &obj, const char field[], const int64_t default_val) noexcept
const rapidjson::Value & field(const rapidjson::Value &obj, const char field[]) noexcept
Definition: JsonAccessors.h:31
SortDirection parse_sort_direction(const rapidjson::Value &collation)
const int64_t json_i64(const rapidjson::Value &obj) noexcept
Definition: JsonAccessors.h:39
NullSortedPosition parse_nulls_position(const rapidjson::Value &collation)
#define CHECK(condition)
Definition: Logger.h:209
RelAlgInputs getRelAlgInputs(const rapidjson::Value &node)

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

std::shared_ptr<RelTableFunction> details::RelAlgDispatcher::dispatchTableFunction ( const rapidjson::Value &  table_func_ra,
RelAlgDagBuilder root_dag_builder 
)
inlineprivate

Definition at line 2435 of file RelAlgDagBuilder.cpp.

References cat_, CHECK, CHECK_GE, CHECK_LT, field(), getRelAlgInputs(), i, json_str(), and anonymous_namespace{RelAlgDagBuilder.cpp}::parse_scalar_expr().

Referenced by run().

2437  {
2438  const auto inputs = getRelAlgInputs(table_func_ra);
2439  const auto& invocation = field(table_func_ra, "invocation");
2440  CHECK(invocation.IsObject());
2441 
2442  const auto& operands = field(invocation, "operands");
2443  CHECK(operands.IsArray());
2444  CHECK_GE(operands.Size(), unsigned(0));
2445 
2446  std::vector<const Rex*> col_inputs;
2447  std::vector<std::unique_ptr<const RexScalar>> table_func_inputs;
2448  std::vector<std::string> fields;
2449 
2450  for (auto exprs_json_it = operands.Begin(); exprs_json_it != operands.End();
2451  ++exprs_json_it) {
2452  const auto& expr_json = *exprs_json_it;
2453  CHECK(expr_json.IsObject());
2454  if (expr_json.HasMember("op")) {
2455  const auto op_str = json_str(field(expr_json, "op"));
2456  if (op_str == "CAST" && expr_json.HasMember("type")) {
2457  const auto& expr_type = field(expr_json, "type");
2458  CHECK(expr_type.IsObject());
2459  CHECK(expr_type.HasMember("type"));
2460  const auto& expr_type_name = json_str(field(expr_type, "type"));
2461  if (expr_type_name == "CURSOR") {
2462  CHECK(expr_json.HasMember("operands"));
2463  const auto& expr_operands = field(expr_json, "operands");
2464  CHECK(expr_operands.IsArray());
2465  if (expr_operands.Size() != 1) {
2466  throw std::runtime_error(
2467  "Table functions currently only support one ResultSet input");
2468  }
2469  auto pos = field(expr_operands[0], "input").GetInt();
2470  CHECK_LT(pos, inputs.size());
2471  for (size_t i = inputs[pos]->size(); i > 0; i--) {
2472  table_func_inputs.emplace_back(
2473  std::make_unique<RexAbstractInput>(col_inputs.size()));
2474  col_inputs.emplace_back(table_func_inputs.back().get());
2475  }
2476  continue;
2477  }
2478  }
2479  }
2480  table_func_inputs.emplace_back(
2481  parse_scalar_expr(*exprs_json_it, cat_, root_dag_builder));
2482  }
2483 
2484  const auto& op_name = field(invocation, "op");
2485  CHECK(op_name.IsString());
2486 
2487  std::vector<std::unique_ptr<const RexScalar>> table_function_projected_outputs;
2488  const auto& row_types = field(table_func_ra, "rowType");
2489  CHECK(row_types.IsArray());
2490  CHECK_GE(row_types.Size(), unsigned(0));
2491  const auto& row_types_array = row_types.GetArray();
2492  for (size_t i = 0; i < row_types_array.Size(); i++) {
2493  // We don't care about the type information in rowType -- replace each output with
2494  // a reference to be resolved later in the translator
2495  table_function_projected_outputs.emplace_back(std::make_unique<RexRef>(i));
2496  fields.emplace_back("");
2497  }
2498  return std::make_shared<RelTableFunction>(op_name.GetString(),
2499  inputs,
2500  fields,
2501  col_inputs,
2502  table_func_inputs,
2503  table_function_projected_outputs);
2504  }
const Catalog_Namespace::Catalog & cat_
const std::string json_str(const rapidjson::Value &obj) noexcept
Definition: JsonAccessors.h:44
#define CHECK_GE(x, y)
Definition: Logger.h:222
const rapidjson::Value & field(const rapidjson::Value &obj, const char field[]) noexcept
Definition: JsonAccessors.h:31
#define CHECK_LT(x, y)
Definition: Logger.h:219
#define CHECK(condition)
Definition: Logger.h:209
std::unique_ptr< const RexScalar > parse_scalar_expr(const rapidjson::Value &expr, const Catalog_Namespace::Catalog &cat, RelAlgDagBuilder &root_dag_builder)
RelAlgInputs getRelAlgInputs(const rapidjson::Value &node)

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

std::shared_ptr<RelScan> details::RelAlgDispatcher::dispatchTableScan ( const rapidjson::Value &  scan_ra)
inlineprivate

Definition at line 2280 of file RelAlgDagBuilder.cpp.

References cat_, CHECK, anonymous_namespace{RelAlgDagBuilder.cpp}::check_empty_inputs_field(), anonymous_namespace{RelAlgDagBuilder.cpp}::getFieldNamesFromScanNode(), getRelAlgHints(), and anonymous_namespace{RelAlgDagBuilder.cpp}::getTableFromScanNode().

Referenced by run().

2280  {
2281  check_empty_inputs_field(scan_ra);
2282  CHECK(scan_ra.IsObject());
2283  const auto td = getTableFromScanNode(cat_, scan_ra);
2284  const auto field_names = getFieldNamesFromScanNode(scan_ra);
2285  if (scan_ra.HasMember("hints")) {
2286  auto scan_node = std::make_shared<RelScan>(td, field_names);
2287  getRelAlgHints(scan_ra, scan_node);
2288  return scan_node;
2289  }
2290  return std::make_shared<RelScan>(td, field_names);
2291  }
const Catalog_Namespace::Catalog & cat_
const TableDescriptor * getTableFromScanNode(const Catalog_Namespace::Catalog &cat, const rapidjson::Value &scan_ra)
#define CHECK(condition)
Definition: Logger.h:209
std::vector< std::string > getFieldNamesFromScanNode(const rapidjson::Value &scan_ra)
void getRelAlgHints(const rapidjson::Value &json_node, std::shared_ptr< RelAlgNode > node)
void check_empty_inputs_field(const rapidjson::Value &node) noexcept

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

std::shared_ptr<RelLogicalUnion> details::RelAlgDispatcher::dispatchUnion ( const rapidjson::Value &  logical_union_ra)
inlineprivate

Definition at line 2547 of file RelAlgDagBuilder.cpp.

References CHECK, field(), and getRelAlgInputs().

Referenced by run().

2548  {
2549  auto inputs = getRelAlgInputs(logical_union_ra);
2550  auto const& all_type_bool = field(logical_union_ra, "all");
2551  CHECK(all_type_bool.IsBool());
2552  return std::make_shared<RelLogicalUnion>(std::move(inputs), all_type_bool.GetBool());
2553  }
const rapidjson::Value & field(const rapidjson::Value &obj, const char field[]) noexcept
Definition: JsonAccessors.h:31
#define CHECK(condition)
Definition: Logger.h:209
RelAlgInputs getRelAlgInputs(const rapidjson::Value &node)

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

std::pair<std::string, std::string> details::RelAlgDispatcher::getKVOptionPair ( std::string &  str,
size_t &  pos 
)
inlineprivate

Definition at line 2567 of file RelAlgDagBuilder.cpp.

Referenced by parseHintString().

2567  {
2568  auto option = str.substr(0, pos);
2569  std::string delim = "=";
2570  size_t delim_pos = option.find(delim);
2571  auto key = option.substr(0, delim_pos);
2572  auto val = option.substr(delim_pos + 1, option.length());
2573  str.erase(0, pos + delim.length() + 1);
2574  return {key, val};
2575  }

+ Here is the caller graph for this function:

void details::RelAlgDispatcher::getRelAlgHints ( const rapidjson::Value &  json_node,
std::shared_ptr< RelAlgNode node 
)
inlineprivate

Definition at line 2626 of file RelAlgDagBuilder.cpp.

References field(), json_str(), and parseHintString().

Referenced by dispatchAggregate(), dispatchJoin(), dispatchProject(), and dispatchTableScan().

2627  {
2628  std::string hint_explained = json_str(field(json_node, "hints"));
2629  size_t pos = 0;
2630  std::string delim = "|";
2631  std::vector<std::string> hint_list;
2632  while ((pos = hint_explained.find(delim)) != std::string::npos) {
2633  hint_list.emplace_back(hint_explained.substr(0, pos));
2634  hint_explained.erase(0, pos + delim.length());
2635  }
2636  // handling the last one
2637  hint_list.emplace_back(hint_explained.substr(0, pos));
2638 
2639  const auto agg_node = std::dynamic_pointer_cast<RelAggregate>(node);
2640  if (agg_node) {
2641  for (std::string& hint : hint_list) {
2642  auto parsed_hint = parseHintString(hint);
2643  agg_node->addHint(parsed_hint);
2644  }
2645  }
2646  const auto project_node = std::dynamic_pointer_cast<RelProject>(node);
2647  if (project_node) {
2648  for (std::string& hint : hint_list) {
2649  auto parsed_hint = parseHintString(hint);
2650  project_node->addHint(parsed_hint);
2651  }
2652  }
2653  const auto scan_node = std::dynamic_pointer_cast<RelScan>(node);
2654  if (scan_node) {
2655  for (std::string& hint : hint_list) {
2656  auto parsed_hint = parseHintString(hint);
2657  scan_node->addHint(parsed_hint);
2658  }
2659  }
2660  const auto join_node = std::dynamic_pointer_cast<RelJoin>(node);
2661  if (join_node) {
2662  for (std::string& hint : hint_list) {
2663  auto parsed_hint = parseHintString(hint);
2664  join_node->addHint(parsed_hint);
2665  }
2666  }
2667 
2668  const auto compound_node = std::dynamic_pointer_cast<RelCompound>(node);
2669  if (compound_node) {
2670  for (std::string& hint : hint_list) {
2671  auto parsed_hint = parseHintString(hint);
2672  compound_node->addHint(parsed_hint);
2673  }
2674  }
2675  }
const std::string json_str(const rapidjson::Value &obj) noexcept
Definition: JsonAccessors.h:44
const rapidjson::Value & field(const rapidjson::Value &obj, const char field[]) noexcept
Definition: JsonAccessors.h:31
ExplainedQueryHint parseHintString(std::string &hint_string)

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

RelAlgInputs details::RelAlgDispatcher::getRelAlgInputs ( const rapidjson::Value &  node)
inlineprivate

Definition at line 2555 of file RelAlgDagBuilder.cpp.

References field(), nodes_, prev(), and anonymous_namespace{RelAlgDagBuilder.cpp}::strings_from_json_array().

Referenced by dispatchAggregate(), dispatchFilter(), dispatchJoin(), dispatchModify(), dispatchProject(), dispatchSort(), dispatchTableFunction(), and dispatchUnion().

2555  {
2556  if (node.HasMember("inputs")) {
2557  const auto str_input_ids = strings_from_json_array(field(node, "inputs"));
2558  RelAlgInputs ra_inputs;
2559  for (const auto& str_id : str_input_ids) {
2560  ra_inputs.push_back(nodes_[std::stoi(str_id)]);
2561  }
2562  return ra_inputs;
2563  }
2564  return {prev(node)};
2565  }
std::vector< std::string > strings_from_json_array(const rapidjson::Value &json_str_arr) noexcept
const rapidjson::Value & field(const rapidjson::Value &obj, const char field[]) noexcept
Definition: JsonAccessors.h:31
std::vector< std::shared_ptr< RelAlgNode > > nodes_
std::vector< std::shared_ptr< const RelAlgNode >> RelAlgInputs
std::shared_ptr< const RelAlgNode > prev(const rapidjson::Value &crt_node)

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

ExplainedQueryHint details::RelAlgDispatcher::parseHintString ( std::string &  hint_string)
inlineprivate

Definition at line 2577 of file RelAlgDagBuilder.cpp.

References CHECK, getKVOptionPair(), and RegisteredQueryHint::translateQueryHint().

Referenced by getRelAlgHints().

2577  {
2578  std::string white_space_delim = " ";
2579  int l = hint_string.length();
2580  hint_string = hint_string.erase(0, 1).substr(0, l - 2);
2581  size_t pos = 0;
2582  if ((pos = hint_string.find("options:")) != std::string::npos) {
2583  // need to parse hint options
2584  std::vector<std::string> tokens;
2585  std::string hint_name = hint_string.substr(0, hint_string.find(white_space_delim));
2586  auto hint_type = RegisteredQueryHint::translateQueryHint(hint_name);
2587  bool kv_list_op = false;
2588  std::string raw_options = hint_string.substr(pos + 8, hint_string.length() - 2);
2589  if (raw_options.find('{') != std::string::npos) {
2590  kv_list_op = true;
2591  } else {
2592  CHECK(raw_options.find('[') != std::string::npos);
2593  }
2594  auto t1 = raw_options.erase(0, 1);
2595  raw_options = t1.substr(0, t1.length() - 1);
2596  std::string op_delim = ", ";
2597  if (kv_list_op) {
2598  // kv options
2599  std::unordered_map<std::string, std::string> kv_options;
2600  while ((pos = raw_options.find(op_delim)) != std::string::npos) {
2601  auto kv_pair = getKVOptionPair(raw_options, pos);
2602  kv_options.emplace(kv_pair.first, kv_pair.second);
2603  }
2604  // handle the last kv pair
2605  auto kv_pair = getKVOptionPair(raw_options, pos);
2606  kv_options.emplace(kv_pair.first, kv_pair.second);
2607  return {hint_type, true, false, true, kv_options};
2608  } else {
2609  std::vector<std::string> list_options;
2610  while ((pos = raw_options.find(op_delim)) != std::string::npos) {
2611  list_options.emplace_back(raw_options.substr(0, pos));
2612  raw_options.erase(0, pos + white_space_delim.length() + 1);
2613  }
2614  // handle the last option
2615  list_options.emplace_back(raw_options.substr(0, pos));
2616  return {hint_type, true, false, false, list_options};
2617  }
2618  } else {
2619  // marker hint: no extra option for this hint
2620  std::string hint_name = hint_string.substr(0, hint_string.find(white_space_delim));
2621  auto hint_type = RegisteredQueryHint::translateQueryHint(hint_name);
2622  return {hint_type, true, true, false};
2623  }
2624  }
static QueryHint translateQueryHint(const std::string &hint_name)
Definition: QueryHint.h:190
#define CHECK(condition)
Definition: Logger.h:209
std::pair< std::string, std::string > getKVOptionPair(std::string &str, size_t &pos)

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

std::shared_ptr<const RelAlgNode> details::RelAlgDispatcher::prev ( const rapidjson::Value &  crt_node)
inlineprivate

Definition at line 2677 of file RelAlgDagBuilder.cpp.

References CHECK, CHECK_EQ, anonymous_namespace{RelAlgDagBuilder.cpp}::node_id(), and nodes_.

Referenced by getRelAlgInputs().

2677  {
2678  const auto id = node_id(crt_node);
2679  CHECK(id);
2680  CHECK_EQ(static_cast<size_t>(id), nodes_.size());
2681  return nodes_.back();
2682  }
#define CHECK_EQ(x, y)
Definition: Logger.h:217
std::vector< std::shared_ptr< RelAlgNode > > nodes_
#define CHECK(condition)
Definition: Logger.h:209
unsigned node_id(const rapidjson::Value &ra_node) noexcept

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

std::vector<std::shared_ptr<RelAlgNode> > details::RelAlgDispatcher::run ( const rapidjson::Value &  rels,
RelAlgDagBuilder root_dag_builder 
)
inline

Definition at line 2240 of file RelAlgDagBuilder.cpp.

References CHECK, CHECK_EQ, dispatchAggregate(), dispatchFilter(), dispatchJoin(), dispatchLogicalValues(), dispatchModify(), dispatchProject(), dispatchSort(), dispatchTableFunction(), dispatchTableScan(), dispatchUnion(), field(), json_str(), anonymous_namespace{RelAlgDagBuilder.cpp}::node_id(), and nodes_.

Referenced by RelAlgDagBuilder::build().

2241  {
2242  for (auto rels_it = rels.Begin(); rels_it != rels.End(); ++rels_it) {
2243  const auto& crt_node = *rels_it;
2244  const auto id = node_id(crt_node);
2245  CHECK_EQ(static_cast<size_t>(id), nodes_.size());
2246  CHECK(crt_node.IsObject());
2247  std::shared_ptr<RelAlgNode> ra_node = nullptr;
2248  const auto rel_op = json_str(field(crt_node, "relOp"));
2249  if (rel_op == std::string("EnumerableTableScan") ||
2250  rel_op == std::string("LogicalTableScan")) {
2251  ra_node = dispatchTableScan(crt_node);
2252  } else if (rel_op == std::string("LogicalProject")) {
2253  ra_node = dispatchProject(crt_node, root_dag_builder);
2254  } else if (rel_op == std::string("LogicalFilter")) {
2255  ra_node = dispatchFilter(crt_node, root_dag_builder);
2256  } else if (rel_op == std::string("LogicalAggregate")) {
2257  ra_node = dispatchAggregate(crt_node);
2258  } else if (rel_op == std::string("LogicalJoin")) {
2259  ra_node = dispatchJoin(crt_node, root_dag_builder);
2260  } else if (rel_op == std::string("LogicalSort")) {
2261  ra_node = dispatchSort(crt_node);
2262  } else if (rel_op == std::string("LogicalValues")) {
2263  ra_node = dispatchLogicalValues(crt_node);
2264  } else if (rel_op == std::string("LogicalTableModify")) {
2265  ra_node = dispatchModify(crt_node);
2266  } else if (rel_op == std::string("LogicalTableFunctionScan")) {
2267  ra_node = dispatchTableFunction(crt_node, root_dag_builder);
2268  } else if (rel_op == std::string("LogicalUnion")) {
2269  ra_node = dispatchUnion(crt_node);
2270  } else {
2271  throw QueryNotSupported(std::string("Node ") + rel_op + " not supported yet");
2272  }
2273  nodes_.push_back(ra_node);
2274  }
2275 
2276  return std::move(nodes_);
2277  }
std::shared_ptr< RelAggregate > dispatchAggregate(const rapidjson::Value &agg_ra)
#define CHECK_EQ(x, y)
Definition: Logger.h:217
std::shared_ptr< RelProject > dispatchProject(const rapidjson::Value &proj_ra, RelAlgDagBuilder &root_dag_builder)
std::shared_ptr< RelScan > dispatchTableScan(const rapidjson::Value &scan_ra)
std::shared_ptr< RelLogicalUnion > dispatchUnion(const rapidjson::Value &logical_union_ra)
const std::string json_str(const rapidjson::Value &obj) noexcept
Definition: JsonAccessors.h:44
const rapidjson::Value & field(const rapidjson::Value &obj, const char field[]) noexcept
Definition: JsonAccessors.h:31
std::vector< std::shared_ptr< RelAlgNode > > nodes_
std::shared_ptr< RelFilter > dispatchFilter(const rapidjson::Value &filter_ra, RelAlgDagBuilder &root_dag_builder)
std::shared_ptr< RelJoin > dispatchJoin(const rapidjson::Value &join_ra, RelAlgDagBuilder &root_dag_builder)
std::shared_ptr< RelModify > dispatchModify(const rapidjson::Value &logical_modify_ra)
std::shared_ptr< RelSort > dispatchSort(const rapidjson::Value &sort_ra)
#define CHECK(condition)
Definition: Logger.h:209
unsigned node_id(const rapidjson::Value &ra_node) noexcept
std::shared_ptr< RelLogicalValues > dispatchLogicalValues(const rapidjson::Value &logical_values_ra)
std::shared_ptr< RelTableFunction > dispatchTableFunction(const rapidjson::Value &table_func_ra, RelAlgDagBuilder &root_dag_builder)

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

Member Data Documentation

std::vector<std::shared_ptr<RelAlgNode> > details::RelAlgDispatcher::nodes_
private

Definition at line 2685 of file RelAlgDagBuilder.cpp.

Referenced by getRelAlgInputs(), prev(), and run().


The documentation for this class was generated from the following file: