OmniSciDB  baf940c279
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)
 
HintExplained 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 2121 of file RelAlgDagBuilder.cpp.

Constructor & Destructor Documentation

◆ RelAlgDispatcher()

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

Definition at line 2123 of file RelAlgDagBuilder.cpp.

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

Member Function Documentation

◆ dispatchAggregate()

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

Definition at line 2211 of file RelAlgDagBuilder.cpp.

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

2211  {
2212  const auto inputs = getRelAlgInputs(agg_ra);
2213  CHECK_EQ(size_t(1), inputs.size());
2214  const auto fields = strings_from_json_array(field(agg_ra, "fields"));
2215  const auto group = indices_from_json_array(field(agg_ra, "group"));
2216  for (size_t i = 0; i < group.size(); ++i) {
2217  CHECK_EQ(i, group[i]);
2218  }
2219  if (agg_ra.HasMember("groups") || agg_ra.HasMember("indicator")) {
2220  throw QueryNotSupported("GROUP BY extensions not supported");
2221  }
2222  const auto& aggs_json_arr = field(agg_ra, "aggs");
2223  CHECK(aggs_json_arr.IsArray());
2224  std::vector<std::unique_ptr<const RexAgg>> aggs;
2225  for (auto aggs_json_arr_it = aggs_json_arr.Begin();
2226  aggs_json_arr_it != aggs_json_arr.End();
2227  ++aggs_json_arr_it) {
2228  aggs.emplace_back(parse_aggregate_expr(*aggs_json_arr_it));
2229  }
2230  if (agg_ra.HasMember("hints")) {
2231  auto agg_node =
2232  std::make_shared<RelAggregate>(group.size(), aggs, fields, inputs.front());
2233  getRelAlgHints(agg_ra, agg_node);
2234  return agg_node;
2235  }
2236  return std::make_shared<RelAggregate>(group.size(), aggs, fields, inputs.front());
2237  }
std::vector< std::string > strings_from_json_array(const rapidjson::Value &json_str_arr) noexcept
#define CHECK_EQ(x, y)
Definition: Logger.h:205
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:197
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:

◆ dispatchFilter()

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

Definition at line 2200 of file RelAlgDagBuilder.cpp.

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

2201  {
2202  const auto inputs = getRelAlgInputs(filter_ra);
2203  CHECK_EQ(size_t(1), inputs.size());
2204  const auto id = node_id(filter_ra);
2205  CHECK(id);
2206  auto condition =
2207  parse_scalar_expr(field(filter_ra, "condition"), cat_, root_dag_builder);
2208  return std::make_shared<RelFilter>(condition, inputs.front());
2209  }
#define CHECK_EQ(x, y)
Definition: Logger.h:205
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:197
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:

◆ dispatchJoin()

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

Definition at line 2239 of file RelAlgDagBuilder.cpp.

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

2240  {
2241  const auto inputs = getRelAlgInputs(join_ra);
2242  CHECK_EQ(size_t(2), inputs.size());
2243  const auto join_type = to_join_type(json_str(field(join_ra, "joinType")));
2244  auto filter_rex =
2245  parse_scalar_expr(field(join_ra, "condition"), cat_, root_dag_builder);
2246  if (join_ra.HasMember("hints")) {
2247  auto join_node =
2248  std::make_shared<RelJoin>(inputs[0], inputs[1], filter_rex, join_type);
2249  getRelAlgHints(join_ra, join_node);
2250  return join_node;
2251  }
2252  return std::make_shared<RelJoin>(inputs[0], inputs[1], filter_rex, join_type);
2253  }
#define CHECK_EQ(x, y)
Definition: Logger.h:205
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:

◆ dispatchLogicalValues()

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

Definition at line 2394 of file RelAlgDagBuilder.cpp.

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

