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

Public Member Functions

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

Private Member Functions

std::shared_ptr< RelScandispatchTableScan (const rapidjson::Value &scan_ra)
 
std::shared_ptr< RelProjectdispatchProject (const rapidjson::Value &proj_ra, RelAlgDag &root_dag)
 
std::shared_ptr< RelFilterdispatchFilter (const rapidjson::Value &filter_ra, RelAlgDag &root_dag)
 
std::shared_ptr< RelAggregatedispatchAggregate (const rapidjson::Value &agg_ra)
 
std::shared_ptr< RelJoindispatchJoin (const rapidjson::Value &join_ra, RelAlgDag &root_dag)
 
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, RelAlgDag &root_dag)
 
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 2776 of file RelAlgDag.cpp.

Constructor & Destructor Documentation

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

Definition at line 2778 of file RelAlgDag.cpp.

2778 : cat_(cat) {}
const Catalog_Namespace::Catalog & cat_
Definition: RelAlgDag.cpp:3230

Member Function Documentation

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

Definition at line 2865 of file RelAlgDag.cpp.

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

Referenced by run().

2865  {
2866  const auto inputs = getRelAlgInputs(agg_ra);
2867  CHECK_EQ(size_t(1), inputs.size());
2868  const auto fields = strings_from_json_array(field(agg_ra, "fields"));
2869  const auto group = indices_from_json_array(field(agg_ra, "group"));
2870  for (size_t i = 0; i < group.size(); ++i) {
2871  CHECK_EQ(i, group[i]);
2872  }
2873  if (agg_ra.HasMember("groups") || agg_ra.HasMember("indicator")) {
2874  throw QueryNotSupported("GROUP BY extensions not supported");
2875  }
2876  const auto& aggs_json_arr = field(agg_ra, "aggs");
2877  CHECK(aggs_json_arr.IsArray());
2878  std::vector<std::unique_ptr<const RexAgg>> aggs;
2879  for (auto aggs_json_arr_it = aggs_json_arr.Begin();
2880  aggs_json_arr_it != aggs_json_arr.End();
2881  ++aggs_json_arr_it) {
2882  aggs.emplace_back(parse_aggregate_expr(*aggs_json_arr_it));
2883  }
2884  if (agg_ra.HasMember("hints")) {
2885  auto agg_node =
2886  std::make_shared<RelAggregate>(group.size(), aggs, fields, inputs.front());
2887  getRelAlgHints(agg_ra, agg_node);
2888  return agg_node;
2889  }
2890  return std::make_shared<RelAggregate>(group.size(), aggs, fields, inputs.front());
2891  }
#define CHECK_EQ(x, y)
Definition: Logger.h:297
std::vector< size_t > indices_from_json_array(const rapidjson::Value &json_idx_arr) noexcept
Definition: RelAlgDag.cpp:1325
std::unique_ptr< const RexAgg > parse_aggregate_expr(const rapidjson::Value &expr)
Definition: RelAlgDag.cpp:1338
const rapidjson::Value & field(const rapidjson::Value &obj, const char field[]) noexcept
Definition: JsonAccessors.h:31
std::vector< std::string > strings_from_json_array(const rapidjson::Value &json_str_arr) noexcept
Definition: RelAlgDag.cpp:1313
#define CHECK(condition)
Definition: Logger.h:289
void getRelAlgHints(const rapidjson::Value &json_node, std::shared_ptr< RelAlgNode > node)
Definition: RelAlgDag.cpp:3172
RelAlgInputs getRelAlgInputs(const rapidjson::Value &node)
Definition: RelAlgDag.cpp:3092

+ 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,
RelAlgDag root_dag 
)
inlineprivate

Definition at line 2855 of file RelAlgDag.cpp.

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

Referenced by run().

