OmniSciDB  8fa3bf436f
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros 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 2147 of file RelAlgDagBuilder.cpp.

Constructor & Destructor Documentation

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

Definition at line 2149 of file RelAlgDagBuilder.cpp.

2149 : 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 2237 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().

2237  {
2238  const auto inputs = getRelAlgInputs(agg_ra);
2239  CHECK_EQ(size_t(1), inputs.size());
2240  const auto fields = strings_from_json_array(field(agg_ra, "fields"));
2241  const auto group = indices_from_json_array(field(agg_ra, "group"));
2242  for (size_t i = 0; i < group.size(); ++i) {
2243  CHECK_EQ(i, group[i]);
2244  }
2245  if (agg_ra.HasMember("groups") || agg_ra.HasMember("indicator")) {
2246  throw QueryNotSupported("GROUP BY extensions not supported");
2247  }
2248  const auto& aggs_json_arr = field(agg_ra, "aggs");
2249  CHECK(aggs_json_arr.IsArray());
2250  std::vector<std::unique_ptr<const RexAgg>> aggs;
2251  for (auto aggs_json_arr_it = aggs_json_arr.Begin();
2252  aggs_json_arr_it != aggs_json_arr.End();
2253  ++aggs_json_arr_it) {
2254  aggs.emplace_back(parse_aggregate_expr(*aggs_json_arr_it));
2255  }
2256  if (agg_ra.HasMember("hints")) {
2257  auto agg_node =
2258  std::make_shared<RelAggregate>(group.size(), aggs, fields, inputs.front());
2259  getRelAlgHints(agg_ra, agg_node);
2260  return agg_node;
2261  }
2262  return std::make_shared<RelAggregate>(group.size(), aggs, fields, inputs.front());
2263  }
std::vector< std::string > strings_from_json_array(const rapidjson::Value &json_str_arr) noexcept
#define CHECK_EQ(x, y)
Definition: Logger.h:211
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:203
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 2226 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().

2227  {
2228  const auto inputs = getRelAlgInputs(filter_ra);
2229  CHECK_EQ(size_t(1), inputs.size());
2230  const auto id = node_id(filter_ra);
2231  CHECK(id);
2232  auto condition =
2233  parse_scalar_expr(field(filter_ra, "condition"), cat_, root_dag_builder);
2234  return std::make_shared<RelFilter>(condition, inputs.front());
2235  }
#define CHECK_EQ(x, y)
Definition: Logger.h:211
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:203
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 2265 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().

2266  {
2267  const auto inputs = getRelAlgInputs(join_ra);
2268  CHECK_EQ(size_t(2), inputs.size());
2269  const auto join_type = to_join_type(json_str(field(join_ra, "joinType")));
2270  auto filter_rex =
2271  parse_scalar_expr(field(join_ra, "condition"), cat_, root_dag_builder);
2272  if (join_ra.HasMember("hints")) {
2273  auto join_node =
2274  std::make_shared<RelJoin>(inputs[0], inputs[1], filter_rex, join_type);
2275  getRelAlgHints(join_ra, join_node);
2276  return join_node;
2277  }
2278  return std::make_shared<RelJoin>(inputs[0], inputs[1], filter_rex, join_type);
2279  }
#define CHECK_EQ(x, y)
Definition: Logger.h:211
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 2417 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().

2418  {
2419  const auto& tuple_type_arr = field(logical_values_ra, "type");
2420  CHECK(tuple_type_arr.IsArray());
2421  std::vector<TargetMetaInfo> tuple_type;
2422  for (auto tuple_type_arr_it = tuple_type_arr.Begin();
2423  tuple_type_arr_it != tuple_type_arr.End();
2424  ++tuple_type_arr_it) {
2425  const auto component_type = parse_type(*tuple_type_arr_it);
2426  const auto component_name = json_str(field(*tuple_type_arr_it, "name"));
2427  tuple_type.emplace_back(component_name, component_type);
2428  }
2429  const auto& inputs_arr = field(logical_values_ra, "inputs");
2430  CHECK(inputs_arr.IsArray());
2431  const auto& tuples_arr = field(logical_values_ra, "tuples");
2432  CHECK(tuples_arr.IsArray());
2433 
2434  if (inputs_arr.Size()) {
2435  throw QueryNotSupported("Inputs not supported in logical values yet.");
2436  }
2437 
2438  std::vector<RelLogicalValues::RowValues> values;
2439  if (tuples_arr.Size()) {
2440  for (const auto& row : tuples_arr.GetArray()) {
2441  CHECK(row.IsArray());
2442  const auto values_json = row.GetArray();
2443  if (!values.empty()) {
2444  CHECK_EQ(values[0].size(), values_json.Size());
2445  }
2446  values.emplace_back(RelLogicalValues::RowValues{});
2447  for (const auto& value : values_json) {
2448  CHECK(value.IsObject());
2449  CHECK(value.HasMember("literal"));
2450  values.back().emplace_back(parse_literal(value));
2451  }
2452  }
2453  }
2454 
2455  return std::make_shared<RelLogicalValues>(tuple_type, values);
2456  }
SQLTypeInfo parse_type(const rapidjson::Value &type_obj)
#define CHECK_EQ(x, y)
Definition: Logger.h:211
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:203
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 2303 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().