2395  {
2396  const auto& tuple_type_arr = field(logical_values_ra, "type");
2397  CHECK(tuple_type_arr.IsArray());
2398  std::vector<TargetMetaInfo> tuple_type;
2399  for (auto tuple_type_arr_it = tuple_type_arr.Begin();
2400  tuple_type_arr_it != tuple_type_arr.End();
2401  ++tuple_type_arr_it) {
2402  const auto component_type = parse_type(*tuple_type_arr_it);
2403  const auto component_name = json_str(field(*tuple_type_arr_it, "name"));
2404  tuple_type.emplace_back(component_name, component_type);
2405  }
2406  const auto& inputs_arr = field(logical_values_ra, "inputs");
2407  CHECK(inputs_arr.IsArray());
2408  const auto& tuples_arr = field(logical_values_ra, "tuples");
2409  CHECK(tuples_arr.IsArray());
2410 
2411  if (inputs_arr.Size()) {
2412  throw QueryNotSupported("Inputs not supported in logical values yet.");
2413  }
2414 
2415  std::vector<RelLogicalValues::RowValues> values;
2416  if (tuples_arr.Size()) {
2417  for (const auto& row : tuples_arr.GetArray()) {
2418  CHECK(row.IsArray());
2419  const auto values_json = row.GetArray();
2420  if (!values.empty()) {
2421  CHECK_EQ(values[0].size(), values_json.Size());
2422  }
2423  values.emplace_back(RelLogicalValues::RowValues{});
2424  for (const auto& value : values_json) {
2425  CHECK(value.IsObject());
2426  CHECK(value.HasMember("literal"));
2427  values.back().emplace_back(parse_literal(value));
2428  }
2429  }
2430  }
2431 
2432  return std::make_shared<RelLogicalValues>(tuple_type, values);
2433  }
SQLTypeInfo parse_type(const rapidjson::Value &type_obj)
#define CHECK_EQ(x, y)
Definition: Logger.h:205
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)
std::vector< std::unique_ptr< const RexScalar > > RowValues
#define CHECK(condition)
Definition: Logger.h:197
+ Here is the call graph for this function:

◆ dispatchModify()

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

Definition at line 2277 of file RelAlgDagBuilder.cpp.

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

2277  {
2278  const auto inputs = getRelAlgInputs(logical_modify_ra);
2279  CHECK_EQ(size_t(1), inputs.size());
2280 
2281  const auto table_descriptor = getTableFromScanNode(cat_, logical_modify_ra);
2282  if (table_descriptor->isView) {
2283  throw std::runtime_error("UPDATE of a view is unsupported.");
2284  }
2285 
2286  bool flattened = json_bool(field(logical_modify_ra, "flattened"));
2287  std::string op = json_str(field(logical_modify_ra, "operation"));
2288  RelModify::TargetColumnList target_column_list;
2289 
2290  if (op == "UPDATE") {
2291  const auto& update_columns = field(logical_modify_ra, "updateColumnList");
2292  CHECK(update_columns.IsArray());
2293 
2294  for (auto column_arr_it = update_columns.Begin();
2295  column_arr_it != update_columns.End();
2296  ++column_arr_it) {
2297  target_column_list.push_back(column_arr_it->GetString());
2298  }
2299  }
2300 
2301  auto modify_node = std::make_shared<RelModify>(
2302  cat_, table_descriptor, flattened, op, target_column_list, inputs[0]);
2303  switch (modify_node->getOperation()) {
2305  modify_node->applyDeleteModificationsToInputNode();
2306  break;
2307  }
2309  modify_node->applyUpdateModificationsToInputNode();
2310  break;
2311  }
2312  default:
2313  throw std::runtime_error("Unsupported RelModify operation: " +
2314  json_node_to_string(logical_modify_ra));
2315  }
2316 
2317  return modify_node;
2318  }
#define CHECK_EQ(x, y)
Definition: Logger.h:205
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:197
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:

◆ dispatchProject()

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

Definition at line 2178 of file RelAlgDagBuilder.cpp.

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

