OmniSciDB  a5dc49c757
 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 2890 of file RelAlgDag.cpp.

Constructor & Destructor Documentation

details::RelAlgDispatcher::RelAlgDispatcher ( )
inline

Definition at line 2892 of file RelAlgDag.cpp.

2892 {}

Member Function Documentation

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

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

2979  {
2980  const auto inputs = getRelAlgInputs(agg_ra);
2981  CHECK_EQ(size_t(1), inputs.size());
2982  const auto fields = strings_from_json_array(field(agg_ra, "fields"));
2983  const auto group = indices_from_json_array(field(agg_ra, "group"));
2984  for (size_t i = 0; i < group.size(); ++i) {
2985  CHECK_EQ(i, group[i]);
2986  }
2987  if (agg_ra.HasMember("groups") || agg_ra.HasMember("indicator")) {
2988  throw QueryNotSupported("GROUP BY extensions not supported");
2989  }
2990  const auto& aggs_json_arr = field(agg_ra, "aggs");
2991  CHECK(aggs_json_arr.IsArray());
2992  std::vector<std::unique_ptr<const RexAgg>> aggs;
2993  for (auto aggs_json_arr_it = aggs_json_arr.Begin();
2994  aggs_json_arr_it != aggs_json_arr.End();
2995  ++aggs_json_arr_it) {
2996  aggs.emplace_back(parse_aggregate_expr(*aggs_json_arr_it));
2997  }
2998  if (agg_ra.HasMember("hints")) {
2999  auto agg_node =
3000  std::make_shared<RelAggregate>(group.size(), aggs, fields, inputs.front());
3001  getRelAlgHints(agg_ra, agg_node);
3002  return agg_node;
3003  }
3004  return std::make_shared<RelAggregate>(group.size(), aggs, fields, inputs.front());
3005  }
#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:3295
RelAlgInputs getRelAlgInputs(const rapidjson::Value &node)
Definition: RelAlgDag.cpp:3215

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

2970  {
2971  const auto inputs = getRelAlgInputs(filter_ra);
2972  CHECK_EQ(size_t(1), inputs.size());
2973  const auto id = node_id(filter_ra);
2974  CHECK(id);
2975  auto condition = parse_scalar_expr(field(filter_ra, "condition"), root_dag);
2976  return std::make_shared<RelFilter>(condition, inputs.front());
2977  }
#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:3215

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

3008  {
3009  const auto inputs = getRelAlgInputs(join_ra);
3010  CHECK_EQ(size_t(2), inputs.size());
3011  const auto join_type = to_join_type(json_str(field(join_ra, "joinType")));
3012  auto filter_rex = parse_scalar_expr(field(join_ra, "condition"), root_dag);
3013  if (join_ra.HasMember("hints")) {
3014  auto join_node =
3015  std::make_shared<RelJoin>(inputs[0], inputs[1], filter_rex, join_type);
3016  getRelAlgHints(join_ra, join_node);
3017  return join_node;
3018  }
3019  return std::make_shared<RelJoin>(inputs[0], inputs[1], filter_rex, join_type);
3020  }
#define CHECK_EQ(x, y)
Definition: Logger.h:301
JoinType to_join_type(const std::string &join_type_name)
Definition: RelAlgDag.cpp:1404
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:3295
RelAlgInputs getRelAlgInputs(const rapidjson::Value &node)
Definition: RelAlgDag.cpp:3215

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