2856  {
2857  const auto inputs = getRelAlgInputs(filter_ra);
2858  CHECK_EQ(size_t(1), inputs.size());
2859  const auto id = node_id(filter_ra);
2860  CHECK(id);
2861  auto condition = parse_scalar_expr(field(filter_ra, "condition"), cat_, root_dag);
2862  return std::make_shared<RelFilter>(condition, inputs.front());
2863  }
#define CHECK_EQ(x, y)
Definition: Logger.h:297
const Catalog_Namespace::Catalog & cat_
Definition: RelAlgDag.cpp:3230
std::unique_ptr< const RexScalar > parse_scalar_expr(const rapidjson::Value &expr, const Catalog_Namespace::Catalog &cat, RelAlgDag &root_dag)
Definition: RelAlgDag.cpp:1355
const rapidjson::Value & field(const rapidjson::Value &obj, const char field[]) noexcept
Definition: JsonAccessors.h:31
#define CHECK(condition)
Definition: Logger.h:289
unsigned node_id(const rapidjson::Value &ra_node) noexcept
Definition: RelAlgDag.cpp:957
RelAlgInputs getRelAlgInputs(const rapidjson::Value &node)
Definition: RelAlgDag.cpp:3092

+ 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,
RelAlgDag root_dag 
)
inlineprivate

Definition at line 2893 of file RelAlgDag.cpp.

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

Referenced by run().

2894  {
2895  const auto inputs = getRelAlgInputs(join_ra);
2896  CHECK_EQ(size_t(2), inputs.size());
2897  const auto join_type = to_join_type(json_str(field(join_ra, "joinType")));
2898  auto filter_rex = parse_scalar_expr(field(join_ra, "condition"), cat_, root_dag);
2899  if (join_ra.HasMember("hints")) {
2900  auto join_node =
2901  std::make_shared<RelJoin>(inputs[0], inputs[1], filter_rex, join_type);
2902  getRelAlgHints(join_ra, join_node);
2903  return join_node;
2904  }
2905  return std::make_shared<RelJoin>(inputs[0], inputs[1], filter_rex, join_type);
2906  }
#define CHECK_EQ(x, y)
Definition: Logger.h:297
const Catalog_Namespace::Catalog & cat_
Definition: RelAlgDag.cpp:3230
JoinType to_join_type(const std::string &join_type_name)
Definition: RelAlgDag.cpp:1379
const std::string json_str(const rapidjson::Value &obj) noexcept
Definition: JsonAccessors.h:44
std::unique_ptr< const RexScalar > parse_scalar_expr(const rapidjson::Value &expr, const Catalog_Namespace::Catalog &cat, RelAlgDag &root_dag)
Definition: RelAlgDag.cpp:1355
const rapidjson::Value & field(const rapidjson::Value &obj, const char field[]) noexcept
Definition: JsonAccessors.h:31
void getRelAlgHints(const rapidjson::Value &json_node, std::shared_ptr< RelAlgNode > node)
Definition: RelAlgDag.cpp:3172
RelAlgInputs getRelAlgInputs(const rapidjson::Value &node)
Definition: RelAlgDag.cpp:3092

+ 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 3043 of file RelAlgDag.cpp.

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

Referenced by run().

3044  {
3045  const auto& tuple_type_arr = field(logical_values_ra, "type");
3046  CHECK(tuple_type_arr.IsArray());
3047  std::vector<TargetMetaInfo> tuple_type;
3048  for (auto tuple_type_arr_it = tuple_type_arr.Begin();
3049  tuple_type_arr_it != tuple_type_arr.End();
3050  ++tuple_type_arr_it) {
3051  const auto component_type = parse_type(*tuple_type_arr_it);
3052  const auto component_name = json_str(field(*tuple_type_arr_it, "name"));
3053  tuple_type.emplace_back(component_name, component_type);
3054  }
3055  const auto& inputs_arr = field(logical_values_ra, "inputs");
3056  CHECK(inputs_arr.IsArray());
3057  const auto& tuples_arr = field(logical_values_ra, "tuples");
3058  CHECK(tuples_arr.IsArray());
3059 
3060  if (inputs_arr.Size()) {
3061  throw QueryNotSupported("Inputs not supported in logical values yet.");
3062  }
3063 
3064  std::vector<RelLogicalValues::RowValues> values;
3065  if (tuples_arr.Size()) {
3066  for (const auto& row : tuples_arr.GetArray()) {
3067  CHECK(row.IsArray());
3068  const auto values_json = row.GetArray();
3069  if (!values.empty()) {
3070  CHECK_EQ(values[0].size(), values_json.Size());
3071  }
3072  values.emplace_back(RelLogicalValues::RowValues{});
3073  for (const auto& value : values_json) {
3074  CHECK(value.IsObject());
3075  CHECK(value.HasMember("literal"));
3076  values.back().emplace_back(parse_literal(value));
3077  }
3078  }
3079  }
3080 
3081  return std::make_shared<RelLogicalValues>(tuple_type, values);
3082  }
#define CHECK_EQ(x, y)
Definition: Logger.h:297
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
SQLTypeInfo parse_type(const rapidjson::Value &type_obj)
Definition: RelAlgDag.cpp:1065
std::unique_ptr< RexLiteral > parse_literal(const rapidjson::Value &expr)
Definition: RelAlgDag.cpp:979
#define CHECK(condition)
Definition: Logger.h:289
std::vector< std::unique_ptr< const RexScalar >> RowValues
Definition: RelAlgDag.h:2364