2179  {
2180  const auto inputs = getRelAlgInputs(proj_ra);
2181  CHECK_EQ(size_t(1), inputs.size());
2182  const auto& exprs_json = field(proj_ra, "exprs");
2183  CHECK(exprs_json.IsArray());
2184  std::vector<std::unique_ptr<const RexScalar>> exprs;
2185  for (auto exprs_json_it = exprs_json.Begin(); exprs_json_it != exprs_json.End();
2186  ++exprs_json_it) {
2187  exprs.emplace_back(parse_scalar_expr(*exprs_json_it, cat_, root_dag_builder));
2188  }
2189  const auto& fields = field(proj_ra, "fields");
2190  if (proj_ra.HasMember("hints")) {
2191  auto project_node = std::make_shared<RelProject>(
2192  exprs, strings_from_json_array(fields), inputs.front());
2193  getRelAlgHints(proj_ra, project_node);
2194  return project_node;
2195  }
2196  return std::make_shared<RelProject>(
2197  exprs, strings_from_json_array(fields), inputs.front());
2198  }
std::vector< std::string > strings_from_json_array(const rapidjson::Value &json_str_arr) noexcept
#define CHECK_EQ(x, y)
Definition: Logger.h:205
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:197
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:

◆ dispatchSort()

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

Definition at line 2255 of file RelAlgDagBuilder.cpp.

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

2255  {
2256  const auto inputs = getRelAlgInputs(sort_ra);
2257  CHECK_EQ(size_t(1), inputs.size());
2258  std::vector<SortField> collation;
2259  const auto& collation_arr = field(sort_ra, "collation");
2260  CHECK(collation_arr.IsArray());
2261  for (auto collation_arr_it = collation_arr.Begin();
2262  collation_arr_it != collation_arr.End();
2263  ++collation_arr_it) {
2264  const size_t field_idx = json_i64(field(*collation_arr_it, "field"));
2265  const auto sort_dir = parse_sort_direction(*collation_arr_it);
2266  const auto null_pos = parse_nulls_position(*collation_arr_it);
2267  collation.emplace_back(field_idx, sort_dir, null_pos);
2268  }
2269  auto limit = get_int_literal_field(sort_ra, "fetch", -1);
2270  const auto offset = get_int_literal_field(sort_ra, "offset", 0);
2271  auto ret = std::make_shared<RelSort>(
2272  collation, limit > 0 ? limit : 0, offset, inputs.front());
2273  ret->setEmptyResult(limit == 0);
2274  return ret;
2275  }
#define CHECK_EQ(x, y)
Definition: Logger.h:205
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:197
RelAlgInputs getRelAlgInputs(const rapidjson::Value &node)
+ Here is the call graph for this function:

◆ dispatchTableFunction()

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

Definition at line 2320 of file RelAlgDagBuilder.cpp.

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

2322  {
2323  const auto inputs = getRelAlgInputs(table_func_ra);
2324  const auto& invocation = field(table_func_ra, "invocation");
2325  CHECK(invocation.IsObject());
2326 
2327  const auto& operands = field(invocation, "operands");
2328  CHECK(operands.IsArray());
2329  CHECK_GE(operands.Size(), unsigned(0));
2330 
2331  std::vector<const Rex*> col_inputs;
2332  std::vector<std::unique_ptr<const RexScalar>> table_func_inputs;
2333  std::vector<std::string> fields;
2334 
2335  for (auto exprs_json_it = operands.Begin(); exprs_json_it != operands.End();
2336  ++exprs_json_it) {
2337  const auto& expr_json = *exprs_json_it;
2338  CHECK(expr_json.IsObject());
2339  if (expr_json.HasMember("op")) {
2340  const auto op_str = json_str(field(expr_json, "op"));
2341  if (op_str == "CAST" && expr_json.HasMember("type")) {
2342  const auto& expr_type = field(expr_json, "type");
2343  CHECK(expr_type.IsObject());
2344  CHECK(expr_type.HasMember("type"));
2345  const auto& expr_type_name = json_str(field(expr_type, "type"));
2346  if (expr_type_name == "CURSOR") {
2347  CHECK(expr_json.HasMember("operands"));
2348  const auto& expr_operands = field(expr_json, "operands");
2349  CHECK(expr_operands.IsArray());
2350  if (expr_operands.Size() != 1) {
2351  throw std::runtime_error(
2352  "Table functions currently only support one ResultSet input");
2353  }
2354 
2355  const auto prior_node = prev(table_func_ra);
2356  CHECK(prior_node);
2357  // Forward the values from the prior node as RexInputs
2358  for (size_t i = 0; i < prior_node->size(); i++) {
2359  table_func_inputs.emplace_back(
2360  std::make_unique<RexAbstractInput>(col_inputs.size()));
2361  col_inputs.emplace_back(table_func_inputs.back().get());
2362  }
2363  continue;
2364  }
2365  }
2366  }
2367  table_func_inputs.emplace_back(
2368  parse_scalar_expr(*exprs_json_it, cat_, root_dag_builder));
2369  }
2370 
2371  const auto& op_name = field(invocation, "op");
2372  CHECK(op_name.IsString());
2373 
2374  std::vector<std::unique_ptr<const RexScalar>> table_function_projected_outputs;
2375  const auto& row_types = field(table_func_ra, "rowType");
2376  CHECK(row_types.IsArray());
2377  CHECK_GE(row_types.Size(), unsigned(0));
2378  const auto& row_types_array = row_types.GetArray();
2379  for (size_t i = 0; i < row_types_array.Size(); i++) {
2380  // We don't care about the type information in rowType -- replace each output with
2381  // a reference to be resolved later in the translator
2382  table_function_projected_outputs.emplace_back(std::make_unique<RexRef>(i));
2383  fields.emplace_back("");
2384  }
2385 
2386  return std::make_shared<RelTableFunction>(op_name.GetString(),
2387  inputs,
2388  fields,
2389  col_inputs,
2390  table_func_inputs,
2391  table_function_projected_outputs);
2392  }
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:210
const rapidjson::Value & field(const rapidjson::Value &obj, const char field[]) noexcept
Definition: JsonAccessors.h:31
#define CHECK(condition)
Definition: Logger.h:197
std::unique_ptr< const RexScalar > parse_scalar_expr(const rapidjson::Value &expr, const Catalog_Namespace::Catalog &cat, RelAlgDagBuilder &root_dag_builder)
std::shared_ptr< const RelAlgNode > prev(const rapidjson::Value &crt_node)
RelAlgInputs getRelAlgInputs(const rapidjson::Value &node)
+ Here is the call graph for this function:

◆ dispatchTableScan()

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

Definition at line 2165 of file RelAlgDagBuilder.cpp.

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

2165  {
2166  check_empty_inputs_field(scan_ra);
2167  CHECK(scan_ra.IsObject());
2168  const auto td = getTableFromScanNode(cat_, scan_ra);
2169  const auto field_names = getFieldNamesFromScanNode(scan_ra);
2170  if (scan_ra.HasMember("hints")) {
2171  auto scan_node = std::make_shared<RelScan>(td, field_names);
2172  getRelAlgHints(scan_ra, scan_node);
2173  return scan_node;
2174  }
2175  return std::make_shared<RelScan>(td, field_names);
2176  }
const Catalog_Namespace::Catalog & cat_
const TableDescriptor * getTableFromScanNode(const Catalog_Namespace::Catalog &cat, const rapidjson::Value &scan_ra)
#define CHECK(condition)
Definition: Logger.h:197
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:

◆ dispatchUnion()

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

Definition at line 2435 of file RelAlgDagBuilder.cpp.

References CHECK, and field().

2436  {
2437  auto inputs = getRelAlgInputs(logical_union_ra);
2438  auto const& all_type_bool = field(logical_union_ra, "all");
2439  CHECK(all_type_bool.IsBool());
2440  return std::make_shared<RelLogicalUnion>(std::move(inputs), all_type_bool.GetBool());
2441  }
const rapidjson::Value & field(const rapidjson::Value &obj, const char field[]) noexcept
Definition: JsonAccessors.h:31
#define CHECK(condition)
Definition: Logger.h:197
RelAlgInputs getRelAlgInputs(const rapidjson::Value &node)
+ Here is the call graph for this function:

◆ getKVOptionPair()

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

Definition at line 2455 of file RelAlgDagBuilder.cpp.

2455  {
2456  auto option = str.substr(0, pos);
2457  std::string delim = "=";
2458  size_t delim_pos = option.find(delim);
2459  auto key = option.substr(0, delim_pos);
2460  auto val = option.substr(delim_pos + 1, option.length());
2461  str.erase(0, pos + delim.length() + 1);
2462  return {key, val};
2463  }

◆ getRelAlgHints()

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

Definition at line 2512 of file RelAlgDagBuilder.cpp.

References field(), and json_str().