3161  {
3162  const auto& tuple_type_arr = field(logical_values_ra, "type");
3163  CHECK(tuple_type_arr.IsArray());
3164  std::vector<TargetMetaInfo> tuple_type;
3165  for (auto tuple_type_arr_it = tuple_type_arr.Begin();
3166  tuple_type_arr_it != tuple_type_arr.End();
3167  ++tuple_type_arr_it) {
3168  auto component_type = parse_type(*tuple_type_arr_it);
3169  const auto component_name = json_str(field(*tuple_type_arr_it, "name"));
3170  if (component_type.is_none_encoded_string()) {
3171  component_type.set_compression(kENCODING_DICT);
3172  component_type.set_comp_param(TRANSIENT_DICT_ID);
3173  component_type.setStringDictKey({TRANSIENT_DICT_DB_ID, TRANSIENT_DICT_ID});
3174  component_type.set_size(4);
3175  }
3176  tuple_type.emplace_back(component_name, component_type);
3177  }
3178  const auto& inputs_arr = field(logical_values_ra, "inputs");
3179  CHECK(inputs_arr.IsArray());
3180  const auto& tuples_arr = field(logical_values_ra, "tuples");
3181  CHECK(tuples_arr.IsArray());
3182 
3183  if (inputs_arr.Size()) {
3184  throw QueryNotSupported("Inputs not supported in logical values yet.");
3185  }
3186 
3187  std::vector<RelLogicalValues::RowValues> values;
3188  if (tuples_arr.Size()) {
3189  for (const auto& row : tuples_arr.GetArray()) {
3190  CHECK(row.IsArray());
3191  const auto values_json = row.GetArray();
3192  if (!values.empty()) {
3193  CHECK_EQ(values[0].size(), values_json.Size());
3194  }
3195  values.emplace_back(RelLogicalValues::RowValues{});
3196  for (const auto& value : values_json) {
3197  CHECK(value.IsObject());
3198  CHECK(value.HasMember("literal"));
3199  values.back().emplace_back(parse_literal(value));
3200  }
3201  }
3202  }
3203 
3204  return std::make_shared<RelLogicalValues>(tuple_type, values);
3205  }
#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 3046 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().

3046  {
3047  const auto inputs = getRelAlgInputs(logical_modify_ra);
3048  CHECK_EQ(size_t(1), inputs.size());
3049 
3050  const auto [cat, table_descriptor] =
3051  getCatalogAndTableFromScanNode(logical_modify_ra);
3052  if (table_descriptor->isView) {
3053  throw std::runtime_error("UPDATE of a view is unsupported.");
3054  }
3055 
3056  bool flattened = json_bool(field(logical_modify_ra, "flattened"));
3057  std::string op = json_str(field(logical_modify_ra, "operation"));
3058  RelModify::TargetColumnList target_column_list;
3059 
3060  if (op == "UPDATE") {
3061  const auto& update_columns = field(logical_modify_ra, "updateColumnList");
3062  CHECK(update_columns.IsArray());
3063 
3064  for (auto column_arr_it = update_columns.Begin();
3065  column_arr_it != update_columns.End();
3066  ++column_arr_it) {
3067  target_column_list.push_back(column_arr_it->GetString());
3068  }
3069  }
3070 
3071  auto modify_node = std::make_shared<RelModify>(
3072  *cat, table_descriptor, flattened, op, target_column_list, inputs[0]);
3073  switch (modify_node->getOperation()) {
3075  modify_node->applyDeleteModificationsToInputNode();
3076  break;
3077  }
3079  modify_node->applyUpdateModificationsToInputNode();
3080  break;
3081  }
3082  default:
3083  throw std::runtime_error("Unsupported RelModify operation: " +
3084  json_node_to_string(logical_modify_ra));
3085  }
3086 
3087  return modify_node;
3088  }
#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:2861
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:3215

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

2948  {
2949  const auto inputs = getRelAlgInputs(proj_ra);
2950  CHECK_EQ(size_t(1), inputs.size());
2951  const auto& exprs_json = field(proj_ra, "exprs");
2952  CHECK(exprs_json.IsArray());
2953  std::vector<std::unique_ptr<const RexScalar>> exprs;
2954  for (auto exprs_json_it = exprs_json.Begin(); exprs_json_it != exprs_json.End();
2955  ++exprs_json_it) {
2956  exprs.emplace_back(parse_scalar_expr(*exprs_json_it, root_dag));
2957  }
2958  const auto& fields = field(proj_ra, "fields");
2959  if (proj_ra.HasMember("hints")) {
2960  auto project_node = std::make_shared<RelProject>(
2961  exprs, strings_from_json_array(fields), inputs.front());
2962  getRelAlgHints(proj_ra, project_node);
2963  return project_node;
2964  }
2965  return std::make_shared<RelProject>(
2966  exprs, strings_from_json_array(fields), inputs.front());
2967  }
#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:3295
RelAlgInputs getRelAlgInputs(const rapidjson::Value &node)
Definition: RelAlgDag.cpp:3215

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