+ 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 2930 of file RelAlgDag.cpp.

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

Referenced by run().

2930  {
2931  const auto inputs = getRelAlgInputs(logical_modify_ra);
2932  CHECK_EQ(size_t(1), inputs.size());
2933 
2934  const auto table_descriptor = getTableFromScanNode(cat_, logical_modify_ra);
2935  if (table_descriptor->isView) {
2936  throw std::runtime_error("UPDATE of a view is unsupported.");
2937  }
2938 
2939  bool flattened = json_bool(field(logical_modify_ra, "flattened"));
2940  std::string op = json_str(field(logical_modify_ra, "operation"));
2941  RelModify::TargetColumnList target_column_list;
2942 
2943  if (op == "UPDATE") {
2944  const auto& update_columns = field(logical_modify_ra, "updateColumnList");
2945  CHECK(update_columns.IsArray());
2946 
2947  for (auto column_arr_it = update_columns.Begin();
2948  column_arr_it != update_columns.End();
2949  ++column_arr_it) {
2950  target_column_list.push_back(column_arr_it->GetString());
2951  }
2952  }
2953 
2954  auto modify_node = std::make_shared<RelModify>(
2955  cat_, table_descriptor, flattened, op, target_column_list, inputs[0]);
2956  switch (modify_node->getOperation()) {
2958  modify_node->applyDeleteModificationsToInputNode();
2959  break;
2960  }
2962  modify_node->applyUpdateModificationsToInputNode();
2963  break;
2964  }
2965  default:
2966  throw std::runtime_error("Unsupported RelModify operation: " +
2967  json_node_to_string(logical_modify_ra));
2968  }
2969 
2970  return modify_node;
2971  }
#define CHECK_EQ(x, y)
Definition: Logger.h:297
const Catalog_Namespace::Catalog & cat_
Definition: RelAlgDag.cpp:3230
std::vector< std::string > TargetColumnList
Definition: RelAlgDag.h:2022
const bool json_bool(const rapidjson::Value &obj) noexcept
Definition: JsonAccessors.h:49
std::string json_node_to_string(const rapidjson::Value &node) noexcept
Definition: RelAlgDag.cpp:962
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
#define CHECK(condition)
Definition: Logger.h:289
const TableDescriptor * getTableFromScanNode(const Catalog_Namespace::Catalog &cat, const rapidjson::Value &scan_ra)
Definition: RelAlgDag.cpp:2749
RelAlgInputs getRelAlgInputs(const rapidjson::Value &node)
Definition: RelAlgDag.cpp:3092

+ 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,
RelAlgDag root_dag 
)
inlineprivate

Definition at line 2833 of file RelAlgDag.cpp.

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

Referenced by run().

2834  {
2835  const auto inputs = getRelAlgInputs(proj_ra);
2836  CHECK_EQ(size_t(1), inputs.size());
2837  const auto& exprs_json = field(proj_ra, "exprs");
2838  CHECK(exprs_json.IsArray());
2839  std::vector<std::unique_ptr<const RexScalar>> exprs;
2840  for (auto exprs_json_it = exprs_json.Begin(); exprs_json_it != exprs_json.End();
2841  ++exprs_json_it) {
2842  exprs.emplace_back(parse_scalar_expr(*exprs_json_it, cat_, root_dag));
2843  }
2844  const auto& fields = field(proj_ra, "fields");
2845  if (proj_ra.HasMember("hints")) {
2846  auto project_node = std::make_shared<RelProject>(
2847  exprs, strings_from_json_array(fields), inputs.front());
2848  getRelAlgHints(proj_ra, project_node);
2849  return project_node;
2850  }
2851  return std::make_shared<RelProject>(
2852  exprs, strings_from_json_array(fields), inputs.front());
2853  }
#define CHECK_EQ(x, y)
Definition: Logger.h:297
const Catalog_Namespace::Catalog & cat_
Definition: RelAlgDag.cpp:3230
std::unique_ptr< const RexScalar > parse_scalar_expr(const rapidjson::Value &expr, const Catalog_Namespace::Catalog &cat, RelAlgDag &root_dag)
Definition: RelAlgDag.cpp:1355
const rapidjson::Value & field(const rapidjson::Value &obj, const char field[]) noexcept
Definition: JsonAccessors.h:31
std::vector< std::string > strings_from_json_array(const rapidjson::Value &json_str_arr) noexcept
Definition: RelAlgDag.cpp:1313
#define CHECK(condition)
Definition: Logger.h:289
void getRelAlgHints(const rapidjson::Value &json_node, std::shared_ptr< RelAlgNode > node)
Definition: RelAlgDag.cpp:3172
RelAlgInputs getRelAlgInputs(const rapidjson::Value &node)
Definition: RelAlgDag.cpp:3092

