OmniSciDB  c1a53651b2
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
details::RelAlgDispatcher Class Reference

Public Member Functions

 RelAlgDispatcher ()
 
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

std::vector< std::shared_ptr
< RelAlgNode > > 
nodes_
 

Detailed Description

Definition at line 2771 of file RelAlgDag.cpp.

Constructor & Destructor Documentation

details::RelAlgDispatcher::RelAlgDispatcher ( )
inline

Definition at line 2773 of file RelAlgDag.cpp.

2773 {}

Member Function Documentation

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

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

2860  {
2861  const auto inputs = getRelAlgInputs(agg_ra);
2862  CHECK_EQ(size_t(1), inputs.size());
2863  const auto fields = strings_from_json_array(field(agg_ra, "fields"));
2864  const auto group = indices_from_json_array(field(agg_ra, "group"));
2865  for (size_t i = 0; i < group.size(); ++i) {
2866  CHECK_EQ(i, group[i]);
2867  }
2868  if (agg_ra.HasMember("groups") || agg_ra.HasMember("indicator")) {
2869  throw QueryNotSupported("GROUP BY extensions not supported");
2870  }
2871  const auto& aggs_json_arr = field(agg_ra, "aggs");
2872  CHECK(aggs_json_arr.IsArray());
2873  std::vector<std::unique_ptr<const RexAgg>> aggs;
2874  for (auto aggs_json_arr_it = aggs_json_arr.Begin();
2875  aggs_json_arr_it != aggs_json_arr.End();
2876  ++aggs_json_arr_it) {
2877  aggs.emplace_back(parse_aggregate_expr(*aggs_json_arr_it));
2878  }
2879  if (agg_ra.HasMember("hints")) {
2880  auto agg_node =
2881  std::make_shared<RelAggregate>(group.size(), aggs, fields, inputs.front());
2882  getRelAlgHints(agg_ra, agg_node);
2883  return agg_node;
2884  }
2885  return std::make_shared<RelAggregate>(group.size(), aggs, fields, inputs.front());
2886  }
#define CHECK_EQ(x, y)
Definition: Logger.h:301
std::vector< size_t > indices_from_json_array(const rapidjson::Value &json_idx_arr) noexcept
Definition: RelAlgDag.cpp:1317
std::unique_ptr< const RexAgg > parse_aggregate_expr(const rapidjson::Value &expr)
Definition: RelAlgDag.cpp:1330
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:1305
#define CHECK(condition)
Definition: Logger.h:291
void getRelAlgHints(const rapidjson::Value &json_node, std::shared_ptr< RelAlgNode > node)
Definition: RelAlgDag.cpp:3174
RelAlgInputs getRelAlgInputs(const rapidjson::Value &node)
Definition: RelAlgDag.cpp:3094

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

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

Referenced by run().

2851  {
2852  const auto inputs = getRelAlgInputs(filter_ra);
2853  CHECK_EQ(size_t(1), inputs.size());
2854  const auto id = node_id(filter_ra);
2855  CHECK(id);
2856  auto condition = parse_scalar_expr(field(filter_ra, "condition"), root_dag);
2857  return std::make_shared<RelFilter>(condition, inputs.front());
2858  }
#define CHECK_EQ(x, y)
Definition: Logger.h:301
const rapidjson::Value & field(const rapidjson::Value &obj, const char field[]) noexcept
Definition: JsonAccessors.h:31
#define CHECK(condition)
Definition: Logger.h:291
std::unique_ptr< const RexScalar > parse_scalar_expr(const rapidjson::Value &expr, RelAlgDag &root_dag)
Definition: RelAlgDag.cpp:1347
unsigned node_id(const rapidjson::Value &ra_node) noexcept
Definition: RelAlgDag.cpp:957
RelAlgInputs getRelAlgInputs(const rapidjson::Value &node)
Definition: RelAlgDag.cpp:3094

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

References 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().

2889  {
2890  const auto inputs = getRelAlgInputs(join_ra);
2891  CHECK_EQ(size_t(2), inputs.size());
2892  const auto join_type = to_join_type(json_str(field(join_ra, "joinType")));
2893  auto filter_rex = parse_scalar_expr(field(join_ra, "condition"), root_dag);
2894  if (join_ra.HasMember("hints")) {
2895  auto join_node =
2896  std::make_shared<RelJoin>(inputs[0], inputs[1], filter_rex, join_type);
2897  getRelAlgHints(join_ra, join_node);
2898  return join_node;
2899  }
2900  return std::make_shared<RelJoin>(inputs[0], inputs[1], filter_rex, join_type);
2901  }
#define CHECK_EQ(x, y)
Definition: Logger.h:301
JoinType to_join_type(const std::string &join_type_name)
Definition: RelAlgDag.cpp:1370
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, RelAlgDag &root_dag)
Definition: RelAlgDag.cpp:1347
void getRelAlgHints(const rapidjson::Value &json_node, std::shared_ptr< RelAlgNode > node)
Definition: RelAlgDag.cpp:3174
RelAlgInputs getRelAlgInputs(const rapidjson::Value &node)
Definition: RelAlgDag.cpp:3094

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

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