2303  {
2304  const auto inputs = getRelAlgInputs(logical_modify_ra);
2305  CHECK_EQ(size_t(1), inputs.size());
2306 
2307  const auto table_descriptor = getTableFromScanNode(cat_, logical_modify_ra);
2308  if (table_descriptor->isView) {
2309  throw std::runtime_error("UPDATE of a view is unsupported.");
2310  }
2311 
2312  bool flattened = json_bool(field(logical_modify_ra, "flattened"));
2313  std::string op = json_str(field(logical_modify_ra, "operation"));
2314  RelModify::TargetColumnList target_column_list;
2315 
2316  if (op == "UPDATE") {
2317  const auto& update_columns = field(logical_modify_ra, "updateColumnList");
2318  CHECK(update_columns.IsArray());
2319 
2320  for (auto column_arr_it = update_columns.Begin();
2321  column_arr_it != update_columns.End();
2322  ++column_arr_it) {
2323  target_column_list.push_back(column_arr_it->GetString());
2324  }
2325  }
2326 
2327  auto modify_node = std::make_shared<RelModify>(
2328  cat_, table_descriptor, flattened, op, target_column_list, inputs[0]);
2329  switch (modify_node->getOperation()) {
2331  modify_node->applyDeleteModificationsToInputNode();
2332  break;
2333  }
2335  modify_node->applyUpdateModificationsToInputNode();
2336  break;
2337  }
2338  default:
2339  throw std::runtime_error("Unsupported RelModify operation: " +
2340  json_node_to_string(logical_modify_ra));
2341  }
2342 
2343  return modify_node;
2344  }
#define CHECK_EQ(x, y)
Definition: Logger.h:211
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:203
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 2204 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().

2205  {
2206  const auto inputs = getRelAlgInputs(proj_ra);
2207  CHECK_EQ(size_t(1), inputs.size());
2208  const auto& exprs_json = field(proj_ra, "exprs");
2209  CHECK(exprs_json.IsArray());
2210  std::vector<std::unique_ptr<const RexScalar>> exprs;
2211  for (auto exprs_json_it = exprs_json.Begin(); exprs_json_it != exprs_json.End();
2212  ++exprs_json_it) {
2213  exprs.emplace_back(parse_scalar_expr(*exprs_json_it, cat_, root_dag_builder));
2214  }
2215  const auto& fields = field(proj_ra, "fields");
2216  if (proj_ra.HasMember("hints")) {
2217  auto project_node = std::make_shared<RelProject>(
2218  exprs, strings_from_json_array(fields), inputs.front());
2219  getRelAlgHints(proj_ra, project_node);
2220  return project_node;
2221  }
2222  return std::make_shared<RelProject>(
2223  exprs, strings_from_json_array(fields), inputs.front());
2224  }
std::vector< std::string > strings_from_json_array(const rapidjson::Value &json_str_arr) noexcept
#define CHECK_EQ(x, y)
Definition: Logger.h:211
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:203
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 2281 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().

2281  {
2282  const auto inputs = getRelAlgInputs(sort_ra);
2283  CHECK_EQ(size_t(1), inputs.size());
2284  std::vector<SortField> collation;
2285  const auto& collation_arr = field(sort_ra, "collation");
2286  CHECK(collation_arr.IsArray());
2287  for (auto collation_arr_it = collation_arr.Begin();
2288  collation_arr_it != collation_arr.End();
2289  ++collation_arr_it) {
2290  const size_t field_idx = json_i64(field(*collation_arr_it, "field"));
2291  const auto sort_dir = parse_sort_direction(*collation_arr_it);
2292  const auto null_pos = parse_nulls_position(*collation_arr_it);
2293  collation.emplace_back(field_idx, sort_dir, null_pos);
2294  }
2295  auto limit = get_int_literal_field(sort_ra, "fetch", -1);
2296  const auto offset = get_int_literal_field(sort_ra, "offset", 0);
2297  auto ret = std::make_shared<RelSort>(
2298  collation, limit > 0 ? limit : 0, offset, inputs.front());
2299  ret->setEmptyResult(limit == 0);
2300  return ret;
2301  }
#define CHECK_EQ(x, y)
Definition: Logger.h:211
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:203
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 2346 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().