3022  {
3023  const auto inputs = getRelAlgInputs(sort_ra);
3024  CHECK_EQ(size_t(1), inputs.size());
3025  std::vector<SortField> collation;
3026  const auto& collation_arr = field(sort_ra, "collation");
3027  CHECK(collation_arr.IsArray());
3028  for (auto collation_arr_it = collation_arr.Begin();
3029  collation_arr_it != collation_arr.End();
3030  ++collation_arr_it) {
3031  const size_t field_idx = json_i64(field(*collation_arr_it, "field"));
3032  const auto sort_dir = parse_sort_direction(*collation_arr_it);
3033  const auto null_pos = parse_nulls_position(*collation_arr_it);
3034  collation.emplace_back(field_idx, sort_dir, null_pos);
3035  }
3036  auto limit = get_int_literal_field(sort_ra, "fetch", -1);
3037  const auto offset = get_int_literal_field(sort_ra, "offset", 0);
3038  auto ret = std::make_shared<RelSort>(
3039  collation,
3040  limit >= 0 ? std::make_optional<size_t>(limit) : std::nullopt,
3041  offset,
3042  inputs.front());
3043  return ret;
3044  }
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:2841
#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:3215

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

3092  {
3093  const auto inputs = getRelAlgInputs(table_func_ra);
3094  const auto& invocation = field(table_func_ra, "invocation");
3095  CHECK(invocation.IsObject());
3096 
3097  const auto& operands = field(invocation, "operands");
3098  CHECK(operands.IsArray());
3099  CHECK_GE(operands.Size(), unsigned(0));
3100 
3101  std::vector<const Rex*> col_inputs;
3102  std::vector<std::unique_ptr<const RexScalar>> table_func_inputs;
3103  std::vector<std::string> fields;
3104 
3105  for (auto exprs_json_it = operands.Begin(); exprs_json_it != operands.End();
3106  ++exprs_json_it) {
3107  const auto& expr_json = *exprs_json_it;
3108  CHECK(expr_json.IsObject());
3109  if (expr_json.HasMember("op")) {
3110  const auto op_str = json_str(field(expr_json, "op"));
3111  if (op_str == "CAST" && expr_json.HasMember("type")) {
3112  const auto& expr_type = field(expr_json, "type");
3113  CHECK(expr_type.IsObject());
3114  CHECK(expr_type.HasMember("type"));
3115  const auto& expr_type_name = json_str(field(expr_type, "type"));
3116  if (expr_type_name == "CURSOR") {
3117  CHECK(expr_json.HasMember("operands"));
3118  const auto& expr_operands = field(expr_json, "operands");
3119  CHECK(expr_operands.IsArray());
3120  if (expr_operands.Size() != 1) {
3121  throw std::runtime_error(
3122  "Table functions currently only support one ResultSet input");
3123  }
3124  auto pos = field(expr_operands[0], "input").GetInt();
3125  CHECK_LT(pos, inputs.size());
3126  for (size_t i = inputs[pos]->size(); i > 0; i--) {
3127  table_func_inputs.emplace_back(
3128  std::make_unique<RexAbstractInput>(col_inputs.size()));
3129  col_inputs.emplace_back(table_func_inputs.back().get());
3130  }
3131  continue;
3132  }
3133  }
3134  }
3135  table_func_inputs.emplace_back(parse_scalar_expr(*exprs_json_it, root_dag));
3136  }
3137 
3138  const auto& op_name = field(invocation, "op");
3139  CHECK(op_name.IsString());
3140 
3141  std::vector<std::unique_ptr<const RexScalar>> table_function_projected_outputs;
3142  const auto& row_types = field(table_func_ra, "rowType");
3143  CHECK(row_types.IsArray());
3144  CHECK_GE(row_types.Size(), unsigned(0));
3145  const auto& row_types_array = row_types.GetArray();
3146  for (size_t i = 0; i < row_types_array.Size(); i++) {
3147  // We don't care about the type information in rowType -- replace each output with
3148  // a reference to be resolved later in the translator
3149  table_function_projected_outputs.emplace_back(std::make_unique<RexRef>(i));
3150  fields.emplace_back("");
3151  }
3152  return std::make_shared<RelTableFunction>(op_name.GetString(),
3153  inputs,
3154  fields,
3155  col_inputs,
3156  table_func_inputs,
3157  table_function_projected_outputs);
3158  }
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:3215

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