2513  {
2514  std::string hint_explained = json_str(field(json_node, "hints"));
2515  size_t pos = 0;
2516  std::string delim = "|";
2517  std::vector<std::string> hint_list;
2518  while ((pos = hint_explained.find(delim)) != std::string::npos) {
2519  hint_list.emplace_back(hint_explained.substr(0, pos));
2520  hint_explained.erase(0, pos + delim.length());
2521  }
2522  // handling the last one
2523  hint_list.emplace_back(hint_explained.substr(0, pos));
2524 
2525  const auto agg_node = std::dynamic_pointer_cast<RelAggregate>(node);
2526  if (agg_node) {
2527  for (std::string& hint : hint_list) {
2528  auto parsed_hint = parseHintString(hint);
2529  agg_node->addHint(parsed_hint);
2530  }
2531  }
2532  const auto project_node = std::dynamic_pointer_cast<RelProject>(node);
2533  if (project_node) {
2534  for (std::string& hint : hint_list) {
2535  auto parsed_hint = parseHintString(hint);
2536  project_node->addHint(parsed_hint);
2537  }
2538  }
2539  const auto scan_node = std::dynamic_pointer_cast<RelScan>(node);
2540  if (scan_node) {
2541  for (std::string& hint : hint_list) {
2542  auto parsed_hint = parseHintString(hint);
2543  scan_node->addHint(parsed_hint);
2544  }
2545  }
2546  const auto join_node = std::dynamic_pointer_cast<RelJoin>(node);
2547  if (join_node) {
2548  for (std::string& hint : hint_list) {
2549  auto parsed_hint = parseHintString(hint);
2550  join_node->addHint(parsed_hint);
2551  }
2552  }
2553 
2554  const auto compound_node = std::dynamic_pointer_cast<RelCompound>(node);
2555  if (compound_node) {
2556  for (std::string& hint : hint_list) {
2557  auto parsed_hint = parseHintString(hint);
2558  compound_node->addHint(parsed_hint);
2559  }
2560  }
2561  }
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
HintExplained parseHintString(std::string &hint_string)
+ Here is the call graph for this function:

◆ getRelAlgInputs()

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

Definition at line 2443 of file RelAlgDagBuilder.cpp.

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

2443  {
2444  if (node.HasMember("inputs")) {
2445  const auto str_input_ids = strings_from_json_array(field(node, "inputs"));
2446  RelAlgInputs ra_inputs;
2447  for (const auto& str_id : str_input_ids) {
2448  ra_inputs.push_back(nodes_[std::stoi(str_id)]);
2449  }
2450  return ra_inputs;
2451  }
2452  return {prev(node)};
2453  }
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:

◆ parseHintString()

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

Definition at line 2465 of file RelAlgDagBuilder.cpp.

References CHECK.

2465  {
2466  std::string white_space_delim = " ";
2467  int l = hint_string.length();
2468  hint_string = hint_string.erase(0, 1).substr(0, l - 2);
2469  size_t pos = 0;
2470  if ((pos = hint_string.find("options:")) != std::string::npos) {
2471  // need to parse hint options
2472  std::vector<std::string> tokens;
2473  std::string hint_name = hint_string.substr(0, hint_string.find(white_space_delim));
2474  bool kv_list_op = false;
2475  std::string raw_options = hint_string.substr(pos + 8, hint_string.length() - 2);
2476  if (raw_options.find('{') != std::string::npos) {
2477  kv_list_op = true;
2478  } else {
2479  CHECK(raw_options.find('[') != std::string::npos);
2480  }
2481  auto t1 = raw_options.erase(0, 1);
2482  raw_options = t1.substr(0, t1.length() - 1);
2483  std::string op_delim = ", ";
2484  if (kv_list_op) {
2485  // kv options
2486  std::unordered_map<std::string, std::string> kv_options;
2487  while ((pos = raw_options.find(op_delim)) != std::string::npos) {
2488  auto kv_pair = getKVOptionPair(raw_options, pos);
2489  kv_options.emplace(kv_pair.first, kv_pair.second);
2490  }
2491  // handle the last kv pair
2492  auto kv_pair = getKVOptionPair(raw_options, pos);
2493  kv_options.emplace(kv_pair.first, kv_pair.second);
2494  return {hint_name, true, false, true, kv_options};
2495  } else {
2496  std::vector<std::string> list_options;
2497  while ((pos = raw_options.find(op_delim)) != std::string::npos) {
2498  list_options.emplace_back(raw_options.substr(0, pos));
2499  raw_options.erase(0, pos + white_space_delim.length() + 1);
2500  }
2501  // handle the last option
2502  list_options.emplace_back(raw_options.substr(0, pos));
2503  return {hint_name, true, false, false, list_options};
2504  }
2505  } else {
2506  // marker hint: no extra option for this hint
2507  std::string hint_name = hint_string.substr(0, hint_string.find(white_space_delim));
2508  return {hint_name, true, true, false};
2509  }
2510  }
#define CHECK(condition)
Definition: Logger.h:197
std::pair< std::string, std::string > getKVOptionPair(std::string &str, size_t &pos)