+ 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 2908 of file RelAlgDag.cpp.

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

Referenced by run().

2908  {
2909  const auto inputs = getRelAlgInputs(sort_ra);
2910  CHECK_EQ(size_t(1), inputs.size());
2911  std::vector<SortField> collation;
2912  const auto& collation_arr = field(sort_ra, "collation");
2913  CHECK(collation_arr.IsArray());
2914  for (auto collation_arr_it = collation_arr.Begin();
2915  collation_arr_it != collation_arr.End();
2916  ++collation_arr_it) {
2917  const size_t field_idx = json_i64(field(*collation_arr_it, "field"));
2918  const auto sort_dir = parse_sort_direction(*collation_arr_it);
2919  const auto null_pos = parse_nulls_position(*collation_arr_it);
2920  collation.emplace_back(field_idx, sort_dir, null_pos);
2921  }
2922  auto limit = get_int_literal_field(sort_ra, "fetch", -1);
2923  const auto offset = get_int_literal_field(sort_ra, "offset", 0);
2924  auto ret = std::make_shared<RelSort>(
2925  collation, limit > 0 ? limit : 0, offset, inputs.front(), limit > 0);
2926  ret->setEmptyResult(limit == 0);
2927  return ret;
2928  }
NullSortedPosition parse_nulls_position(const rapidjson::Value &collation)
Definition: RelAlgDag.cpp:1179
#define CHECK_EQ(x, y)
Definition: Logger.h:297
const rapidjson::Value & field(const rapidjson::Value &obj, const char field[]) noexcept
Definition: JsonAccessors.h:31
const int64_t json_i64(const rapidjson::Value &obj) noexcept
Definition: JsonAccessors.h:39
int64_t get_int_literal_field(const rapidjson::Value &obj, const char field[], const int64_t default_val) noexcept
Definition: RelAlgDag.cpp:2730
#define CHECK(condition)
Definition: Logger.h:289
SortDirection parse_sort_direction(const rapidjson::Value &collation)
Definition: RelAlgDag.cpp:1173
RelAlgInputs getRelAlgInputs(const rapidjson::Value &node)
Definition: RelAlgDag.cpp:3092

+ 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,
RelAlgDag root_dag 
)
inlineprivate

Definition at line 2973 of file RelAlgDag.cpp.

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

Referenced by run().