2348  {
2349  const auto inputs = getRelAlgInputs(table_func_ra);
2350  const auto& invocation = field(table_func_ra, "invocation");
2351  CHECK(invocation.IsObject());
2352 
2353  const auto& operands = field(invocation, "operands");
2354  CHECK(operands.IsArray());
2355  CHECK_GE(operands.Size(), unsigned(0));
2356 
2357  std::vector<const Rex*> col_inputs;
2358  std::vector<std::unique_ptr<const RexScalar>> table_func_inputs;
2359  std::vector<std::string> fields;
2360 
2361  for (auto exprs_json_it = operands.Begin(); exprs_json_it != operands.End();
2362  ++exprs_json_it) {
2363  const auto& expr_json = *exprs_json_it;
2364  CHECK(expr_json.IsObject());
2365  if (expr_json.HasMember("op")) {
2366  const auto op_str = json_str(field(expr_json, "op"));
2367  if (op_str == "CAST" && expr_json.HasMember("type")) {
2368  const auto& expr_type = field(expr_json, "type");
2369  CHECK(expr_type.IsObject());
2370  CHECK(expr_type.HasMember("type"));
2371  const auto& expr_type_name = json_str(field(expr_type, "type"));
2372  if (expr_type_name == "CURSOR") {
2373  CHECK(expr_json.HasMember("operands"));
2374  const auto& expr_operands = field(expr_json, "operands");
2375  CHECK(expr_operands.IsArray());
2376  if (expr_operands.Size() != 1) {
2377  throw std::runtime_error(
2378  "Table functions currently only support one ResultSet input");
2379  }
2380  auto pos = field(expr_operands[0], "input").GetInt();
2381  CHECK_LT(pos, inputs.size());
2382  for (size_t i = inputs[pos]->size(); i > 0; i--) {
2383  table_func_inputs.emplace_back(
2384  std::make_unique<RexAbstractInput>(col_inputs.size()));
2385  col_inputs.emplace_back(table_func_inputs.back().get());
2386  }
2387  continue;
2388  }
2389  }
2390  }
2391  table_func_inputs.emplace_back(
2392  parse_scalar_expr(*exprs_json_it, cat_, root_dag_builder));
2393  }
2394 
2395  const auto& op_name = field(invocation, "op");
2396  CHECK(op_name.IsString());
2397 
2398  std::vector<std::unique_ptr<const RexScalar>> table_function_projected_outputs;
2399  const auto& row_types = field(table_func_ra, "rowType");
2400  CHECK(row_types.IsArray());
2401  CHECK_GE(row_types.Size(), unsigned(0));
2402  const auto& row_types_array = row_types.GetArray();
2403  for (size_t i = 0; i < row_types_array.Size(); i++) {
2404  // We don't care about the type information in rowType -- replace each output with
2405  // a reference to be resolved later in the translator
2406  table_function_projected_outputs.emplace_back(std::make_unique<RexRef>(i));
2407  fields.emplace_back("");
2408  }
2409  return std::make_shared<RelTableFunction>(op_name.GetString(),
2410  inputs,
2411  fields,
2412  col_inputs,
2413  table_func_inputs,
2414  table_function_projected_outputs);
2415  }
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:216
const rapidjson::Value & field(const rapidjson::Value &obj, const char field[]) noexcept
Definition: JsonAccessors.h:31
#define CHECK_LT(x, y)
Definition: Logger.h:213
#define CHECK(condition)
Definition: Logger.h:203
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 2191 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().

2191  {
2192  check_empty_inputs_field(scan_ra);
2193  CHECK(scan_ra.IsObject());
2194  const auto td = getTableFromScanNode(cat_, scan_ra);
2195  const auto field_names = getFieldNamesFromScanNode(scan_ra);
2196  if (scan_ra.HasMember("hints")) {
2197  auto scan_node = std::make_shared<RelScan>(td, field_names);
2198  getRelAlgHints(scan_ra, scan_node);
2199  return scan_node;
2200  }
2201  return std::make_shared<RelScan>(td, field_names);
2202  }
const Catalog_Namespace::Catalog & cat_
const TableDescriptor * getTableFromScanNode(const Catalog_Namespace::Catalog &cat, const rapidjson::Value &scan_ra)
#define CHECK(condition)
Definition: Logger.h:203
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 2458 of file RelAlgDagBuilder.cpp.

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