◆ prev()

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

Definition at line 2563 of file RelAlgDagBuilder.cpp.

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

2563  {
2564  const auto id = node_id(crt_node);
2565  CHECK(id);
2566  CHECK_EQ(static_cast<size_t>(id), nodes_.size());
2567  return nodes_.back();
2568  }
#define CHECK_EQ(x, y)
Definition: Logger.h:205
std::vector< std::shared_ptr< RelAlgNode > > nodes_
#define CHECK(condition)
Definition: Logger.h:197
unsigned node_id(const rapidjson::Value &ra_node) noexcept
+ Here is the call graph for this function:

◆ run()

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

Definition at line 2125 of file RelAlgDagBuilder.cpp.

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

Referenced by RelAlgDagBuilder::build().

2126  {
2127  for (auto rels_it = rels.Begin(); rels_it != rels.End(); ++rels_it) {
2128  const auto& crt_node = *rels_it;
2129  const auto id = node_id(crt_node);
2130  CHECK_EQ(static_cast<size_t>(id), nodes_.size());
2131  CHECK(crt_node.IsObject());
2132  std::shared_ptr<RelAlgNode> ra_node = nullptr;
2133  const auto rel_op = json_str(field(crt_node, "relOp"));
2134  if (rel_op == std::string("EnumerableTableScan") ||
2135  rel_op == std::string("LogicalTableScan")) {
2136  ra_node = dispatchTableScan(crt_node);
2137  } else if (rel_op == std::string("LogicalProject")) {
2138  ra_node = dispatchProject(crt_node, root_dag_builder);
2139  } else if (rel_op == std::string("LogicalFilter")) {
2140  ra_node = dispatchFilter(crt_node, root_dag_builder);
2141  } else if (rel_op == std::string("LogicalAggregate")) {
2142  ra_node = dispatchAggregate(crt_node);
2143  } else if (rel_op == std::string("LogicalJoin")) {
2144  ra_node = dispatchJoin(crt_node, root_dag_builder);
2145  } else if (rel_op == std::string("LogicalSort")) {
2146  ra_node = dispatchSort(crt_node);
2147  } else if (rel_op == std::string("LogicalValues")) {
2148  ra_node = dispatchLogicalValues(crt_node);
2149  } else if (rel_op == std::string("LogicalTableModify")) {
2150  ra_node = dispatchModify(crt_node);
2151  } else if (rel_op == std::string("LogicalTableFunctionScan")) {
2152  ra_node = dispatchTableFunction(crt_node, root_dag_builder);
2153  } else if (rel_op == std::string("LogicalUnion")) {
2154  ra_node = dispatchUnion(crt_node);
2155  } else {
2156  throw QueryNotSupported(std::string("Node ") + rel_op + " not supported yet");
2157  }
2158  nodes_.push_back(ra_node);
2159  }
2160 
2161  return std::move(nodes_);
2162  }
std::shared_ptr< RelAggregate > dispatchAggregate(const rapidjson::Value &agg_ra)
#define CHECK_EQ(x, y)
Definition: Logger.h:205
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:197
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

◆ cat_

const Catalog_Namespace::Catalog& details::RelAlgDispatcher::cat_
private

Definition at line 2570 of file RelAlgDagBuilder.cpp.

◆ nodes_

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

Definition at line 2571 of file RelAlgDagBuilder.cpp.


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