OmniSciDB  85c2d10cdc
 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)
 
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 2127 of file RelAlgDagBuilder.cpp.

Constructor & Destructor Documentation

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

Definition at line 2129 of file RelAlgDagBuilder.cpp.

2129 : 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 2217 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().

2217  {
2218  const auto inputs = getRelAlgInputs(agg_ra);
2219  CHECK_EQ(size_t(1), inputs.size());
2220  const auto fields = strings_from_json_array(field(agg_ra, "fields"));
2221  const auto group = indices_from_json_array(field(agg_ra, "group"));
2222  for (size_t i = 0; i < group.size(); ++i) {
2223  CHECK_EQ(i, group[i]);
2224  }
2225  if (agg_ra.HasMember("groups") || agg_ra.HasMember("indicator")) {
2226  throw QueryNotSupported("GROUP BY extensions not supported");
2227  }
2228  const auto& aggs_json_arr = field(agg_ra, "aggs");
2229  CHECK(aggs_json_arr.IsArray());
2230  std::vector<std::unique_ptr<const RexAgg>> aggs;
2231  for (auto aggs_json_arr_it = aggs_json_arr.Begin();
2232  aggs_json_arr_it != aggs_json_arr.End();
2233  ++aggs_json_arr_it) {
2234  aggs.emplace_back(parse_aggregate_expr(*aggs_json_arr_it));
2235  }
2236  if (agg_ra.HasMember("hints")) {
2237  auto agg_node =
2238  std::make_shared<RelAggregate>(group.size(), aggs, fields, inputs.front());
2239  getRelAlgHints(agg_ra, agg_node);
2240  return agg_node;
2241  }
2242  return std::make_shared<RelAggregate>(group.size(), aggs, fields, inputs.front());
2243  }
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:

+ 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 2206 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().

2207  {
2208  const auto inputs = getRelAlgInputs(filter_ra);
2209  CHECK_EQ(size_t(1), inputs.size());
2210  const auto id = node_id(filter_ra);
2211  CHECK(id);
2212  auto condition =
2213  parse_scalar_expr(field(filter_ra, "condition"), cat_, root_dag_builder);
2214  return std::make_shared<RelFilter>(condition, inputs.front());
2215  }
#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:

+ 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 2245 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().

2246  {
2247  const auto inputs = getRelAlgInputs(join_ra);
2248  CHECK_EQ(size_t(2), inputs.size());
2249  const auto join_type = to_join_type(json_str(field(join_ra, "joinType")));
2250  auto filter_rex =
2251  parse_scalar_expr(field(join_ra, "condition"), cat_, root_dag_builder);
2252  if (join_ra.HasMember("hints")) {
2253  auto join_node =
2254  std::make_shared<RelJoin>(inputs[0], inputs[1], filter_rex, join_type);
2255  getRelAlgHints(join_ra, join_node);
2256  return join_node;
2257  }
2258  return std::make_shared<RelJoin>(inputs[0], inputs[1], filter_rex, join_type);
2259  }
#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:

+ 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 2397 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().

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

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

+ 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 2184 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().

2185  {
2186  const auto inputs = getRelAlgInputs(proj_ra);
2187  CHECK_EQ(size_t(1), inputs.size());
2188  const auto& exprs_json = field(proj_ra, "exprs");
2189  CHECK(exprs_json.IsArray());
2190  std::vector<std::unique_ptr<const RexScalar>> exprs;
2191  for (auto exprs_json_it = exprs_json.Begin(); exprs_json_it != exprs_json.End();
2192  ++exprs_json_it) {
2193  exprs.emplace_back(parse_scalar_expr(*exprs_json_it, cat_, root_dag_builder));
2194  }
2195  const auto& fields = field(proj_ra, "fields");
2196  if (proj_ra.HasMember("hints")) {
2197  auto project_node = std::make_shared<RelProject>(
2198  exprs, strings_from_json_array(fields), inputs.front());
2199  getRelAlgHints(proj_ra, project_node);
2200  return project_node;
2201  }
2202  return std::make_shared<RelProject>(
2203  exprs, strings_from_json_array(fields), inputs.front());
2204  }
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:

+ Here is the caller graph for this function:

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

Definition at line 2261 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().

2261  {
2262  const auto inputs = getRelAlgInputs(sort_ra);
2263  CHECK_EQ(size_t(1), inputs.size());
2264  std::vector<SortField> collation;
2265  const auto& collation_arr = field(sort_ra, "collation");
2266  CHECK(collation_arr.IsArray());
2267  for (auto collation_arr_it = collation_arr.Begin();
2268  collation_arr_it != collation_arr.End();
2269  ++collation_arr_it) {
2270  const size_t field_idx = json_i64(field(*collation_arr_it, "field"));
2271  const auto sort_dir = parse_sort_direction(*collation_arr_it);
2272  const auto null_pos = parse_nulls_position(*collation_arr_it);
2273  collation.emplace_back(field_idx, sort_dir, null_pos);
2274  }
2275  auto limit = get_int_literal_field(sort_ra, "fetch", -1);
2276  const auto offset = get_int_literal_field(sort_ra, "offset", 0);
2277  auto ret = std::make_shared<RelSort>(
2278  collation, limit > 0 ? limit : 0, offset, inputs.front());
2279  ret->setEmptyResult(limit == 0);
2280  return ret;
2281  }
#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:

+ 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 2326 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().

2328  {
2329  const auto inputs = getRelAlgInputs(table_func_ra);
2330  const auto& invocation = field(table_func_ra, "invocation");
2331  CHECK(invocation.IsObject());
2332 
2333  const auto& operands = field(invocation, "operands");
2334  CHECK(operands.IsArray());
2335  CHECK_GE(operands.Size(), unsigned(0));
2336 
2337  std::vector<const Rex*> col_inputs;
2338  std::vector<std::unique_ptr<const RexScalar>> table_func_inputs;
2339  std::vector<std::string> fields;
2340 
2341  for (auto exprs_json_it = operands.Begin(); exprs_json_it != operands.End();
2342  ++exprs_json_it) {
2343  const auto& expr_json = *exprs_json_it;
2344  CHECK(expr_json.IsObject());
2345  if (expr_json.HasMember("op")) {
2346  const auto op_str = json_str(field(expr_json, "op"));
2347  if (op_str == "CAST" && expr_json.HasMember("type")) {
2348  const auto& expr_type = field(expr_json, "type");
2349  CHECK(expr_type.IsObject());
2350  CHECK(expr_type.HasMember("type"));
2351  const auto& expr_type_name = json_str(field(expr_type, "type"));
2352  if (expr_type_name == "CURSOR") {
2353  CHECK(expr_json.HasMember("operands"));
2354  const auto& expr_operands = field(expr_json, "operands");
2355  CHECK(expr_operands.IsArray());
2356  if (expr_operands.Size() != 1) {
2357  throw std::runtime_error(
2358  "Table functions currently only support one ResultSet input");
2359  }
2360  auto pos = field(expr_operands[0], "input").GetInt();
2361  CHECK_LT(pos, inputs.size());
2362  for (size_t i = inputs[pos]->size(); i > 0; i--) {
2363  table_func_inputs.emplace_back(
2364  std::make_unique<RexAbstractInput>(col_inputs.size()));
2365  col_inputs.emplace_back(table_func_inputs.back().get());
2366  }
2367  continue;
2368  }
2369  }
2370  }
2371  table_func_inputs.emplace_back(
2372  parse_scalar_expr(*exprs_json_it, cat_, root_dag_builder));
2373  }
2374 
2375  const auto& op_name = field(invocation, "op");
2376  CHECK(op_name.IsString());
2377 
2378  std::vector<std::unique_ptr<const RexScalar>> table_function_projected_outputs;
2379  const auto& row_types = field(table_func_ra, "rowType");
2380  CHECK(row_types.IsArray());
2381  CHECK_GE(row_types.Size(), unsigned(0));
2382  const auto& row_types_array = row_types.GetArray();
2383  for (size_t i = 0; i < row_types_array.Size(); i++) {
2384  // We don't care about the type information in rowType -- replace each output with
2385  // a reference to be resolved later in the translator
2386  table_function_projected_outputs.emplace_back(std::make_unique<RexRef>(i));
2387  fields.emplace_back("");
2388  }
2389  return std::make_shared<RelTableFunction>(op_name.GetString(),
2390  inputs,
2391  fields,
2392  col_inputs,
2393  table_func_inputs,
2394  table_function_projected_outputs);
2395  }
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_LT(x, y)
Definition: Logger.h:207
#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)
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 2171 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().

2171  {
2172  check_empty_inputs_field(scan_ra);
2173  CHECK(scan_ra.IsObject());
2174  const auto td = getTableFromScanNode(cat_, scan_ra);
2175  const auto field_names = getFieldNamesFromScanNode(scan_ra);
2176  if (scan_ra.HasMember("hints")) {
2177  auto scan_node = std::make_shared<RelScan>(td, field_names);
2178  getRelAlgHints(scan_ra, scan_node);
2179  return scan_node;
2180  }
2181  return std::make_shared<RelScan>(td, field_names);
2182  }
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:

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

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

Referenced by run().

2439  {
2440  auto inputs = getRelAlgInputs(logical_union_ra);
2441  auto const& all_type_bool = field(logical_union_ra, "all");
2442  CHECK(all_type_bool.IsBool());
2443  return std::make_shared<RelLogicalUnion>(std::move(inputs), all_type_bool.GetBool());
2444  }
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:

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

Referenced by parseHintString().

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

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

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

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

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

+ Here is the caller graph for this function:

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

Definition at line 2446 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().

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

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

Definition at line 2468 of file RelAlgDagBuilder.cpp.

References CHECK, and getKVOptionPair().

Referenced by getRelAlgHints().

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

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

Referenced by getRelAlgInputs().

2566  {
2567  const auto id = node_id(crt_node);
2568  CHECK(id);
2569  CHECK_EQ(static_cast<size_t>(id), nodes_.size());
2570  return nodes_.back();
2571  }
#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:

+ 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 2131 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().

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

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

Definition at line 2574 of file RelAlgDagBuilder.cpp.

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


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