Referenced by run().

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

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

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

Referenced by run().

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

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

References 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().

2829  {
2830  const auto inputs = getRelAlgInputs(proj_ra);
2831  CHECK_EQ(size_t(1), inputs.size());
2832  const auto& exprs_json = field(proj_ra, "exprs");
2833  CHECK(exprs_json.IsArray());
2834  std::vector<std::unique_ptr<const RexScalar>> exprs;
2835  for (auto exprs_json_it = exprs_json.Begin(); exprs_json_it != exprs_json.End();
2836  ++exprs_json_it) {
2837  exprs.emplace_back(parse_scalar_expr(*exprs_json_it, root_dag));
2838  }
2839  const auto& fields = field(proj_ra, "fields");
2840  if (proj_ra.HasMember("hints")) {
2841  auto project_node = std::make_shared<RelProject>(
2842  exprs, strings_from_json_array(fields), inputs.front());
2843  getRelAlgHints(proj_ra, project_node);
2844  return project_node;
2845  }
2846  return std::make_shared<RelProject>(
2847  exprs, strings_from_json_array(fields), inputs.front());
2848  }
#define CHECK_EQ(x, y)
Definition: Logger.h:301
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:1305
#define CHECK(condition)
Definition: Logger.h:291
std::unique_ptr< const RexScalar > parse_scalar_expr(const rapidjson::Value &expr, RelAlgDag &root_dag)
Definition: RelAlgDag.cpp:1347
void getRelAlgHints(const rapidjson::Value &json_node, std::shared_ptr< RelAlgNode > node)
Definition: RelAlgDag.cpp:3174
RelAlgInputs getRelAlgInputs(const rapidjson::Value &node)
Definition: RelAlgDag.cpp:3094

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

2903  {
2904  const auto inputs = getRelAlgInputs(sort_ra);
2905  CHECK_EQ(size_t(1), inputs.size());
2906  std::vector<SortField> collation;
2907  const auto& collation_arr = field(sort_ra, "collation");
2908  CHECK(collation_arr.IsArray());
2909  for (auto collation_arr_it = collation_arr.Begin();
2910  collation_arr_it != collation_arr.End();
2911  ++collation_arr_it) {
2912  const size_t field_idx = json_i64(field(*collation_arr_it, "field"));
2913  const auto sort_dir = parse_sort_direction(*collation_arr_it);
2914  const auto null_pos = parse_nulls_position(*collation_arr_it);
2915  collation.emplace_back(field_idx, sort_dir, null_pos);
2916  }
2917  auto limit = get_int_literal_field(sort_ra, "fetch", -1);
2918  const auto offset = get_int_literal_field(sort_ra, "offset", 0);
2919  auto ret = std::make_shared<RelSort>(
2920  collation, limit > 0 ? limit : 0, offset, inputs.front(), limit > 0);
2921  ret->setEmptyResult(limit == 0);
2922  return ret;
2923  }
NullSortedPosition parse_nulls_position(const rapidjson::Value &collation)
Definition: RelAlgDag.cpp:1179
#define CHECK_EQ(x, y)
Definition: Logger.h:301
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:2722
#define CHECK(condition)
Definition: Logger.h:291
SortDirection parse_sort_direction(const rapidjson::Value &collation)
Definition: RelAlgDag.cpp:1173
RelAlgInputs getRelAlgInputs(const rapidjson::Value &node)
Definition: RelAlgDag.cpp:3094

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

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

Referenced by run().

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

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

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

Referenced by run().

2815  {
2816  check_empty_inputs_field(scan_ra);
2817  CHECK(scan_ra.IsObject());
2818  const auto [cat, td] = getCatalogAndTableFromScanNode(scan_ra);
2819  const auto field_names = getFieldNamesFromScanNode(scan_ra);
2820  if (scan_ra.HasMember("hints")) {
2821  auto scan_node = std::make_shared<RelScan>(td, field_names, *cat);
2822  getRelAlgHints(scan_ra, scan_node);
2823  return scan_node;
2824  }
2825  return std::make_shared<RelScan>(td, field_names, *cat);
2826  }
std::string cat(Ts &&...args)
const std::pair< const Catalog_Namespace::Catalog *, const TableDescriptor * > getCatalogAndTableFromScanNode(const rapidjson::Value &scan_ra)
Definition: RelAlgDag.cpp:2742
#define CHECK(condition)
Definition: Logger.h:291
void getRelAlgHints(const rapidjson::Value &json_node, std::shared_ptr< RelAlgNode > node)
Definition: RelAlgDag.cpp:3174
void check_empty_inputs_field(const rapidjson::Value &node) noexcept
Definition: RelAlgDag.cpp:2736
std::vector< std::string > getFieldNamesFromScanNode(const rapidjson::Value &scan_ra)
Definition: RelAlgDag.cpp:2754

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

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