2975  {
2976  const auto inputs = getRelAlgInputs(table_func_ra);
2977  const auto& invocation = field(table_func_ra, "invocation");
2978  CHECK(invocation.IsObject());
2979 
2980  const auto& operands = field(invocation, "operands");
2981  CHECK(operands.IsArray());
2982  CHECK_GE(operands.Size(), unsigned(0));
2983 
2984  std::vector<const Rex*> col_inputs;
2985  std::vector<std::unique_ptr<const RexScalar>> table_func_inputs;
2986  std::vector<std::string> fields;
2987 
2988  for (auto exprs_json_it = operands.Begin(); exprs_json_it != operands.End();
2989  ++exprs_json_it) {
2990  const auto& expr_json = *exprs_json_it;
2991  CHECK(expr_json.IsObject());
2992  if (expr_json.HasMember("op")) {
2993  const auto op_str = json_str(field(expr_json, "op"));
2994  if (op_str == "CAST" && expr_json.HasMember("type")) {
2995  const auto& expr_type = field(expr_json, "type");
2996  CHECK(expr_type.IsObject());
2997  CHECK(expr_type.HasMember("type"));
2998  const auto& expr_type_name = json_str(field(expr_type, "type"));
2999  if (expr_type_name == "CURSOR") {
3000  CHECK(expr_json.HasMember("operands"));
3001  const auto& expr_operands = field(expr_json, "operands");
3002  CHECK(expr_operands.IsArray());
3003  if (expr_operands.Size() != 1) {
3004  throw std::runtime_error(
3005  "Table functions currently only support one ResultSet input");
3006  }
3007  auto pos = field(expr_operands[0], "input").GetInt();
3008  CHECK_LT(pos, inputs.size());
3009  for (size_t i = inputs[pos]->size(); i > 0; i--) {
3010  table_func_inputs.emplace_back(
3011  std::make_unique<RexAbstractInput>(col_inputs.size()));
3012  col_inputs.emplace_back(table_func_inputs.back().get());
3013  }
3014  continue;
3015  }
3016  }
3017  }
3018  table_func_inputs.emplace_back(parse_scalar_expr(*exprs_json_it, cat_, root_dag));
3019  }
3020 
3021  const auto& op_name = field(invocation, "op");
3022  CHECK(op_name.IsString());
3023 
3024  std::vector<std::unique_ptr<const RexScalar>> table_function_projected_outputs;
3025  const auto& row_types = field(table_func_ra, "rowType");
3026  CHECK(row_types.IsArray());
3027  CHECK_GE(row_types.Size(), unsigned(0));
3028  const auto& row_types_array = row_types.GetArray();
3029  for (size_t i = 0; i < row_types_array.Size(); i++) {
3030  // We don't care about the type information in rowType -- replace each output with
3031  // a reference to be resolved later in the translator
3032  table_function_projected_outputs.emplace_back(std::make_unique<RexRef>(i));
3033  fields.emplace_back("");
3034  }
3035  return std::make_shared<RelTableFunction>(op_name.GetString(),
3036  inputs,
3037  fields,
3038  col_inputs,
3039  table_func_inputs,
3040  table_function_projected_outputs);
3041  }
const Catalog_Namespace::Catalog & cat_
Definition: RelAlgDag.cpp:3230
const std::string json_str(const rapidjson::Value &obj) noexcept
Definition: JsonAccessors.h:44
#define CHECK_GE(x, y)
Definition: Logger.h:302
std::unique_ptr< const RexScalar > parse_scalar_expr(const rapidjson::Value &expr, const Catalog_Namespace::Catalog &cat, RelAlgDag &root_dag)
Definition: RelAlgDag.cpp:1355
const rapidjson::Value & field(const rapidjson::Value &obj, const char field[]) noexcept
Definition: JsonAccessors.h:31
#define CHECK_LT(x, y)
Definition: Logger.h:299
#define CHECK(condition)
Definition: Logger.h:289
RelAlgInputs getRelAlgInputs(const rapidjson::Value &node)
Definition: RelAlgDag.cpp:3092

+ 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 2820 of file RelAlgDag.cpp.

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

Referenced by run().

2820  {
2821  check_empty_inputs_field(scan_ra);
2822  CHECK(scan_ra.IsObject());
2823  const auto td = getTableFromScanNode(cat_, scan_ra);
2824  const auto field_names = getFieldNamesFromScanNode(scan_ra);
2825  if (scan_ra.HasMember("hints")) {
2826  auto scan_node = std::make_shared<RelScan>(td, field_names);
2827  getRelAlgHints(scan_ra, scan_node);
2828  return scan_node;
2829  }
2830  return std::make_shared<RelScan>(td, field_names);
2831  }
const Catalog_Namespace::Catalog & cat_
Definition: RelAlgDag.cpp:3230
#define CHECK(condition)
Definition: Logger.h:289
void getRelAlgHints(const rapidjson::Value &json_node, std::shared_ptr< RelAlgNode > node)
Definition: RelAlgDag.cpp:3172
void check_empty_inputs_field(const rapidjson::Value &node) noexcept
Definition: RelAlgDag.cpp:2744
const TableDescriptor * getTableFromScanNode(const Catalog_Namespace::Catalog &cat, const rapidjson::Value &scan_ra)
Definition: RelAlgDag.cpp:2749
std::vector< std::string > getFieldNamesFromScanNode(const rapidjson::Value &scan_ra)
Definition: RelAlgDag.cpp:2759