2934  {
2935  check_empty_inputs_field(scan_ra);
2936  CHECK(scan_ra.IsObject());
2937  const auto [cat, td] = getCatalogAndTableFromScanNode(scan_ra);
2938  const auto field_names = getFieldNamesFromScanNode(scan_ra);
2939  if (scan_ra.HasMember("hints")) {
2940  auto scan_node = std::make_shared<RelScan>(td, field_names, *cat);
2941  getRelAlgHints(scan_ra, scan_node);
2942  return scan_node;
2943  }
2944  return std::make_shared<RelScan>(td, field_names, *cat);
2945  }
std::string cat(Ts &&...args)
const std::pair< const Catalog_Namespace::Catalog *, const TableDescriptor * > getCatalogAndTableFromScanNode(const rapidjson::Value &scan_ra)
Definition: RelAlgDag.cpp:2861
#define CHECK(condition)
Definition: Logger.h:291
void getRelAlgHints(const rapidjson::Value &json_node, std::shared_ptr< RelAlgNode > node)
Definition: RelAlgDag.cpp:3295
void check_empty_inputs_field(const rapidjson::Value &node) noexcept
Definition: RelAlgDag.cpp:2855
std::vector< std::string > getFieldNamesFromScanNode(const rapidjson::Value &scan_ra)
Definition: RelAlgDag.cpp:2873

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

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

Referenced by run().

3208  {
3209  auto inputs = getRelAlgInputs(logical_union_ra);
3210  auto const& all_type_bool = field(logical_union_ra, "all");
3211  CHECK(all_type_bool.IsBool());
3212  return std::make_shared<RelLogicalUnion>(std::move(inputs), all_type_bool.GetBool());
3213  }
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:3215

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

Referenced by parseHintString().

3227  {
3228  auto option = str.substr(0, pos);
3229  std::string delim = "=";
3230  size_t delim_pos = option.find(delim);
3231  auto key = option.substr(0, delim_pos);
3232  auto val = option.substr(delim_pos + 1, option.length());
3233  str.erase(0, pos + delim.length() + 1);
3234  return {key, val};
3235  }

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

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

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

3296  {
3297  std::string hint_explained = json_str(field(json_node, "hints"));
3298  size_t pos = 0;
3299  std::string delim = "|";
3300  std::vector<std::string> hint_list;
3301  while ((pos = hint_explained.find(delim)) != std::string::npos) {
3302  hint_list.emplace_back(hint_explained.substr(0, pos));
3303  hint_explained.erase(0, pos + delim.length());
3304  }
3305  // handling the last one
3306  hint_list.emplace_back(hint_explained.substr(0, pos));
3307 
3308  const auto agg_node = std::dynamic_pointer_cast<RelAggregate>(node);
3309  if (agg_node) {
3310  for (std::string& hint : hint_list) {
3311  auto parsed_hint = parseHintString(hint);
3312  agg_node->addHint(parsed_hint);
3313  }
3314  }
3315  const auto project_node = std::dynamic_pointer_cast<RelProject>(node);
3316  if (project_node) {
3317  for (std::string& hint : hint_list) {
3318  auto parsed_hint = parseHintString(hint);
3319  project_node->addHint(parsed_hint);
3320  }
3321  }
3322  const auto scan_node = std::dynamic_pointer_cast<RelScan>(node);
3323  if (scan_node) {
3324  for (std::string& hint : hint_list) {
3325  auto parsed_hint = parseHintString(hint);
3326  scan_node->addHint(parsed_hint);
3327  }
3328  }
3329  const auto join_node = std::dynamic_pointer_cast<RelJoin>(node);
3330  if (join_node) {
3331  for (std::string& hint : hint_list) {
3332  auto parsed_hint = parseHintString(hint);
3333  join_node->addHint(parsed_hint);
3334  }
3335  }
3336 
3337  const auto compound_node = std::dynamic_pointer_cast<RelCompound>(node);
3338  if (compound_node) {
3339  for (std::string& hint : hint_list) {
3340  auto parsed_hint = parseHintString(hint);
3341  compound_node->addHint(parsed_hint);
3342  }
3343  }
3344  }
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:3237

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

