OmniSciDB  72c90bc290
 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 2867 of file RelAlgDag.cpp.

Constructor & Destructor Documentation

details::RelAlgDispatcher::RelAlgDispatcher ( )
inline

Definition at line 2869 of file RelAlgDag.cpp.

2869 {}

Member Function Documentation

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

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

2956  {
2957  const auto inputs = getRelAlgInputs(agg_ra);
2958  CHECK_EQ(size_t(1), inputs.size());
2959  const auto fields = strings_from_json_array(field(agg_ra, "fields"));
2960  const auto group = indices_from_json_array(field(agg_ra, "group"));
2961  for (size_t i = 0; i < group.size(); ++i) {
2962  CHECK_EQ(i, group[i]);
2963  }
2964  if (agg_ra.HasMember("groups") || agg_ra.HasMember("indicator")) {
2965  throw QueryNotSupported("GROUP BY extensions not supported");
2966  }
2967  const auto& aggs_json_arr = field(agg_ra, "aggs");
2968  CHECK(aggs_json_arr.IsArray());
2969  std::vector<std::unique_ptr<const RexAgg>> aggs;
2970  for (auto aggs_json_arr_it = aggs_json_arr.Begin();
2971  aggs_json_arr_it != aggs_json_arr.End();
2972  ++aggs_json_arr_it) {
2973  aggs.emplace_back(parse_aggregate_expr(*aggs_json_arr_it));
2974  }
2975  if (agg_ra.HasMember("hints")) {
2976  auto agg_node =
2977  std::make_shared<RelAggregate>(group.size(), aggs, fields, inputs.front());
2978  getRelAlgHints(agg_ra, agg_node);
2979  return agg_node;
2980  }
2981  return std::make_shared<RelAggregate>(group.size(), aggs, fields, inputs.front());
2982  }
#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:1348
std::unique_ptr< const RexAgg > parse_aggregate_expr(const rapidjson::Value &expr)
Definition: RelAlgDag.cpp:1361
const rapidjson::Value & field(const rapidjson::Value &obj, const char field[]) noexcept
Definition: JsonAccessors.h:33
std::vector< std::string > strings_from_json_array(const rapidjson::Value &json_str_arr) noexcept
Definition: RelAlgDag.cpp:1336
#define CHECK(condition)
Definition: Logger.h:291
void getRelAlgHints(const rapidjson::Value &json_node, std::shared_ptr< RelAlgNode > node)
Definition: RelAlgDag.cpp:3272
RelAlgInputs getRelAlgInputs(const rapidjson::Value &node)
Definition: RelAlgDag.cpp:3192

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

2947  {
2948  const auto inputs = getRelAlgInputs(filter_ra);
2949  CHECK_EQ(size_t(1), inputs.size());
2950  const auto id = node_id(filter_ra);
2951  CHECK(id);
2952  auto condition = parse_scalar_expr(field(filter_ra, "condition"), root_dag);
2953  return std::make_shared<RelFilter>(condition, inputs.front());
2954  }
#define CHECK_EQ(x, y)
Definition: Logger.h:301
const rapidjson::Value & field(const rapidjson::Value &obj, const char field[]) noexcept
Definition: JsonAccessors.h:33
#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:1378
unsigned node_id(const rapidjson::Value &ra_node) noexcept
Definition: RelAlgDag.cpp:973
RelAlgInputs getRelAlgInputs(const rapidjson::Value &node)
Definition: RelAlgDag.cpp:3192

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