Referenced by run().

2459  {
2460  auto inputs = getRelAlgInputs(logical_union_ra);
2461  auto const& all_type_bool = field(logical_union_ra, "all");
2462  CHECK(all_type_bool.IsBool());
2463  return std::make_shared<RelLogicalUnion>(std::move(inputs), all_type_bool.GetBool());
2464  }
const rapidjson::Value & field(const rapidjson::Value &obj, const char field[]) noexcept
Definition: JsonAccessors.h:31
#define CHECK(condition)
Definition: Logger.h:203
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 2478 of file RelAlgDagBuilder.cpp.

Referenced by parseHintString().

2478  {
2479  auto option = str.substr(0, pos);
2480  std::string delim = "=";
2481  size_t delim_pos = option.find(delim);
2482  auto key = option.substr(0, delim_pos);
2483  auto val = option.substr(delim_pos + 1, option.length());
2484  str.erase(0, pos + delim.length() + 1);
2485  return {key, val};
2486  }

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

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

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

2538  {
2539  std::string hint_explained = json_str(field(json_node, "hints"));
2540  size_t pos = 0;
2541  std::string delim = "|";
2542  std::vector<std::string> hint_list;
2543  while ((pos = hint_explained.find(delim)) != std::string::npos) {
2544  hint_list.emplace_back(hint_explained.substr(0, pos));
2545  hint_explained.erase(0, pos + delim.length());
2546  }
2547  // handling the last one
2548  hint_list.emplace_back(hint_explained.substr(0, pos));
2549 
2550  const auto agg_node = std::dynamic_pointer_cast<RelAggregate>(node);
2551  if (agg_node) {
2552  for (std::string& hint : hint_list) {
2553  auto parsed_hint = parseHintString(hint);
2554  agg_node->addHint(parsed_hint);
2555  }
2556  }
2557  const auto project_node = std::dynamic_pointer_cast<RelProject>(node);
2558  if (project_node) {
2559  for (std::string& hint : hint_list) {
2560  auto parsed_hint = parseHintString(hint);
2561  project_node->addHint(parsed_hint);
2562  }
2563  }
2564  const auto scan_node = std::dynamic_pointer_cast<RelScan>(node);
2565  if (scan_node) {
2566  for (std::string& hint : hint_list) {
2567  auto parsed_hint = parseHintString(hint);
2568  scan_node->addHint(parsed_hint);
2569  }
2570  }
2571  const auto join_node = std::dynamic_pointer_cast<RelJoin>(node);
2572  if (join_node) {
2573  for (std::string& hint : hint_list) {
2574  auto parsed_hint = parseHintString(hint);
2575  join_node->addHint(parsed_hint);
2576  }
2577  }
2578 
2579  const auto compound_node = std::dynamic_pointer_cast<RelCompound>(node);
2580  if (compound_node) {
2581  for (std::string& hint : hint_list) {
2582  auto parsed_hint = parseHintString(hint);
2583  compound_node->addHint(parsed_hint);
2584  }
2585  }
2586  }
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 2466 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().

2466  {
2467  if (node.HasMember("inputs")) {
2468  const auto str_input_ids = strings_from_json_array(field(node, "inputs"));
2469  RelAlgInputs ra_inputs;
2470  for (const auto& str_id : str_input_ids) {
2471  ra_inputs.push_back(nodes_[std::stoi(str_id)]);
2472  }
2473  return ra_inputs;
2474  }
2475  return {prev(node)};
2476  }
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 2488 of file RelAlgDagBuilder.cpp.

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

Referenced by getRelAlgHints().