+ 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 3084 of file RelAlgDag.cpp.

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

Referenced by run().

3085  {
3086  auto inputs = getRelAlgInputs(logical_union_ra);
3087  auto const& all_type_bool = field(logical_union_ra, "all");
3088  CHECK(all_type_bool.IsBool());
3089  return std::make_shared<RelLogicalUnion>(std::move(inputs), all_type_bool.GetBool());
3090  }
const rapidjson::Value & field(const rapidjson::Value &obj, const char field[]) noexcept
Definition: JsonAccessors.h:31
#define CHECK(condition)
Definition: Logger.h:289
RelAlgInputs getRelAlgInputs(const rapidjson::Value &node)
Definition: RelAlgDag.cpp:3092

+ 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 3104 of file RelAlgDag.cpp.

Referenced by parseHintString().

3104  {
3105  auto option = str.substr(0, pos);
3106  std::string delim = "=";
3107  size_t delim_pos = option.find(delim);
3108  auto key = option.substr(0, delim_pos);
3109  auto val = option.substr(delim_pos + 1, option.length());
3110  str.erase(0, pos + delim.length() + 1);
3111  return {key, val};
3112  }

+ 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 3172 of file RelAlgDag.cpp.

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

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

3173  {
3174  std::string hint_explained = json_str(field(json_node, "hints"));
3175  size_t pos = 0;
3176  std::string delim = "|";
3177  std::vector<std::string> hint_list;
3178  while ((pos = hint_explained.find(delim)) != std::string::npos) {
3179  hint_list.emplace_back(hint_explained.substr(0, pos));
3180  hint_explained.erase(0, pos + delim.length());
3181  }
3182  // handling the last one
3183  hint_list.emplace_back(hint_explained.substr(0, pos));
3184 
3185  const auto agg_node = std::dynamic_pointer_cast<RelAggregate>(node);
3186  if (agg_node) {
3187  for (std::string& hint : hint_list) {
3188  auto parsed_hint = parseHintString(hint);
3189  agg_node->addHint(parsed_hint);
3190  }
3191  }
3192  const auto project_node = std::dynamic_pointer_cast<RelProject>(node);
3193  if (project_node) {
3194  for (std::string& hint : hint_list) {
3195  auto parsed_hint = parseHintString(hint);
3196  project_node->addHint(parsed_hint);
3197  }
3198  }
3199  const auto scan_node = std::dynamic_pointer_cast<RelScan>(node);
3200  if (scan_node) {
3201  for (std::string& hint : hint_list) {
3202  auto parsed_hint = parseHintString(hint);
3203  scan_node->addHint(parsed_hint);
3204  }
3205  }
3206  const auto join_node = std::dynamic_pointer_cast<RelJoin>(node);
3207  if (join_node) {
3208  for (std::string& hint : hint_list) {
3209  auto parsed_hint = parseHintString(hint);
3210  join_node->addHint(parsed_hint);
3211  }
3212  }
3213 
3214  const auto compound_node = std::dynamic_pointer_cast<RelCompound>(node);
3215  if (compound_node) {
3216  for (std::string& hint : hint_list) {
3217  auto parsed_hint = parseHintString(hint);
3218  compound_node->addHint(parsed_hint);
3219  }
3220  }
3221  }
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)
Definition: RelAlgDag.cpp:3114

+ 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 3092 of file RelAlgDag.cpp.

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

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

3092  {
3093  if (node.HasMember("inputs")) {
3094  const auto str_input_ids = strings_from_json_array(field(node, "inputs"));
3095  RelAlgInputs ra_inputs;
3096  for (const auto& str_id : str_input_ids) {
3097  ra_inputs.push_back(nodes_[std::stoi(str_id)]);
3098  }
3099  return ra_inputs;
3100  }
3101  return {prev(node)};
3102  }
const rapidjson::Value & field(const rapidjson::Value &obj, const char field[]) noexcept
Definition: JsonAccessors.h:31
std::vector< std::shared_ptr< const RelAlgNode >> RelAlgInputs
Definition: RelAlgDag.h:316
std::vector< std::shared_ptr< RelAlgNode > > nodes_
Definition: RelAlgDag.cpp:3231
std::vector< std::string > strings_from_json_array(const rapidjson::Value &json_str_arr) noexcept
Definition: RelAlgDag.cpp:1313
std::shared_ptr< const RelAlgNode > prev(const rapidjson::Value &crt_node)
Definition: RelAlgDag.cpp:3223