2985  {
2986  const auto inputs = getRelAlgInputs(join_ra);
2987  CHECK_EQ(size_t(2), inputs.size());
2988  const auto join_type = to_join_type(json_str(field(join_ra, "joinType")));
2989  auto filter_rex = parse_scalar_expr(field(join_ra, "condition"), root_dag);
2990  if (join_ra.HasMember("hints")) {
2991  auto join_node =
2992  std::make_shared<RelJoin>(inputs[0], inputs[1], filter_rex, join_type);
2993  getRelAlgHints(join_ra, join_node);
2994  return join_node;
2995  }
2996  return std::make_shared<RelJoin>(inputs[0], inputs[1], filter_rex, join_type);
2997  }
#define CHECK_EQ(x, y)
Definition: Logger.h:301
JoinType to_join_type(const std::string &join_type_name)
Definition: RelAlgDag.cpp:1401
const std::string json_str(const rapidjson::Value &obj) noexcept
Definition: JsonAccessors.h:46
const rapidjson::Value & field(const rapidjson::Value &obj, const char field[]) noexcept
Definition: JsonAccessors.h:33
std::unique_ptr< const RexScalar > parse_scalar_expr(const rapidjson::Value &expr, RelAlgDag &root_dag)
Definition: RelAlgDag.cpp:1378
void getRelAlgHints(const rapidjson::Value &json_node, std::shared_ptr< RelAlgNode > node)
Definition: RelAlgDag.cpp:3272
RelAlgInputs getRelAlgInputs(const rapidjson::Value &node)
Definition: RelAlgDag.cpp:3192

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

3138  {
3139  const auto& tuple_type_arr = field(logical_values_ra, "type");
3140  CHECK(tuple_type_arr.IsArray());
3141  std::vector<TargetMetaInfo> tuple_type;
3142  for (auto tuple_type_arr_it = tuple_type_arr.Begin();
3143  tuple_type_arr_it != tuple_type_arr.End();
3144  ++tuple_type_arr_it) {
3145  auto component_type = parse_type(*tuple_type_arr_it);
3146  const auto component_name = json_str(field(*tuple_type_arr_it, "name"));
3147  if (component_type.is_none_encoded_string()) {
3148  component_type.set_compression(kENCODING_DICT);
3149  component_type.set_comp_param(TRANSIENT_DICT_ID);
3150  component_type.setStringDictKey({TRANSIENT_DICT_DB_ID, TRANSIENT_DICT_ID});
3151  component_type.set_size(4);
3152  }
3153  tuple_type.emplace_back(component_name, component_type);
3154  }
3155  const auto& inputs_arr = field(logical_values_ra, "inputs");
3156  CHECK(inputs_arr.IsArray());
3157  const auto& tuples_arr = field(logical_values_ra, "tuples");
3158  CHECK(tuples_arr.IsArray());
3159 
3160  if (inputs_arr.Size()) {
3161  throw QueryNotSupported("Inputs not supported in logical values yet.");
3162  }
3163 
3164  std::vector<RelLogicalValues::RowValues> values;
3165  if (tuples_arr.Size()) {
3166  for (const auto& row : tuples_arr.GetArray()) {
3167  CHECK(row.IsArray());
3168  const auto values_json = row.GetArray();
3169  if (!values.empty()) {
3170  CHECK_EQ(values[0].size(), values_json.Size());
3171  }
3172  values.emplace_back(RelLogicalValues::RowValues{});
3173  for (const auto& value : values_json) {
3174  CHECK(value.IsObject());
3175  CHECK(value.HasMember("literal"));
3176  values.back().emplace_back(parse_literal(value));
3177  }
3178  }
3179  }
3180 
3181  return std::make_shared<RelLogicalValues>(tuple_type, values);
3182  }
#define CHECK_EQ(x, y)
Definition: Logger.h:301
const std::string json_str(const rapidjson::Value &obj) noexcept
Definition: JsonAccessors.h:46
#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:33
SQLTypeInfo parse_type(const rapidjson::Value &type_obj)
Definition: RelAlgDag.cpp:1080
std::unique_ptr< RexLiteral > parse_literal(const rapidjson::Value &expr)
Definition: RelAlgDag.cpp:995
#define CHECK(condition)
Definition: Logger.h:291
std::vector< std::unique_ptr< const RexScalar >> RowValues
Definition: RelAlgDag.h:2656

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