2488  {
2489  std::string white_space_delim = " ";
2490  int l = hint_string.length();
2491  hint_string = hint_string.erase(0, 1).substr(0, l - 2);
2492  size_t pos = 0;
2493  if ((pos = hint_string.find("options:")) != std::string::npos) {
2494  // need to parse hint options
2495  std::vector<std::string> tokens;
2496  std::string hint_name = hint_string.substr(0, hint_string.find(white_space_delim));
2497  auto hint_type = RegisteredQueryHint::translateQueryHint(hint_name);
2498  bool kv_list_op = false;
2499  std::string raw_options = hint_string.substr(pos + 8, hint_string.length() - 2);
2500  if (raw_options.find('{') != std::string::npos) {
2501  kv_list_op = true;
2502  } else {
2503  CHECK(raw_options.find('[') != std::string::npos);
2504  }
2505  auto t1 = raw_options.erase(0, 1);
2506  raw_options = t1.substr(0, t1.length() - 1);
2507  std::string op_delim = ", ";
2508  if (kv_list_op) {
2509  // kv options
2510  std::unordered_map<std::string, std::string> kv_options;
2511  while ((pos = raw_options.find(op_delim)) != std::string::npos) {
2512  auto kv_pair = getKVOptionPair(raw_options, pos);
2513  kv_options.emplace(kv_pair.first, kv_pair.second);
2514  }
2515  // handle the last kv pair
2516  auto kv_pair = getKVOptionPair(raw_options, pos);
2517  kv_options.emplace(kv_pair.first, kv_pair.second);
2518  return {hint_type, true, false, true, kv_options};
2519  } else {
2520  std::vector<std::string> list_options;
2521  while ((pos = raw_options.find(op_delim)) != std::string::npos) {
2522  list_options.emplace_back(raw_options.substr(0, pos));
2523  raw_options.erase(0, pos + white_space_delim.length() + 1);
2524  }
2525  // handle the last option
2526  list_options.emplace_back(raw_options.substr(0, pos));
2527  return {hint_type, true, false, false, list_options};
2528  }
2529  } else {
2530  // marker hint: no extra option for this hint
2531  std::string hint_name = hint_string.substr(0, hint_string.find(white_space_delim));
2532  auto hint_type = RegisteredQueryHint::translateQueryHint(hint_name);
2533  return {hint_type, true, true, false};
2534  }
2535  }
static QueryHint translateQueryHint(const std::string &hint_name)
Definition: QueryHint.h:178
#define CHECK(condition)
Definition: Logger.h:203
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 2588 of file RelAlgDagBuilder.cpp.

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

Referenced by getRelAlgInputs().

2588  {
2589  const auto id = node_id(crt_node);
2590  CHECK(id);
2591  CHECK_EQ(static_cast<size_t>(id), nodes_.size());
2592  return nodes_.back();
2593  }
#define CHECK_EQ(x, y)
Definition: Logger.h:211
std::vector< std::shared_ptr< RelAlgNode > > nodes_
#define CHECK(condition)
Definition: Logger.h:203
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 2151 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().

2152  {
2153  for (auto rels_it = rels.Begin(); rels_it != rels.End(); ++rels_it) {
2154  const auto& crt_node = *rels_it;
2155  const auto id = node_id(crt_node);
2156  CHECK_EQ(static_cast<size_t>(id), nodes_.size());
2157  CHECK(crt_node.IsObject());
2158  std::shared_ptr<RelAlgNode> ra_node = nullptr;
2159  const auto rel_op = json_str(field(crt_node, "relOp"));
2160  if (rel_op == std::string("EnumerableTableScan") ||
2161  rel_op == std::string("LogicalTableScan")) {
2162  ra_node = dispatchTableScan(crt_node);
2163  } else if (rel_op == std::string("LogicalProject")) {
2164  ra_node = dispatchProject(crt_node, root_dag_builder);
2165  } else if (rel_op == std::string("LogicalFilter")) {
2166  ra_node = dispatchFilter(crt_node, root_dag_builder);
2167  } else if (rel_op == std::string("LogicalAggregate")) {
2168  ra_node = dispatchAggregate(crt_node);
2169  } else if (rel_op == std::string("LogicalJoin")) {
2170  ra_node = dispatchJoin(crt_node, root_dag_builder);
2171  } else if (rel_op == std::string("LogicalSort")) {
2172  ra_node = dispatchSort(crt_node);
2173  } else if (rel_op == std::string("LogicalValues")) {
2174  ra_node = dispatchLogicalValues(crt_node);
2175  } else if (rel_op == std::string("LogicalTableModify")) {
2176  ra_node = dispatchModify(crt_node);
2177  } else if (rel_op == std::string("LogicalTableFunctionScan")) {
2178  ra_node = dispatchTableFunction(crt_node, root_dag_builder);
2179  } else if (rel_op == std::string("LogicalUnion")) {
2180  ra_node = dispatchUnion(crt_node);
2181  } else {
2182  throw QueryNotSupported(std::string("Node ") + rel_op + " not supported yet");
2183  }
2184  nodes_.push_back(ra_node);
2185  }
2186 
2187  return std::move(nodes_);
2188  }
std::shared_ptr< RelAggregate > dispatchAggregate(const rapidjson::Value &agg_ra)
#define CHECK_EQ(x, y)
Definition: Logger.h:211
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:203
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 2596 of file RelAlgDagBuilder.cpp.

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


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