Referenced by run().

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

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

Referenced by parseHintString().

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

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

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

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

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

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

3094  {
3095  if (node.HasMember("inputs")) {
3096  const auto str_input_ids = strings_from_json_array(field(node, "inputs"));
3097  RelAlgInputs ra_inputs;
3098  for (const auto& str_id : str_input_ids) {
3099  ra_inputs.push_back(nodes_[std::stoi(str_id)]);
3100  }
3101  return ra_inputs;
3102  }
3103  return {prev(node)};
3104  }
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:3232
std::vector< std::string > strings_from_json_array(const rapidjson::Value &json_str_arr) noexcept
Definition: RelAlgDag.cpp:1305
std::shared_ptr< const RelAlgNode > prev(const rapidjson::Value &crt_node)
Definition: RelAlgDag.cpp:3225

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

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

Referenced by getRelAlgHints().

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

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

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

Referenced by getRelAlgInputs().

3225  {
3226  const auto id = node_id(crt_node);
3227  CHECK(id);
3228  CHECK_EQ(static_cast<size_t>(id), nodes_.size());
3229  return nodes_.back();
3230  }
#define CHECK_EQ(x, y)
Definition: Logger.h:301
std::vector< std::shared_ptr< RelAlgNode > > nodes_
Definition: RelAlgDag.cpp:3232
#define CHECK(condition)
Definition: Logger.h:291
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 2775 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().

2776  {
2777  for (auto rels_it = rels.Begin(); rels_it != rels.End(); ++rels_it) {
2778  const auto& crt_node = *rels_it;
2779  const auto id = node_id(crt_node);
2780  CHECK_EQ(static_cast<size_t>(id), nodes_.size());
2781  CHECK(crt_node.IsObject());
2782  std::shared_ptr<RelAlgNode> ra_node = nullptr;
2783  const auto rel_op = json_str(field(crt_node, "relOp"));
2784  if (rel_op == std::string("EnumerableTableScan") ||
2785  rel_op == std::string("LogicalTableScan")) {
2786  ra_node = dispatchTableScan(crt_node);
2787  } else if (rel_op == std::string("LogicalProject")) {
2788  ra_node = dispatchProject(crt_node, root_dag);
2789  } else if (rel_op == std::string("LogicalFilter")) {
2790  ra_node = dispatchFilter(crt_node, root_dag);
2791  } else if (rel_op == std::string("LogicalAggregate")) {
2792  ra_node = dispatchAggregate(crt_node);
2793  } else if (rel_op == std::string("LogicalJoin")) {
2794  ra_node = dispatchJoin(crt_node, root_dag);
2795  } else if (rel_op == std::string("LogicalSort")) {
2796  ra_node = dispatchSort(crt_node);
2797  } else if (rel_op == std::string("LogicalValues")) {
2798  ra_node = dispatchLogicalValues(crt_node);
2799  } else if (rel_op == std::string("LogicalTableModify")) {
2800  ra_node = dispatchModify(crt_node);
2801  } else if (rel_op == std::string("LogicalTableFunctionScan")) {
2802  ra_node = dispatchTableFunction(crt_node, root_dag);
2803  } else if (rel_op == std::string("LogicalUnion")) {
2804  ra_node = dispatchUnion(crt_node);
2805  } else {
2806  throw QueryNotSupported(std::string("Node ") + rel_op + " not supported yet");
2807  }
2808  nodes_.push_back(ra_node);
2809  }
2810 
2811  return std::move(nodes_);
2812  }
std::shared_ptr< RelAggregate > dispatchAggregate(const rapidjson::Value &agg_ra)
Definition: RelAlgDag.cpp:2860
#define CHECK_EQ(x, y)
Definition: Logger.h:301
std::shared_ptr< RelFilter > dispatchFilter(const rapidjson::Value &filter_ra, RelAlgDag &root_dag)
Definition: RelAlgDag.cpp:2850
std::shared_ptr< RelScan > dispatchTableScan(const rapidjson::Value &scan_ra)
Definition: RelAlgDag.cpp:2815
std::shared_ptr< RelLogicalUnion > dispatchUnion(const rapidjson::Value &logical_union_ra)
Definition: RelAlgDag.cpp:3086
std::shared_ptr< RelProject > dispatchProject(const rapidjson::Value &proj_ra, RelAlgDag &root_dag)
Definition: RelAlgDag.cpp:2828
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:2888
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:2969
std::vector< std::shared_ptr< RelAlgNode > > nodes_
Definition: RelAlgDag.cpp:3232
std::shared_ptr< RelModify > dispatchModify(const rapidjson::Value &logical_modify_ra)
Definition: RelAlgDag.cpp:2925
std::shared_ptr< RelSort > dispatchSort(const rapidjson::Value &sort_ra)
Definition: RelAlgDag.cpp:2903
#define CHECK(condition)
Definition: Logger.h:291
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:3039

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

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


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