3023  {
3024  const auto inputs = getRelAlgInputs(logical_modify_ra);
3025  CHECK_EQ(size_t(1), inputs.size());
3026 
3027  const auto [cat, table_descriptor] =
3028  getCatalogAndTableFromScanNode(logical_modify_ra);
3029  if (table_descriptor->isView) {
3030  throw std::runtime_error("UPDATE of a view is unsupported.");
3031  }
3032 
3033  bool flattened = json_bool(field(logical_modify_ra, "flattened"));
3034  std::string op = json_str(field(logical_modify_ra, "operation"));
3035  RelModify::TargetColumnList target_column_list;
3036 
3037  if (op == "UPDATE") {
3038  const auto& update_columns = field(logical_modify_ra, "updateColumnList");
3039  CHECK(update_columns.IsArray());
3040 
3041  for (auto column_arr_it = update_columns.Begin();
3042  column_arr_it != update_columns.End();
3043  ++column_arr_it) {
3044  target_column_list.push_back(column_arr_it->GetString());
3045  }
3046  }
3047 
3048  auto modify_node = std::make_shared<RelModify>(
3049  *cat, table_descriptor, flattened, op, target_column_list, inputs[0]);
3050  switch (modify_node->getOperation()) {
3052  modify_node->applyDeleteModificationsToInputNode();
3053  break;
3054  }
3056  modify_node->applyUpdateModificationsToInputNode();
3057  break;
3058  }
3059  default:
3060  throw std::runtime_error("Unsupported RelModify operation: " +
3061  json_node_to_string(logical_modify_ra));
3062  }
3063 
3064  return modify_node;
3065  }
#define CHECK_EQ(x, y)
Definition: Logger.h:301
std::string cat(Ts &&...args)
std::vector< std::string > TargetColumnList
Definition: RelAlgDag.h:2291
const bool json_bool(const rapidjson::Value &obj) noexcept
Definition: JsonAccessors.h:51
std::string json_node_to_string(const rapidjson::Value &node) noexcept
Definition: RelAlgDag.cpp:978
const std::string json_str(const rapidjson::Value &obj) noexcept
Definition: JsonAccessors.h:46
const std::pair< const Catalog_Namespace::Catalog *, const TableDescriptor * > getCatalogAndTableFromScanNode(const rapidjson::Value &scan_ra)
Definition: RelAlgDag.cpp:2838
const rapidjson::Value & field(const rapidjson::Value &obj, const char field[]) noexcept
Definition: JsonAccessors.h:33
#define CHECK(condition)
Definition: Logger.h:291
RelAlgInputs getRelAlgInputs(const rapidjson::Value &node)
Definition: RelAlgDag.cpp:3192

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

2925  {
2926  const auto inputs = getRelAlgInputs(proj_ra);
2927  CHECK_EQ(size_t(1), inputs.size());
2928  const auto& exprs_json = field(proj_ra, "exprs");
2929  CHECK(exprs_json.IsArray());
2930  std::vector<std::unique_ptr<const RexScalar>> exprs;
2931  for (auto exprs_json_it = exprs_json.Begin(); exprs_json_it != exprs_json.End();
2932  ++exprs_json_it) {
2933  exprs.emplace_back(parse_scalar_expr(*exprs_json_it, root_dag));
2934  }
2935  const auto& fields = field(proj_ra, "fields");
2936  if (proj_ra.HasMember("hints")) {
2937  auto project_node = std::make_shared<RelProject>(
2938  exprs, strings_from_json_array(fields), inputs.front());
2939  getRelAlgHints(proj_ra, project_node);
2940  return project_node;
2941  }
2942  return std::make_shared<RelProject>(
2943  exprs, strings_from_json_array(fields), inputs.front());
2944  }
#define CHECK_EQ(x, y)
Definition: Logger.h:301
const rapidjson::Value & field(const rapidjson::Value &obj, const char field[]) noexcept
Definition: JsonAccessors.h:33
std::vector< std::string > strings_from_json_array(const rapidjson::Value &json_str_arr) noexcept
Definition: RelAlgDag.cpp:1336
#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:1378
void getRelAlgHints(const rapidjson::Value &json_node, std::shared_ptr< RelAlgNode > node)
Definition: RelAlgDag.cpp:3272
RelAlgInputs getRelAlgInputs(const rapidjson::Value &node)
Definition: RelAlgDag.cpp:3192

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