3215  {
3216  if (node.HasMember("inputs")) {
3217  const auto str_input_ids = strings_from_json_array(field(node, "inputs"));
3218  RelAlgInputs ra_inputs;
3219  for (const auto& str_id : str_input_ids) {
3220  ra_inputs.push_back(nodes_[std::stoi(str_id)]);
3221  }
3222  return ra_inputs;
3223  }
3224  return {prev(node)};
3225  }
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:3353
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:3346

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

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

Referenced by getRelAlgHints().

3237  {
3238  std::string white_space_delim = " ";
3239  int l = hint_string.length();
3240  hint_string = hint_string.erase(0, 1).substr(0, l - 2);
3241  size_t pos = 0;
3242  auto global_hint_checker = [&](const std::string& input_hint_name) -> HintIdentifier {
3243  bool global_hint = false;
3244  std::string hint_name = input_hint_name;
3245  auto global_hint_identifier = hint_name.substr(0, 2);
3246  if (global_hint_identifier.compare("g_") == 0) {
3247  global_hint = true;
3248  hint_name = hint_name.substr(2, hint_string.length());
3249  }
3250  return {global_hint, hint_name};
3251  };
3252  auto parsed_hint =
3253  global_hint_checker(hint_string.substr(0, hint_string.find(white_space_delim)));
3254  auto hint_type = RegisteredQueryHint::translateQueryHint(parsed_hint.hint_name);
3255  if ((pos = hint_string.find("options:")) != std::string::npos) {
3256  // need to parse hint options
3257  std::vector<std::string> tokens;
3258  bool kv_list_op = false;
3259  std::string raw_options = hint_string.substr(pos + 8, hint_string.length() - 2);
3260  if (raw_options.find('{') != std::string::npos) {
3261  kv_list_op = true;
3262  } else {
3263  CHECK(raw_options.find('[') != std::string::npos);
3264  }
3265  auto t1 = raw_options.erase(0, 1);
3266  raw_options = t1.substr(0, t1.length() - 1);
3267  std::string op_delim = ", ";
3268  if (kv_list_op) {
3269  // kv options
3270  std::unordered_map<std::string, std::string> kv_options;
3271  while ((pos = raw_options.find(op_delim)) != std::string::npos) {
3272  auto kv_pair = getKVOptionPair(raw_options, pos);
3273  kv_options.emplace(kv_pair.first, kv_pair.second);
3274  }
3275  // handle the last kv pair
3276  auto kv_pair = getKVOptionPair(raw_options, pos);
3277  kv_options.emplace(kv_pair.first, kv_pair.second);
3278  return {hint_type, parsed_hint.global_hint, false, true, kv_options};
3279  } else {
3280  std::vector<std::string> list_options;
3281  while ((pos = raw_options.find(op_delim)) != std::string::npos) {
3282  list_options.emplace_back(raw_options.substr(0, pos));
3283  raw_options.erase(0, pos + white_space_delim.length() + 1);
3284  }
3285  // handle the last option
3286  list_options.emplace_back(raw_options.substr(0, pos));
3287  return {hint_type, parsed_hint.global_hint, false, false, list_options};
3288  }
3289  } else {
3290  // marker hint: no extra option for this hint
3291  return {hint_type, parsed_hint.global_hint, true, false};
3292  }
3293  }
static QueryHint translateQueryHint(const std::string &hint_name)
Definition: QueryHint.h:382
#define CHECK(condition)
Definition: Logger.h:291
std::pair< std::string, std::string > getKVOptionPair(std::string &str, size_t &pos)
Definition: RelAlgDag.cpp:3227

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

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