+ 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 3114 of file RelAlgDag.cpp.

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

Referenced by getRelAlgHints().

3114  {
3115  std::string white_space_delim = " ";
3116  int l = hint_string.length();
3117  hint_string = hint_string.erase(0, 1).substr(0, l - 2);
3118  size_t pos = 0;
3119  auto global_hint_checker = [&](const std::string& input_hint_name) -> HintIdentifier {
3120  bool global_hint = false;
3121  std::string hint_name = input_hint_name;
3122  auto global_hint_identifier = hint_name.substr(0, 2);
3123  if (global_hint_identifier.compare("g_") == 0) {
3124  global_hint = true;
3125  hint_name = hint_name.substr(2, hint_string.length());
3126  }
3127  return {global_hint, hint_name};
3128  };
3129  auto parsed_hint =
3130  global_hint_checker(hint_string.substr(0, hint_string.find(white_space_delim)));
3131  auto hint_type = RegisteredQueryHint::translateQueryHint(parsed_hint.hint_name);
3132  if ((pos = hint_string.find("options:")) != std::string::npos) {
3133  // need to parse hint options
3134  std::vector<std::string> tokens;
3135  bool kv_list_op = false;
3136  std::string raw_options = hint_string.substr(pos + 8, hint_string.length() - 2);
3137  if (raw_options.find('{') != std::string::npos) {
3138  kv_list_op = true;
3139  } else {
3140  CHECK(raw_options.find('[') != std::string::npos);
3141  }
3142  auto t1 = raw_options.erase(0, 1);
3143  raw_options = t1.substr(0, t1.length() - 1);
3144  std::string op_delim = ", ";
3145  if (kv_list_op) {
3146  // kv options
3147  std::unordered_map<std::string, std::string> kv_options;
3148  while ((pos = raw_options.find(op_delim)) != std::string::npos) {
3149  auto kv_pair = getKVOptionPair(raw_options, pos);
3150  kv_options.emplace(kv_pair.first, kv_pair.second);
3151  }
3152  // handle the last kv pair
3153  auto kv_pair = getKVOptionPair(raw_options, pos);
3154  kv_options.emplace(kv_pair.first, kv_pair.second);
3155  return {hint_type, parsed_hint.global_hint, false, true, kv_options};
3156  } else {
3157  std::vector<std::string> list_options;
3158  while ((pos = raw_options.find(op_delim)) != std::string::npos) {
3159  list_options.emplace_back(raw_options.substr(0, pos));
3160  raw_options.erase(0, pos + white_space_delim.length() + 1);
3161  }
3162  // handle the last option
3163  list_options.emplace_back(raw_options.substr(0, pos));
3164  return {hint_type, parsed_hint.global_hint, false, false, list_options};
3165  }
3166  } else {
3167  // marker hint: no extra option for this hint
3168  return {hint_type, parsed_hint.global_hint, true, false};
3169  }
3170  }
static QueryHint translateQueryHint(const std::string &hint_name)
Definition: QueryHint.h:332
#define CHECK(condition)
Definition: Logger.h:289
std::pair< std::string, std::string > getKVOptionPair(std::string &str, size_t &pos)
Definition: RelAlgDag.cpp:3104

+ 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 3223 of file RelAlgDag.cpp.

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

Referenced by getRelAlgInputs().

3223  {
3224  const auto id = node_id(crt_node);
3225  CHECK(id);
3226  CHECK_EQ(static_cast<size_t>(id), nodes_.size());
3227  return nodes_.back();
3228  }
#define CHECK_EQ(x, y)
Definition: Logger.h:297
std::vector< std::shared_ptr< RelAlgNode > > nodes_
Definition: RelAlgDag.cpp:3231
#define CHECK(condition)
Definition: Logger.h:289
unsigned node_id(const rapidjson::Value &ra_node) noexcept
Definition: RelAlgDag.cpp:957

+ 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,
RelAlgDag root_dag 
)
inline

Definition at line 2780 of file RelAlgDag.cpp.

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

Referenced by RelAlgDagBuilder::build().