2999  {
3000  const auto inputs = getRelAlgInputs(sort_ra);
3001  CHECK_EQ(size_t(1), inputs.size());
3002  std::vector<SortField> collation;
3003  const auto& collation_arr = field(sort_ra, "collation");
3004  CHECK(collation_arr.IsArray());
3005  for (auto collation_arr_it = collation_arr.Begin();
3006  collation_arr_it != collation_arr.End();
3007  ++collation_arr_it) {
3008  const size_t field_idx = json_i64(field(*collation_arr_it, "field"));
3009  const auto sort_dir = parse_sort_direction(*collation_arr_it);
3010  const auto null_pos = parse_nulls_position(*collation_arr_it);
3011  collation.emplace_back(field_idx, sort_dir, null_pos);
3012  }
3013  auto limit = get_int_literal_field(sort_ra, "fetch", -1);
3014  const auto offset = get_int_literal_field(sort_ra, "offset", 0);
3015  auto ret = std::make_shared<RelSort>(
3016  collation,
3017  limit >= 0 ? std::make_optional<size_t>(limit) : std::nullopt,
3018  offset,
3019  inputs.front());
3020  return ret;
3021  }
NullSortedPosition parse_nulls_position(const rapidjson::Value &collation)
Definition: RelAlgDag.cpp:1210
#define CHECK_EQ(x, y)
Definition: Logger.h:301
const rapidjson::Value & field(const rapidjson::Value &obj, const char field[]) noexcept
Definition: JsonAccessors.h:33
const int64_t json_i64(const rapidjson::Value &obj) noexcept
Definition: JsonAccessors.h:41
int64_t get_int_literal_field(const rapidjson::Value &obj, const char field[], const int64_t default_val) noexcept
Definition: RelAlgDag.cpp:2818
#define CHECK(condition)
Definition: Logger.h:291
SortDirection parse_sort_direction(const rapidjson::Value &collation)
Definition: RelAlgDag.cpp:1204
RelAlgInputs getRelAlgInputs(const rapidjson::Value &node)
Definition: RelAlgDag.cpp:3192

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

