OmniSciDB  bf83d84833
 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 2123 of file RelAlgDagBuilder.cpp.

Constructor & Destructor Documentation

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

Definition at line 2125 of file RelAlgDagBuilder.cpp.

2125 : 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 2213 of file RelAlgDagBuilder.cpp.

References CHECK, CHECK_EQ, field(), getRelAlgHints(), getRelAlgInputs(), 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().

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

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

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

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

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

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

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

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

Referenced by run().

2324  {
2325  const auto inputs = getRelAlgInputs(table_func_ra);
2326  const auto& invocation = field(table_func_ra, "invocation");
2327  CHECK(invocation.IsObject());
2328 
2329  const auto& operands = field(invocation, "operands");
2330  CHECK(operands.IsArray());
2331  CHECK_GE(operands.Size(), unsigned(0));
2332 
2333  std::vector<const Rex*> col_inputs;
2334  std::vector<std::unique_ptr<const RexScalar>> table_func_inputs;
2335  std::vector<std::string> fields;
2336 
2337  for (auto exprs_json_it = operands.Begin(); exprs_json_it != operands.End();
2338  ++exprs_json_it) {
2339  const auto& expr_json = *exprs_json_it;
2340  CHECK(expr_json.IsObject());
2341  if (expr_json.HasMember("op")) {
2342  const auto op_str = json_str(field(expr_json, "op"));
2343  if (op_str == "CAST" && expr_json.HasMember("type")) {
2344  const auto& expr_type = field(expr_json, "type");
2345  CHECK(expr_type.IsObject());
2346  CHECK(expr_type.HasMember("type"));
2347  const auto& expr_type_name = json_str(field(expr_type, "type"));
2348  if (expr_type_name == "CURSOR") {
2349  CHECK(expr_json.HasMember("operands"));
2350  const auto& expr_operands = field(expr_json, "operands");
2351  CHECK(expr_operands.IsArray());
2352  if (expr_operands.Size() != 1) {
2353  throw std::runtime_error(
2354  "Table functions currently only support one ResultSet input");
2355  }
2356  auto pos = field(expr_operands[0], "input").GetInt();
2357  CHECK_LT(pos, inputs.size());
2358  for (size_t i = inputs[pos]->size(); i > 0; 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  return std::make_shared<RelTableFunction>(op_name.GetString(),
2386  inputs,
2387  fields,
2388  col_inputs,
2389  table_func_inputs,
2390  table_function_projected_outputs);
2391  }
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 2167 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().

2167  {
2168  check_empty_inputs_field(scan_ra);
2169  CHECK(scan_ra.IsObject());
2170  const auto td = getTableFromScanNode(cat_, scan_ra);
2171  const auto field_names = getFieldNamesFromScanNode(scan_ra);
2172  if (scan_ra.HasMember("hints")) {
2173  auto scan_node = std::make_shared<RelScan>(td, field_names);
2174  getRelAlgHints(scan_ra, scan_node);
2175  return scan_node;
2176  }
2177  return std::make_shared<RelScan>(td, field_names);
2178  }
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 2434 of file RelAlgDagBuilder.cpp.

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

Referenced by run().

2435  {
2436  auto inputs = getRelAlgInputs(logical_union_ra);
2437  auto const& all_type_bool = field(logical_union_ra, "all");
2438  CHECK(all_type_bool.IsBool());
2439  return std::make_shared<RelLogicalUnion>(std::move(inputs), all_type_bool.GetBool());
2440  }
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 2454 of file RelAlgDagBuilder.cpp.

Referenced by parseHintString().

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

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

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

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

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

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

References CHECK, and getKVOptionPair().

Referenced by getRelAlgHints().

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

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

Referenced by getRelAlgInputs().

2562  {
2563  const auto id = node_id(crt_node);
2564  CHECK(id);
2565  CHECK_EQ(static_cast<size_t>(id), nodes_.size());
2566  return nodes_.back();
2567  }
#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 2127 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().

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

const Catalog_Namespace::Catalog& details::RelAlgDispatcher::cat_
private
std::vector<std::shared_ptr<RelAlgNode> > details::RelAlgDispatcher::nodes_
private

Definition at line 2570 of file RelAlgDagBuilder.cpp.

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


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