2781  {
2782  for (auto rels_it = rels.Begin(); rels_it != rels.End(); ++rels_it) {
2783  const auto& crt_node = *rels_it;
2784  const auto id = node_id(crt_node);
2785  CHECK_EQ(static_cast<size_t>(id), nodes_.size());
2786  CHECK(crt_node.IsObject());
2787  std::shared_ptr<RelAlgNode> ra_node = nullptr;
2788  const auto rel_op = json_str(field(crt_node, "relOp"));
2789  if (rel_op == std::string("EnumerableTableScan") ||
2790  rel_op == std::string("LogicalTableScan")) {
2791  ra_node = dispatchTableScan(crt_node);
2792  } else if (rel_op == std::string("LogicalProject")) {
2793  ra_node = dispatchProject(crt_node, root_dag);
2794  } else if (rel_op == std::string("LogicalFilter")) {
2795  ra_node = dispatchFilter(crt_node, root_dag);
2796  } else if (rel_op == std::string("LogicalAggregate")) {
2797  ra_node = dispatchAggregate(crt_node);
2798  } else if (rel_op == std::string("LogicalJoin")) {
2799  ra_node = dispatchJoin(crt_node, root_dag);
2800  } else if (rel_op == std::string("LogicalSort")) {
2801  ra_node = dispatchSort(crt_node);
2802  } else if (rel_op == std::string("LogicalValues")) {
2803  ra_node = dispatchLogicalValues(crt_node);
2804  } else if (rel_op == std::string("LogicalTableModify")) {
2805  ra_node = dispatchModify(crt_node);
2806  } else if (rel_op == std::string("LogicalTableFunctionScan")) {
2807  ra_node = dispatchTableFunction(crt_node, root_dag);
2808  } else if (rel_op == std::string("LogicalUnion")) {
2809  ra_node = dispatchUnion(crt_node);
2810  } else {
2811  throw QueryNotSupported(std::string("Node ") + rel_op + " not supported yet");
2812  }
2813  nodes_.push_back(ra_node);
2814  }
2815 
2816  return std::move(nodes_);
2817  }
std::shared_ptr< RelAggregate > dispatchAggregate(const rapidjson::Value &agg_ra)
Definition: RelAlgDag.cpp:2865
#define CHECK_EQ(x, y)
Definition: Logger.h:297
std::shared_ptr< RelFilter > dispatchFilter(const rapidjson::Value &filter_ra, RelAlgDag &root_dag)
Definition: RelAlgDag.cpp:2855
std::shared_ptr< RelScan > dispatchTableScan(const rapidjson::Value &scan_ra)
Definition: RelAlgDag.cpp:2820
std::shared_ptr< RelLogicalUnion > dispatchUnion(const rapidjson::Value &logical_union_ra)
Definition: RelAlgDag.cpp:3084
std::shared_ptr< RelProject > dispatchProject(const rapidjson::Value &proj_ra, RelAlgDag &root_dag)
Definition: RelAlgDag.cpp:2833
const std::string json_str(const rapidjson::Value &obj) noexcept
Definition: JsonAccessors.h:44
std::shared_ptr< RelJoin > dispatchJoin(const rapidjson::Value &join_ra, RelAlgDag &root_dag)
Definition: RelAlgDag.cpp:2893
const rapidjson::Value & field(const rapidjson::Value &obj, const char field[]) noexcept
Definition: JsonAccessors.h:31
std::shared_ptr< RelTableFunction > dispatchTableFunction(const rapidjson::Value &table_func_ra, RelAlgDag &root_dag)
Definition: RelAlgDag.cpp:2973
std::vector< std::shared_ptr< RelAlgNode > > nodes_
Definition: RelAlgDag.cpp:3231
std::shared_ptr< RelModify > dispatchModify(const rapidjson::Value &logical_modify_ra)
Definition: RelAlgDag.cpp:2930
std::shared_ptr< RelSort > dispatchSort(const rapidjson::Value &sort_ra)
Definition: RelAlgDag.cpp:2908
#define CHECK(condition)
Definition: Logger.h:289
unsigned node_id(const rapidjson::Value &ra_node) noexcept
Definition: RelAlgDag.cpp:957
std::shared_ptr< RelLogicalValues > dispatchLogicalValues(const rapidjson::Value &logical_values_ra)
Definition: RelAlgDag.cpp:3043

+ 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 3231 of file RelAlgDag.cpp.

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


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