3069  {
3070  const auto inputs = getRelAlgInputs(table_func_ra);
3071  const auto& invocation = field(table_func_ra, "invocation");
3072  CHECK(invocation.IsObject());
3073 
3074  const auto& operands = field(invocation, "operands");
3075  CHECK(operands.IsArray());
3076  CHECK_GE(operands.Size(), unsigned(0));
3077 
3078  std::vector<const Rex*> col_inputs;
3079  std::vector<std::unique_ptr<const RexScalar>> table_func_inputs;
3080  std::vector<std::string> fields;
3081 
3082  for (auto exprs_json_it = operands.Begin(); exprs_json_it != operands.End();
3083  ++exprs_json_it) {
3084  const auto& expr_json = *exprs_json_it;
3085  CHECK(expr_json.IsObject());
3086  if (expr_json.HasMember("op")) {
3087  const auto op_str = json_str(field(expr_json, "op"));
3088  if (op_str == "CAST" && expr_json.HasMember("type")) {
3089  const auto& expr_type = field(expr_json, "type");
3090  CHECK(expr_type.IsObject());
3091  CHECK(expr_type.HasMember("type"));
3092  const auto& expr_type_name = json_str(field(expr_type, "type"));
3093  if (expr_type_name == "CURSOR") {
3094  CHECK(expr_json.HasMember("operands"));
3095  const auto& expr_operands = field(expr_json, "operands");
3096  CHECK(expr_operands.IsArray());
3097  if (expr_operands.Size() != 1) {
3098  throw std::runtime_error(
3099  "Table functions currently only support one ResultSet input");
3100  }
3101  auto pos = field(expr_operands[0], "input").GetInt();
3102  CHECK_LT(pos, inputs.size());
3103  for (size_t i = inputs[pos]->size(); i > 0; i--) {
3104  table_func_inputs.emplace_back(
3105  std::make_unique<RexAbstractInput>(col_inputs.size()));
3106  col_inputs.emplace_back(table_func_inputs.back().get());
3107  }
3108  continue;
3109  }
3110  }
3111  }
3112  table_func_inputs.emplace_back(parse_scalar_expr(*exprs_json_it, root_dag));
3113  }
3114 
3115  const auto& op_name = field(invocation, "op");
3116  CHECK(op_name.IsString());
3117 
3118  std::vector<std::unique_ptr<const RexScalar>> table_function_projected_outputs;
3119  const auto& row_types = field(table_func_ra, "rowType");
3120  CHECK(row_types.IsArray());
3121  CHECK_GE(row_types.Size(), unsigned(0));
3122  const auto& row_types_array = row_types.GetArray();
3123  for (size_t i = 0; i < row_types_array.Size(); i++) {
3124  // We don't care about the type information in rowType -- replace each output with
3125  // a reference to be resolved later in the translator
3126  table_function_projected_outputs.emplace_back(std::make_unique<RexRef>(i));
3127  fields.emplace_back("");
3128  }
3129  return std::make_shared<RelTableFunction>(op_name.GetString(),
3130  inputs,
3131  fields,
3132  col_inputs,
3133  table_func_inputs,
3134  table_function_projected_outputs);
3135  }
const std::string json_str(const rapidjson::Value &obj) noexcept
Definition: JsonAccessors.h:46
#define CHECK_GE(x, y)
Definition: Logger.h:306
const rapidjson::Value & field(const rapidjson::Value &obj, const char field[]) noexcept
Definition: JsonAccessors.h:33
#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:1378
RelAlgInputs getRelAlgInputs(const rapidjson::Value &node)
Definition: RelAlgDag.cpp:3192

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

2911  {
2912  check_empty_inputs_field(scan_ra);
2913  CHECK(scan_ra.IsObject());
2914  const auto [cat, td] = getCatalogAndTableFromScanNode(scan_ra);
2915  const auto field_names = getFieldNamesFromScanNode(scan_ra);
2916  if (scan_ra.HasMember("hints")) {
2917  auto scan_node = std::make_shared<RelScan>(td, field_names, *cat);
2918  getRelAlgHints(scan_ra, scan_node);
2919  return scan_node;
2920  }
2921  return std::make_shared<RelScan>(td, field_names, *cat);
2922  }
std::string cat(Ts &&...args)
const std::pair< const Catalog_Namespace::Catalog *, const TableDescriptor * > getCatalogAndTableFromScanNode(const rapidjson::Value &scan_ra)
Definition: RelAlgDag.cpp:2838
#define CHECK(condition)
Definition: Logger.h:291
void getRelAlgHints(const rapidjson::Value &json_node, std::shared_ptr< RelAlgNode > node)
Definition: RelAlgDag.cpp:3272
void check_empty_inputs_field(const rapidjson::Value &node) noexcept
Definition: RelAlgDag.cpp:2832
std::vector< std::string > getFieldNamesFromScanNode(const rapidjson::Value &scan_ra)
Definition: RelAlgDag.cpp:2850

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

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

Referenced by run().

3185  {
3186  auto inputs = getRelAlgInputs(logical_union_ra);
3187  auto const& all_type_bool = field(logical_union_ra, "all");
3188  CHECK(all_type_bool.IsBool());
3189  return std::make_shared<RelLogicalUnion>(std::move(inputs), all_type_bool.GetBool());
3190  }
const rapidjson::Value & field(const rapidjson::Value &obj, const char field[]) noexcept
Definition: JsonAccessors.h:33
#define CHECK(condition)
Definition: Logger.h:291
RelAlgInputs getRelAlgInputs(const rapidjson::Value &node)
Definition: RelAlgDag.cpp:3192

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