Referenced by getRelAlgInputs().

3346  {
3347  const auto id = node_id(crt_node);
3348  CHECK(id);
3349  CHECK_EQ(static_cast<size_t>(id), nodes_.size());
3350  return nodes_.back();
3351  }
#define CHECK_EQ(x, y)
Definition: Logger.h:301
std::vector< std::shared_ptr< RelAlgNode > > nodes_
Definition: RelAlgDag.cpp:3353
#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 2894 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().

2895  {
2896  for (auto rels_it = rels.Begin(); rels_it != rels.End(); ++rels_it) {
2897  const auto& crt_node = *rels_it;
2898  const auto id = node_id(crt_node);
2899  CHECK_EQ(static_cast<size_t>(id), nodes_.size());
2900  CHECK(crt_node.IsObject());
2901  std::shared_ptr<RelAlgNode> ra_node = nullptr;
2902  const auto rel_op = json_str(field(crt_node, "relOp"));
2903  if (rel_op == std::string("EnumerableTableScan") ||
2904  rel_op == std::string("LogicalTableScan")) {
2905  ra_node = dispatchTableScan(crt_node);
2906  } else if (rel_op == std::string("LogicalProject")) {
2907  ra_node = dispatchProject(crt_node, root_dag);
2908  } else if (rel_op == std::string("LogicalFilter")) {
2909  ra_node = dispatchFilter(crt_node, root_dag);
2910  } else if (rel_op == std::string("LogicalAggregate")) {
2911  ra_node = dispatchAggregate(crt_node);
2912  } else if (rel_op == std::string("LogicalJoin")) {
2913  ra_node = dispatchJoin(crt_node, root_dag);
2914  } else if (rel_op == std::string("LogicalSort")) {
2915  ra_node = dispatchSort(crt_node);
2916  } else if (rel_op == std::string("LogicalValues")) {
2917  ra_node = dispatchLogicalValues(crt_node);
2918  } else if (rel_op == std::string("LogicalTableModify")) {
2919  ra_node = dispatchModify(crt_node);
2920  } else if (rel_op == std::string("LogicalTableFunctionScan")) {
2921  ra_node = dispatchTableFunction(crt_node, root_dag);
2922  } else if (rel_op == std::string("LogicalUnion")) {
2923  ra_node = dispatchUnion(crt_node);
2924  } else {
2925  throw QueryNotSupported(std::string("Node ") + rel_op + " not supported yet");
2926  }
2927  nodes_.push_back(ra_node);
2928  }
2929 
2930  return std::move(nodes_);
2931  }
std::shared_ptr< RelAggregate > dispatchAggregate(const rapidjson::Value &agg_ra)
Definition: RelAlgDag.cpp:2979
#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:2969
std::shared_ptr< RelScan > dispatchTableScan(const rapidjson::Value &scan_ra)
Definition: RelAlgDag.cpp:2934
std::shared_ptr< RelLogicalUnion > dispatchUnion(const rapidjson::Value &logical_union_ra)
Definition: RelAlgDag.cpp:3207
std::shared_ptr< RelProject > dispatchProject(const rapidjson::Value &proj_ra, RelAlgDag &root_dag)
Definition: RelAlgDag.cpp:2947
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:3007
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:3090
std::vector< std::shared_ptr< RelAlgNode > > nodes_
Definition: RelAlgDag.cpp:3353
std::shared_ptr< RelModify > dispatchModify(const rapidjson::Value &logical_modify_ra)
Definition: RelAlgDag.cpp:3046
std::shared_ptr< RelSort > dispatchSort(const rapidjson::Value &sort_ra)
Definition: RelAlgDag.cpp:3022
#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:3160

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

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


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