Referenced by parseHintString().

3204  {
3205  auto option = str.substr(0, pos);
3206  std::string delim = "=";
3207  size_t delim_pos = option.find(delim);
3208  auto key = option.substr(0, delim_pos);
3209  auto val = option.substr(delim_pos + 1, option.length());
3210  str.erase(0, pos + delim.length() + 1);
3211  return {key, val};
3212  }

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

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

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

3273  {
3274  std::string hint_explained = json_str(field(json_node, "hints"));
3275  size_t pos = 0;
3276  std::string delim = "|";
3277  std::vector<std::string> hint_list;
3278  while ((pos = hint_explained.find(delim)) != std::string::npos) {
3279  hint_list.emplace_back(hint_explained.substr(0, pos));
3280  hint_explained.erase(0, pos + delim.length());
3281  }
3282  // handling the last one
3283  hint_list.emplace_back(hint_explained.substr(0, pos));
3284 
3285  const auto agg_node = std::dynamic_pointer_cast<RelAggregate>(node);
3286  if (agg_node) {
3287  for (std::string& hint : hint_list) {
3288  auto parsed_hint = parseHintString(hint);
3289  agg_node->addHint(parsed_hint);
3290  }
3291  }
3292  const auto project_node = std::dynamic_pointer_cast<RelProject>(node);
3293  if (project_node) {
3294  for (std::string& hint : hint_list) {
3295  auto parsed_hint = parseHintString(hint);
3296  project_node->addHint(parsed_hint);
3297  }
3298  }
3299  const auto scan_node = std::dynamic_pointer_cast<RelScan>(node);
3300  if (scan_node) {
3301  for (std::string& hint : hint_list) {
3302  auto parsed_hint = parseHintString(hint);
3303  scan_node->addHint(parsed_hint);
3304  }
3305  }
3306  const auto join_node = std::dynamic_pointer_cast<RelJoin>(node);
3307  if (join_node) {
3308  for (std::string& hint : hint_list) {
3309  auto parsed_hint = parseHintString(hint);
3310  join_node->addHint(parsed_hint);
3311  }
3312  }
3313 
3314  const auto compound_node = std::dynamic_pointer_cast<RelCompound>(node);
3315  if (compound_node) {
3316  for (std::string& hint : hint_list) {
3317  auto parsed_hint = parseHintString(hint);
3318  compound_node->addHint(parsed_hint);
3319  }
3320  }
3321  }
const std::string json_str(const rapidjson::Value &obj) noexcept
Definition: JsonAccessors.h:46
const rapidjson::Value & field(const rapidjson::Value &obj, const char field[]) noexcept
Definition: JsonAccessors.h:33
ExplainedQueryHint parseHintString(std::string &hint_string)
Definition: RelAlgDag.cpp:3214

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

3192  {
3193  if (node.HasMember("inputs")) {
3194  const auto str_input_ids = strings_from_json_array(field(node, "inputs"));
3195  RelAlgInputs ra_inputs;
3196  for (const auto& str_id : str_input_ids) {
3197  ra_inputs.push_back(nodes_[std::stoi(str_id)]);
3198  }
3199  return ra_inputs;
3200  }
3201  return {prev(node)};
3202  }
const rapidjson::Value & field(const rapidjson::Value &obj, const char field[]) noexcept
Definition: JsonAccessors.h:33
std::vector< std::shared_ptr< const RelAlgNode >> RelAlgInputs
Definition: RelAlgDag.h:71
std::vector< std::shared_ptr< RelAlgNode > > nodes_
Definition: RelAlgDag.cpp:3330
std::vector< std::string > strings_from_json_array(const rapidjson::Value &json_str_arr) noexcept
Definition: RelAlgDag.cpp:1336
std::shared_ptr< const RelAlgNode > prev(const rapidjson::Value &crt_node)
Definition: RelAlgDag.cpp:3323

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

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

Referenced by getRelAlgHints().

3214  {
3215  std::string white_space_delim = " ";
3216  int l = hint_string.length();
3217  hint_string = hint_string.erase(0, 1).substr(0, l - 2);
3218  size_t pos = 0;
3219  auto global_hint_checker = [&](const std::string& input_hint_name) -> HintIdentifier {
3220  bool global_hint = false;
3221  std::string hint_name = input_hint_name;
3222  auto global_hint_identifier = hint_name.substr(0, 2);
3223  if (global_hint_identifier.compare("g_") == 0) {
3224  global_hint = true;
3225  hint_name = hint_name.substr(2, hint_string.length());
3226  }
3227  return {global_hint, hint_name};
3228  };
3229  auto parsed_hint =
3230  global_hint_checker(hint_string.substr(0, hint_string.find(white_space_delim)));
3231  auto hint_type = RegisteredQueryHint::translateQueryHint(parsed_hint.hint_name);
3232  if ((pos = hint_string.find("options:")) != std::string::npos) {
3233  // need to parse hint options
3234  std::vector<std::string> tokens;
3235  bool kv_list_op = false;
3236  std::string raw_options = hint_string.substr(pos + 8, hint_string.length() - 2);
3237  if (raw_options.find('{') != std::string::npos) {
3238  kv_list_op = true;
3239  } else {
3240  CHECK(raw_options.find('[') != std::string::npos);
3241  }
3242  auto t1 = raw_options.erase(0, 1);
3243  raw_options = t1.substr(0, t1.length() - 1);
3244  std::string op_delim = ", ";
3245  if (kv_list_op) {
3246  // kv options
3247  std::unordered_map<std::string, std::string> kv_options;
3248  while ((pos = raw_options.find(op_delim)) != std::string::npos) {
3249  auto kv_pair = getKVOptionPair(raw_options, pos);
3250  kv_options.emplace(kv_pair.first, kv_pair.second);
3251  }
3252  // handle the last kv pair
3253  auto kv_pair = getKVOptionPair(raw_options, pos);
3254  kv_options.emplace(kv_pair.first, kv_pair.second);
3255  return {hint_type, parsed_hint.global_hint, false, true, kv_options};
3256  } else {
3257  std::vector<std::string> list_options;
3258  while ((pos = raw_options.find(op_delim)) != std::string::npos) {
3259  list_options.emplace_back(raw_options.substr(0, pos));
3260  raw_options.erase(0, pos + white_space_delim.length() + 1);
3261  }
3262  // handle the last option
3263  list_options.emplace_back(raw_options.substr(0, pos));
3264  return {hint_type, parsed_hint.global_hint, false, false, list_options};
3265  }
3266  } else {
3267  // marker hint: no extra option for this hint
3268  return {hint_type, parsed_hint.global_hint, true, false};
3269  }
3270  }
static QueryHint translateQueryHint(const std::string &hint_name)
Definition: QueryHint.h:367
#define CHECK(condition)
Definition: Logger.h:291
std::pair< std::string, std::string > getKVOptionPair(std::string &str, size_t &pos)
Definition: RelAlgDag.cpp:3204

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

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

Referenced by getRelAlgInputs().

3323  {
3324  const auto id = node_id(crt_node);
3325  CHECK(id);
3326  CHECK_EQ(static_cast<size_t>(id), nodes_.size());
3327  return nodes_.back();
3328  }
#define CHECK_EQ(x, y)
Definition: Logger.h:301
std::vector< std::shared_ptr< RelAlgNode > > nodes_
Definition: RelAlgDag.cpp:3330
#define CHECK(condition)
Definition: Logger.h:291
unsigned node_id(const rapidjson::Value &ra_node) noexcept
Definition: RelAlgDag.cpp:973

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

2872  {
2873  for (auto rels_it = rels.Begin(); rels_it != rels.End(); ++rels_it) {
2874  const auto& crt_node = *rels_it;
2875  const auto id = node_id(crt_node);
2876  CHECK_EQ(static_cast<size_t>(id), nodes_.size());
2877  CHECK(crt_node.IsObject());
2878  std::shared_ptr<RelAlgNode> ra_node = nullptr;
2879  const auto rel_op = json_str(field(crt_node, "relOp"));
2880  if (rel_op == std::string("EnumerableTableScan") ||
2881  rel_op == std::string("LogicalTableScan")) {
2882  ra_node = dispatchTableScan(crt_node);
2883  } else if (rel_op == std::string("LogicalProject")) {
2884  ra_node = dispatchProject(crt_node, root_dag);
2885  } else if (rel_op == std::string("LogicalFilter")) {
2886  ra_node = dispatchFilter(crt_node, root_dag);
2887  } else if (rel_op == std::string("LogicalAggregate")) {
2888  ra_node = dispatchAggregate(crt_node);
2889  } else if (rel_op == std::string("LogicalJoin")) {
2890  ra_node = dispatchJoin(crt_node, root_dag);
2891  } else if (rel_op == std::string("LogicalSort")) {
2892  ra_node = dispatchSort(crt_node);
2893  } else if (rel_op == std::string("LogicalValues")) {
2894  ra_node = dispatchLogicalValues(crt_node);
2895  } else if (rel_op == std::string("LogicalTableModify")) {
2896  ra_node = dispatchModify(crt_node);
2897  } else if (rel_op == std::string("LogicalTableFunctionScan")) {
2898  ra_node = dispatchTableFunction(crt_node, root_dag);
2899  } else if (rel_op == std::string("LogicalUnion")) {
2900  ra_node = dispatchUnion(crt_node);
2901  } else {
2902  throw QueryNotSupported(std::string("Node ") + rel_op + " not supported yet");
2903  }
2904  nodes_.push_back(ra_node);
2905  }
2906 
2907  return std::move(nodes_);
2908  }
std::shared_ptr< RelAggregate > dispatchAggregate(const rapidjson::Value &agg_ra)
Definition: RelAlgDag.cpp:2956
#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:2946
std::shared_ptr< RelScan > dispatchTableScan(const rapidjson::Value &scan_ra)
Definition: RelAlgDag.cpp:2911
std::shared_ptr< RelLogicalUnion > dispatchUnion(const rapidjson::Value &logical_union_ra)
Definition: RelAlgDag.cpp:3184
std::shared_ptr< RelProject > dispatchProject(const rapidjson::Value &proj_ra, RelAlgDag &root_dag)
Definition: RelAlgDag.cpp:2924
const std::string json_str(const rapidjson::Value &obj) noexcept
Definition: JsonAccessors.h:46
std::shared_ptr< RelJoin > dispatchJoin(const rapidjson::Value &join_ra, RelAlgDag &root_dag)
Definition: RelAlgDag.cpp:2984
const rapidjson::Value & field(const rapidjson::Value &obj, const char field[]) noexcept
Definition: JsonAccessors.h:33
std::shared_ptr< RelTableFunction > dispatchTableFunction(const rapidjson::Value &table_func_ra, RelAlgDag &root_dag)
Definition: RelAlgDag.cpp:3067
std::vector< std::shared_ptr< RelAlgNode > > nodes_
Definition: RelAlgDag.cpp:3330
std::shared_ptr< RelModify > dispatchModify(const rapidjson::Value &logical_modify_ra)
Definition: RelAlgDag.cpp:3023
std::shared_ptr< RelSort > dispatchSort(const rapidjson::Value &sort_ra)
Definition: RelAlgDag.cpp:2999
#define CHECK(condition)
Definition: Logger.h:291
unsigned node_id(const rapidjson::Value &ra_node) noexcept
Definition: RelAlgDag.cpp:973
std::shared_ptr< RelLogicalValues > dispatchLogicalValues(const rapidjson::Value &logical_values_ra)
Definition: RelAlgDag.cpp:3137

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

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


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