OmniSciDB  5ade3759e0
anonymous_namespace{CalciteAdapter.cpp} Namespace Reference

Classes

class  CalciteAdapter
 
struct  LogicalSortInfo
 

Functions

ssize_t get_agg_operand_idx (const rapidjson::Value &expr)
 
std::tuple< const rapidjson::Value *, SQLTypeInfo, SQLTypeInfoparse_literal (const rapidjson::Value &expr)
 
std::shared_ptr< Analyzer::Exprset_transient_dict (const std::shared_ptr< Analyzer::Expr > expr)
 
void reproject_target_entries (std::vector< std::shared_ptr< Analyzer::TargetEntry >> &agg_targets, const std::vector< size_t > &result_proj_indices, const rapidjson::Value &fields)
 
LogicalSortInfo get_logical_sort_info (const rapidjson::Value &rels)
 
Planner::Scanget_scan_plan (const TableDescriptor *td, const std::vector< std::shared_ptr< Analyzer::TargetEntry >> &scan_targets, std::list< std::shared_ptr< Analyzer::Expr >> &q, std::list< std::shared_ptr< Analyzer::Expr >> &sq, CalciteAdapter &calcite_adapter)
 
Planner::Planget_agg_plan (const TableDescriptor *td, const std::vector< std::shared_ptr< Analyzer::TargetEntry >> &scan_targets, const std::vector< std::shared_ptr< Analyzer::TargetEntry >> &agg_targets, const std::list< std::shared_ptr< Analyzer::Expr >> &groupby_exprs, std::list< std::shared_ptr< Analyzer::Expr >> &q, std::list< std::shared_ptr< Analyzer::Expr >> &sq, CalciteAdapter &calcite_adapter)
 
Planner::Planget_sort_plan (Planner::Plan *plan, const rapidjson::Value &rels, const std::vector< std::shared_ptr< Analyzer::TargetEntry >> &scan_targets, const std::vector< std::shared_ptr< Analyzer::TargetEntry >> &agg_targets)
 
std::vector< size_t > collect_reproject_indices (const rapidjson::Value &exprs)
 
std::vector< std::shared_ptr< Analyzer::TargetEntry > > get_input_targets (const std::vector< std::shared_ptr< Analyzer::TargetEntry >> &in_targets, const rapidjson::Value &exprs, const rapidjson::Value &fields, CalciteAdapter &calcite_adapter)
 
bool needs_result_plan (const rapidjson::Value &exprs)
 
std::vector< std::shared_ptr< Analyzer::TargetEntry > > build_var_refs (const std::vector< std::shared_ptr< Analyzer::TargetEntry >> &in_targets)
 
std::vector< std::shared_ptr< Analyzer::TargetEntry > > build_result_plan_targets (const std::vector< std::shared_ptr< Analyzer::TargetEntry >> &in_targets, const rapidjson::Value &exprs, const rapidjson::Value &fields, CalciteAdapter &calcite_adapter)
 
bool targets_are_refs (const std::vector< std::shared_ptr< Analyzer::TargetEntry >> &in_targets)
 
std::vector< std::shared_ptr< Analyzer::TargetEntry > > handle_logical_project (std::vector< std::shared_ptr< Analyzer::TargetEntry >> &child_plan_targets, const std::vector< std::shared_ptr< Analyzer::TargetEntry >> &in_targets, const rapidjson::Value &logical_project, CalciteAdapter &calcite_adapter)
 
std::vector< std::shared_ptr< Analyzer::TargetEntry > > handle_logical_aggregate (const std::vector< std::shared_ptr< Analyzer::TargetEntry >> &in_targets, std::list< std::shared_ptr< Analyzer::Expr >> &groupby_exprs, const rapidjson::Value &logical_aggregate, CalciteAdapter &calcite_adapter)
 
void add_quals (const std::shared_ptr< Analyzer::Expr > qual_expr, std::list< std::shared_ptr< Analyzer::Expr >> &simple_quals, std::list< std::shared_ptr< Analyzer::Expr >> &quals)
 
void collect_used_columns (std::vector< std::shared_ptr< Analyzer::ColumnVar >> &used_cols, const std::shared_ptr< Analyzer::Expr > expr)
 
std::unordered_set< int > get_used_table_ids (const std::vector< std::shared_ptr< Analyzer::ColumnVar >> &used_cols)
 
void separate_join_quals (std::unordered_map< int, std::list< std::shared_ptr< Analyzer::Expr >>> &quals, std::list< std::shared_ptr< Analyzer::Expr >> &join_quals, const std::list< std::shared_ptr< Analyzer::Expr >> &all_quals)
 
const std::string get_op_name (const rapidjson::Value &obj)
 
bool match_compound_seq (rapidjson::Value::ConstValueIterator &rels_it, const rapidjson::Value::ConstValueIterator rels_end)
 
bool match_filter_project_seq (rapidjson::Value::ConstValueIterator &rels_it, const rapidjson::Value::ConstValueIterator rels_end)
 
bool match_sort_seq (rapidjson::Value::ConstValueIterator &rels_it, const rapidjson::Value::ConstValueIterator rels_end)
 
bool query_is_supported (const rapidjson::Value &rels)
 
std::string pg_shim_impl (const std::string &query)
 

Function Documentation

◆ add_quals()

void anonymous_namespace{CalciteAdapter.cpp}::add_quals ( const std::shared_ptr< Analyzer::Expr qual_expr,
std::list< std::shared_ptr< Analyzer::Expr >> &  simple_quals,
std::list< std::shared_ptr< Analyzer::Expr >> &  quals 
)

Definition at line 940 of file CalciteAdapter.cpp.

References CHECK, and kAND.

Referenced by translate_query().

942  {
943  CHECK(qual_expr);
944  const auto bin_oper = std::dynamic_pointer_cast<const Analyzer::BinOper>(qual_expr);
945  if (!bin_oper) {
946  quals.push_back(qual_expr);
947  return;
948  }
949  if (bin_oper->get_optype() == kAND) {
950  add_quals(bin_oper->get_own_left_operand(), simple_quals, quals);
951  add_quals(bin_oper->get_own_right_operand(), simple_quals, quals);
952  return;
953  }
954  int rte_idx{0};
955  const auto simple_qual = bin_oper->normalize_simple_predicate(rte_idx);
956  if (simple_qual) {
957  simple_quals.push_back(simple_qual);
958  } else {
959  quals.push_back(qual_expr);
960  }
961 }
void add_quals(const std::shared_ptr< Analyzer::Expr > qual_expr, std::list< std::shared_ptr< Analyzer::Expr >> &simple_quals, std::list< std::shared_ptr< Analyzer::Expr >> &quals)
Definition: sqldefs.h:37
#define CHECK(condition)
Definition: Logger.h:187
+ Here is the caller graph for this function:

◆ build_result_plan_targets()

std::vector<std::shared_ptr<Analyzer::TargetEntry> > anonymous_namespace{CalciteAdapter.cpp}::build_result_plan_targets ( const std::vector< std::shared_ptr< Analyzer::TargetEntry >> &  in_targets,
const rapidjson::Value &  exprs,
const rapidjson::Value &  fields,
CalciteAdapter calcite_adapter 
)

Definition at line 833 of file CalciteAdapter.cpp.

References build_var_refs(), CHECK, CHECK_EQ, anonymous_namespace{CalciteAdapter.cpp}::CalciteAdapter::getExprFromNode(), and run-benchmark-import::result.

Referenced by handle_logical_project().

837  {
838  const auto var_refs_to_in_targets = build_var_refs(in_targets);
839  std::vector<std::shared_ptr<Analyzer::TargetEntry>> result;
840  CHECK(fields.IsArray());
841  CHECK_EQ(exprs.Size(), fields.Size());
842  auto fields_it = fields.Begin();
843  for (auto exprs_it = exprs.Begin(); exprs_it != exprs.End(); ++exprs_it, ++fields_it) {
844  const auto analyzer_expr =
845  calcite_adapter.getExprFromNode(*exprs_it, var_refs_to_in_targets);
846  CHECK(fields_it != exprs.End());
847  CHECK(fields_it->IsString());
848  result.emplace_back(
849  new Analyzer::TargetEntry(fields_it->GetString(), analyzer_expr, false));
850  }
851  return result;
852 }
#define CHECK_EQ(x, y)
Definition: Logger.h:195
Definition: Analyzer.h:1406
std::vector< std::shared_ptr< Analyzer::TargetEntry > > build_var_refs(const std::vector< std::shared_ptr< Analyzer::TargetEntry >> &in_targets)
#define CHECK(condition)
Definition: Logger.h:187
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ build_var_refs()

std::vector<std::shared_ptr<Analyzer::TargetEntry> > anonymous_namespace{CalciteAdapter.cpp}::build_var_refs ( const std::vector< std::shared_ptr< Analyzer::TargetEntry >> &  in_targets)

Definition at line 820 of file CalciteAdapter.cpp.

References Analyzer::Var::kINPUT_OUTER, and var_ref().

Referenced by build_result_plan_targets(), and translate_query().

821  {
822  std::vector<std::shared_ptr<Analyzer::TargetEntry>> var_refs_to_in_targets;
823  for (size_t i = 1; i <= in_targets.size(); ++i) {
824  const auto target = in_targets[i - 1];
825  var_refs_to_in_targets.emplace_back(new Analyzer::TargetEntry(
826  target->get_resname(),
827  var_ref(target->get_expr(), Analyzer::Var::kINPUT_OUTER, i),
828  false));
829  }
830  return var_refs_to_in_targets;
831 }
Definition: Analyzer.h:1406
std::shared_ptr< Analyzer::Var > var_ref(const Analyzer::Expr *expr, const Analyzer::Var::WhichRow which_row, const int varno)
Definition: Analyzer.h:1508
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ collect_reproject_indices()

std::vector<size_t> anonymous_namespace{CalciteAdapter.cpp}::collect_reproject_indices ( const rapidjson::Value &  exprs)

Definition at line 774 of file CalciteAdapter.cpp.

References CHECK.

Referenced by handle_logical_project().

774  {
775  std::vector<size_t> result_proj_indices;
776  CHECK(exprs.IsArray());
777  for (auto exprs_it = exprs.Begin(); exprs_it != exprs.End(); ++exprs_it) {
778  CHECK(exprs_it->IsObject());
779  result_proj_indices.push_back((*exprs_it)["input"].GetInt());
780  }
781  return result_proj_indices;
782 }
#define CHECK(condition)
Definition: Logger.h:187
+ Here is the caller graph for this function:

◆ collect_used_columns()

void anonymous_namespace{CalciteAdapter.cpp}::collect_used_columns ( std::vector< std::shared_ptr< Analyzer::ColumnVar >> &  used_cols,
const std::shared_ptr< Analyzer::Expr expr 
)

Definition at line 963 of file CalciteAdapter.cpp.

Referenced by separate_join_quals().

964  {
965  const auto col_var = std::dynamic_pointer_cast<Analyzer::ColumnVar>(expr);
966  if (col_var && !std::dynamic_pointer_cast<Analyzer::Var>(col_var)) {
967  used_cols.push_back(col_var);
968  return;
969  }
970  const auto uoper = std::dynamic_pointer_cast<Analyzer::UOper>(expr);
971  if (uoper) {
972  collect_used_columns(used_cols, uoper->get_own_operand());
973  return;
974  }
975  const auto bin_oper = std::dynamic_pointer_cast<Analyzer::BinOper>(expr);
976  if (bin_oper) {
977  collect_used_columns(used_cols, bin_oper->get_own_left_operand());
978  collect_used_columns(used_cols, bin_oper->get_own_right_operand());
979  return;
980  }
981  const auto extract_expr = std::dynamic_pointer_cast<Analyzer::ExtractExpr>(expr);
982  if (extract_expr) {
983  collect_used_columns(used_cols, extract_expr->get_own_from_expr());
984  return;
985  }
986  const auto datetrunc_expr = std::dynamic_pointer_cast<Analyzer::DatetruncExpr>(expr);
987  if (datetrunc_expr) {
988  collect_used_columns(used_cols, datetrunc_expr->get_own_from_expr());
989  return;
990  }
991  const auto charlength_expr = std::dynamic_pointer_cast<Analyzer::CharLengthExpr>(expr);
992  if (charlength_expr) {
993  collect_used_columns(used_cols, charlength_expr->get_own_arg());
994  return;
995  }
996  const auto keyforstring_expr =
997  std::dynamic_pointer_cast<Analyzer::KeyForStringExpr>(expr);
998  if (keyforstring_expr) {
999  collect_used_columns(used_cols, keyforstring_expr->get_own_arg());
1000  return;
1001  }
1002  const auto cardinality_expr =
1003  std::dynamic_pointer_cast<Analyzer::CardinalityExpr>(expr);
1004  if (cardinality_expr) {
1005  collect_used_columns(used_cols, cardinality_expr->get_own_arg());
1006  return;
1007  }
1008  const auto like_expr = std::dynamic_pointer_cast<Analyzer::LikeExpr>(expr);
1009  if (like_expr) {
1010  collect_used_columns(used_cols, like_expr->get_own_arg());
1011  return;
1012  }
1013 }
void collect_used_columns(std::vector< std::shared_ptr< Analyzer::ColumnVar >> &used_cols, const std::shared_ptr< Analyzer::Expr > expr)
+ Here is the caller graph for this function:

◆ get_agg_operand_idx()

ssize_t anonymous_namespace{CalciteAdapter.cpp}::get_agg_operand_idx ( const rapidjson::Value &  expr)

Definition at line 35 of file CalciteAdapter.cpp.

References CHECK.

Referenced by anonymous_namespace{CalciteAdapter.cpp}::CalciteAdapter::translateAggregate().

35  {
36  CHECK(expr.IsObject());
37  CHECK(expr.HasMember("agg"));
38  const auto& agg_operands = expr["operands"];
39  CHECK(agg_operands.IsArray());
40  CHECK(agg_operands.Size() <= 2);
41  return agg_operands.Empty() ? -1 : agg_operands[0].GetInt();
42 }
#define CHECK(condition)
Definition: Logger.h:187
+ Here is the caller graph for this function:

◆ get_agg_plan()

Planner::Plan* anonymous_namespace{CalciteAdapter.cpp}::get_agg_plan ( const TableDescriptor td,
const std::vector< std::shared_ptr< Analyzer::TargetEntry >> &  scan_targets,
const std::vector< std::shared_ptr< Analyzer::TargetEntry >> &  agg_targets,
const std::list< std::shared_ptr< Analyzer::Expr >> &  groupby_exprs,
std::list< std::shared_ptr< Analyzer::Expr >> &  q,
std::list< std::shared_ptr< Analyzer::Expr >> &  sq,
CalciteAdapter calcite_adapter 
)

Definition at line 744 of file CalciteAdapter.cpp.

References get_scan_plan().

Referenced by translate_query().

751  {
752  Planner::Plan* plan = get_scan_plan(td, scan_targets, q, sq, calcite_adapter);
753  if (!agg_targets.empty()) {
754  plan = new Planner::AggPlan(agg_targets, 0., plan, groupby_exprs);
755  }
756  return plan;
757 }
Planner::Scan * get_scan_plan(const TableDescriptor *td, const std::vector< std::shared_ptr< Analyzer::TargetEntry >> &scan_targets, std::list< std::shared_ptr< Analyzer::Expr >> &q, std::list< std::shared_ptr< Analyzer::Expr >> &sq, CalciteAdapter &calcite_adapter)
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ get_input_targets()

std::vector<std::shared_ptr<Analyzer::TargetEntry> > anonymous_namespace{CalciteAdapter.cpp}::get_input_targets ( const std::vector< std::shared_ptr< Analyzer::TargetEntry >> &  in_targets,
const rapidjson::Value &  exprs,
const rapidjson::Value &  fields,
CalciteAdapter calcite_adapter 
)

Definition at line 784 of file CalciteAdapter.cpp.

References CHECK, CHECK_EQ, anonymous_namespace{CalciteAdapter.cpp}::CalciteAdapter::getExprFromNode(), and run-benchmark-import::result.

Referenced by handle_logical_project().

788  {
789  CHECK(exprs.IsArray());
790  CHECK(fields.IsArray());
791  CHECK_EQ(exprs.Size(), fields.Size());
792  std::vector<std::shared_ptr<Analyzer::TargetEntry>> result;
793  if (in_targets.empty()) {
794  auto fields_it = fields.Begin();
795  for (auto exprs_it = exprs.Begin(); exprs_it != exprs.End();
796  ++exprs_it, ++fields_it) {
797  const auto proj_expr = calcite_adapter.getExprFromNode(*exprs_it, in_targets);
798  CHECK(fields_it != exprs.End());
799  CHECK(fields_it->IsString());
800  result.emplace_back(
801  new Analyzer::TargetEntry(fields_it->GetString(), proj_expr, false));
802  }
803  } else {
804  result = in_targets;
805  }
806  return result;
807 }
#define CHECK_EQ(x, y)
Definition: Logger.h:195
Definition: Analyzer.h:1406
#define CHECK(condition)
Definition: Logger.h:187
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ get_logical_sort_info()

LogicalSortInfo anonymous_namespace{CalciteAdapter.cpp}::get_logical_sort_info ( const rapidjson::Value &  rels)

Definition at line 658 of file CalciteAdapter.cpp.

References CHECK, CHECK_EQ, anonymous_namespace{CalciteAdapter.cpp}::LogicalSortInfo::limit, anonymous_namespace{CalciteAdapter.cpp}::LogicalSortInfo::offset, anonymous_namespace{CalciteAdapter.cpp}::LogicalSortInfo::order_entries, parse_literal(), and run-benchmark-import::result.

Referenced by get_sort_plan(), and translate_query().

658  {
659  LogicalSortInfo result;
660  bool found{false};
661  for (auto rels_it = rels.Begin(); rels_it != rels.End(); ++rels_it) {
662  const auto& sort_rel = *rels_it;
663  CHECK(sort_rel.IsObject() && sort_rel.HasMember("relOp"));
664  if (std::string("LogicalSort") != sort_rel["relOp"].GetString()) {
665  continue;
666  }
667  if (!found) {
668  if (sort_rel.HasMember("fetch")) {
669  const auto& limit_lit = parse_literal(sort_rel["fetch"]);
670  CHECK(std::get<1>(limit_lit).is_decimal() &&
671  std::get<1>(limit_lit).get_scale() == 0);
672  CHECK(std::get<0>(limit_lit)->IsInt64());
673  result.limit = std::get<0>(limit_lit)->GetInt64();
674  }
675  if (sort_rel.HasMember("offset")) {
676  const auto& offset_lit = parse_literal(sort_rel["offset"]);
677  CHECK(std::get<1>(offset_lit).is_decimal() &&
678  std::get<1>(offset_lit).get_scale() == 0);
679  CHECK(std::get<0>(offset_lit)->IsInt64());
680  result.offset = std::get<0>(offset_lit)->GetInt64();
681  }
682  CHECK(sort_rel.HasMember("collation"));
683  const auto& collation = sort_rel["collation"];
684  CHECK(collation.IsArray());
685  for (auto collation_it = collation.Begin(); collation_it != collation.End();
686  ++collation_it) {
687  const auto& oe_node = *collation_it;
688  CHECK(oe_node.IsObject());
689  result.order_entries.emplace_back(
690  oe_node["field"].GetInt() + 1,
691  std::string("DESCENDING") == oe_node["direction"].GetString(),
692  std::string("FIRST") == oe_node["nulls"].GetString());
693  }
694  found = true;
695  } else {
696  // Looks like there are two structurally identical LogicalSortInfo nodes
697  // in the Calcite AST. Validation for now, but maybe they can be different?
698  if (sort_rel.HasMember("fetch")) {
699  const auto& limit_lit = parse_literal(sort_rel["fetch"]);
700  CHECK(std::get<1>(limit_lit).is_decimal() &&
701  std::get<1>(limit_lit).get_scale() == 0);
702  CHECK(std::get<0>(limit_lit)->IsInt64());
703  CHECK_EQ(result.limit, std::get<0>(limit_lit)->GetInt64());
704  }
705  if (sort_rel.HasMember("offset")) {
706  const auto& offset_lit = parse_literal(sort_rel["offset"]);
707  CHECK(std::get<1>(offset_lit).is_decimal() &&
708  std::get<1>(offset_lit).get_scale() == 0);
709  CHECK(std::get<0>(offset_lit)->IsInt64());
710  CHECK_EQ(result.offset, std::get<0>(offset_lit)->GetInt64());
711  }
712  CHECK(sort_rel.HasMember("collation"));
713  const auto& collation = sort_rel["collation"];
714  CHECK(collation.IsArray());
715  CHECK_EQ(static_cast<size_t>(collation.Size()), result.order_entries.size());
716  auto oe_it = result.order_entries.begin();
717  for (size_t i = 0; i < result.order_entries.size(); ++i, ++oe_it) {
718  const auto& oe_node = collation[i];
719  const auto& oe = *oe_it;
720  CHECK_EQ(oe.is_desc,
721  std::string("DESCENDING") == oe_node["direction"].GetString());
722  CHECK_EQ(oe.nulls_first, std::string("FIRST") == oe_node["nulls"].GetString());
723  }
724  }
725  }
726  return result;
727 }
#define CHECK_EQ(x, y)
Definition: Logger.h:195
std::tuple< const rapidjson::Value *, SQLTypeInfo, SQLTypeInfo > parse_literal(const rapidjson::Value &expr)
#define CHECK(condition)
Definition: Logger.h:187
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ get_op_name()

const std::string anonymous_namespace{CalciteAdapter.cpp}::get_op_name ( const rapidjson::Value &  obj)

Definition at line 1042 of file CalciteAdapter.cpp.

References CHECK, and field().

Referenced by match_compound_seq(), match_filter_project_seq(), match_sort_seq(), and query_is_supported().

1042  {
1043  CHECK(obj.IsObject());
1044  const auto field_it = obj.FindMember("relOp");
1045  CHECK(field_it != obj.MemberEnd());
1046  const auto& field = field_it->value;
1047  CHECK(field.IsString());
1048  return field.GetString();
1049 }
const rapidjson::Value & field(const rapidjson::Value &obj, const char field[]) noexcept
Definition: JsonAccessors.h:31
#define CHECK(condition)
Definition: Logger.h:187
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ get_scan_plan()

Planner::Scan* anonymous_namespace{CalciteAdapter.cpp}::get_scan_plan ( const TableDescriptor td,
const std::vector< std::shared_ptr< Analyzer::TargetEntry >> &  scan_targets,
std::list< std::shared_ptr< Analyzer::Expr >> &  q,
std::list< std::shared_ptr< Analyzer::Expr >> &  sq,
CalciteAdapter calcite_adapter 
)

Definition at line 729 of file CalciteAdapter.cpp.

References anonymous_namespace{CalciteAdapter.cpp}::CalciteAdapter::getUsedColumnList(), and TableDescriptor::tableId.

Referenced by get_agg_plan().

734  {
735  return new Planner::Scan(scan_targets,
736  q,
737  0.,
738  nullptr,
739  sq,
740  td->tableId,
741  calcite_adapter.getUsedColumnList(td->tableId));
742 }
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ get_sort_plan()

Planner::Plan* anonymous_namespace{CalciteAdapter.cpp}::get_sort_plan ( Planner::Plan plan,
const rapidjson::Value &  rels,
const std::vector< std::shared_ptr< Analyzer::TargetEntry >> &  scan_targets,
const std::vector< std::shared_ptr< Analyzer::TargetEntry >> &  agg_targets 
)

Definition at line 759 of file CalciteAdapter.cpp.

References get_logical_sort_info().

Referenced by translate_query().

763  {
764  const auto logical_sort_info = get_logical_sort_info(rels);
765  if (!logical_sort_info.order_entries.empty()) {
766  const auto& sort_target_entries =
767  agg_targets.empty() ? scan_targets : agg_targets; // TODO(alex)
768  plan = new Planner::Sort(
769  sort_target_entries, 0, plan, logical_sort_info.order_entries, false);
770  }
771  return plan;
772 }
LogicalSortInfo get_logical_sort_info(const rapidjson::Value &rels)
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ get_used_table_ids()

std::unordered_set<int> anonymous_namespace{CalciteAdapter.cpp}::get_used_table_ids ( const std::vector< std::shared_ptr< Analyzer::ColumnVar >> &  used_cols)

Definition at line 1015 of file CalciteAdapter.cpp.

References run-benchmark-import::result.

Referenced by separate_join_quals().

1016  {
1017  std::unordered_set<int> result;
1018  for (const auto col_var : used_cols) {
1019  result.insert(col_var->get_table_id());
1020  }
1021  return result;
1022 }
+ Here is the caller graph for this function:

◆ handle_logical_aggregate()

std::vector<std::shared_ptr<Analyzer::TargetEntry> > anonymous_namespace{CalciteAdapter.cpp}::handle_logical_aggregate ( const std::vector< std::shared_ptr< Analyzer::TargetEntry >> &  in_targets,
std::list< std::shared_ptr< Analyzer::Expr >> &  groupby_exprs,
const rapidjson::Value &  logical_aggregate,
CalciteAdapter calcite_adapter 
)

Definition at line 893 of file CalciteAdapter.cpp.

References CHECK, CHECK_EQ, anonymous_namespace{CalciteAdapter.cpp}::CalciteAdapter::getExprFromNode(), is_unnest(), Analyzer::Var::kGROUPBY, kUNNEST, run-benchmark-import::result, set_transient_dict(), and var_ref().

Referenced by translate_query().

897  {
898  std::vector<std::shared_ptr<Analyzer::TargetEntry>> result;
899  const auto& agg_nodes = logical_aggregate["aggs"];
900  const auto& group_nodes = logical_aggregate["group"];
901  CHECK(group_nodes.IsArray());
902  for (auto group_nodes_it = group_nodes.Begin(); group_nodes_it != group_nodes.End();
903  ++group_nodes_it) {
904  CHECK(group_nodes_it->IsInt());
905  const int target_idx = group_nodes_it->GetInt();
906  groupby_exprs.push_back(set_transient_dict(in_targets[target_idx]->get_own_expr()));
907  }
908  CHECK(agg_nodes.IsArray());
909  const auto& fields = logical_aggregate["fields"];
910  CHECK(fields.IsArray());
911  auto fields_it = fields.Begin();
912  for (auto group_nodes_it = group_nodes.Begin(); group_nodes_it != group_nodes.End();
913  ++group_nodes_it, ++fields_it) {
914  CHECK(group_nodes_it->IsInt());
915  const int target_idx = group_nodes_it->GetInt();
916  const auto target = in_targets[target_idx];
917  CHECK(fields_it != fields.End());
918  CHECK(fields_it->IsString());
919  CHECK_EQ(target->get_resname(), fields_it->GetString());
920  const auto target_expr = set_transient_dict(target->get_own_expr());
921  const auto uoper_expr = dynamic_cast<const Analyzer::UOper*>(target_expr.get());
922  const bool is_unnest{uoper_expr && uoper_expr->get_optype() == kUNNEST};
923  auto group_var_ref = var_ref(target_expr.get(),
925  group_nodes_it - group_nodes.Begin() + 1);
926  result.emplace_back(
927  new Analyzer::TargetEntry(target->get_resname(), group_var_ref, is_unnest));
928  }
929  for (auto agg_nodes_it = agg_nodes.Begin(); agg_nodes_it != agg_nodes.End();
930  ++agg_nodes_it, ++fields_it) {
931  auto agg_expr = calcite_adapter.getExprFromNode(*agg_nodes_it, in_targets);
932  CHECK(fields_it != fields.End());
933  CHECK(fields_it->IsString());
934  result.emplace_back(
935  new Analyzer::TargetEntry(fields_it->GetString(), agg_expr, false));
936  }
937  return result;
938 }
#define CHECK_EQ(x, y)
Definition: Logger.h:195
Definition: Analyzer.h:1406
std::shared_ptr< Analyzer::Expr > set_transient_dict(const std::shared_ptr< Analyzer::Expr > expr)
std::shared_ptr< Analyzer::Var > var_ref(const Analyzer::Expr *expr, const Analyzer::Var::WhichRow which_row, const int varno)
Definition: Analyzer.h:1508
#define CHECK(condition)
Definition: Logger.h:187
bool is_unnest(const Analyzer::Expr *expr)
Definition: Execute.h:1059
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ handle_logical_project()

std::vector<std::shared_ptr<Analyzer::TargetEntry> > anonymous_namespace{CalciteAdapter.cpp}::handle_logical_project ( std::vector< std::shared_ptr< Analyzer::TargetEntry >> &  child_plan_targets,
const std::vector< std::shared_ptr< Analyzer::TargetEntry >> &  in_targets,
const rapidjson::Value &  logical_project,
CalciteAdapter calcite_adapter 
)

Definition at line 865 of file CalciteAdapter.cpp.

References build_result_plan_targets(), CHECK, collect_reproject_indices(), get_input_targets(), needs_result_plan(), reproject_target_entries(), run-benchmark-import::result, and targets_are_refs().

Referenced by translate_query().

869  {
870  const auto exprs_mem_it = logical_project.FindMember("exprs");
871  CHECK(exprs_mem_it != logical_project.MemberEnd());
872  const auto& exprs = exprs_mem_it->value;
873  const auto fields_mem_it = logical_project.FindMember("fields");
874  CHECK(fields_mem_it != logical_project.MemberEnd());
875  const auto& fields = fields_mem_it->value;
876  auto result = get_input_targets(in_targets, exprs, fields, calcite_adapter);
877  if (in_targets.empty()) { // source scan was the table itself
878  return result;
879  }
880  // needs a re-projection or a result plan
881  if (needs_result_plan(exprs)) {
882  if (!targets_are_refs(result)) {
883  child_plan_targets = result;
884  }
885  return build_result_plan_targets(result, exprs, fields, calcite_adapter);
886  } else { // just target permutation. no need to create a result plan
887  const auto reproj_indices = collect_reproject_indices(exprs);
888  reproject_target_entries(result, reproj_indices, fields);
889  }
890  return result;
891 }
void reproject_target_entries(std::vector< std::shared_ptr< Analyzer::TargetEntry >> &agg_targets, const std::vector< size_t > &result_proj_indices, const rapidjson::Value &fields)
bool targets_are_refs(const std::vector< std::shared_ptr< Analyzer::TargetEntry >> &in_targets)
std::vector< std::shared_ptr< Analyzer::TargetEntry > > build_result_plan_targets(const std::vector< std::shared_ptr< Analyzer::TargetEntry >> &in_targets, const rapidjson::Value &exprs, const rapidjson::Value &fields, CalciteAdapter &calcite_adapter)
#define CHECK(condition)
Definition: Logger.h:187
bool needs_result_plan(const rapidjson::Value &exprs)
std::vector< size_t > collect_reproject_indices(const rapidjson::Value &exprs)
std::vector< std::shared_ptr< Analyzer::TargetEntry > > get_input_targets(const std::vector< std::shared_ptr< Analyzer::TargetEntry >> &in_targets, const rapidjson::Value &exprs, const rapidjson::Value &fields, CalciteAdapter &calcite_adapter)
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ match_compound_seq()

bool anonymous_namespace{CalciteAdapter.cpp}::match_compound_seq ( rapidjson::Value::ConstValueIterator &  rels_it,
const rapidjson::Value::ConstValueIterator  rels_end 
)

Definition at line 1051 of file CalciteAdapter.cpp.

References get_op_name().

Referenced by query_is_supported().

1052  {
1053  auto op_name = get_op_name(*rels_it);
1054  if (op_name == std::string("LogicalFilter")) {
1055  ++rels_it;
1056  }
1057  op_name = get_op_name(*rels_it++);
1058  if (op_name != std::string("LogicalProject")) {
1059  return false;
1060  }
1061  if (rels_it == rels_end) {
1062  return true;
1063  }
1064  op_name = get_op_name(*rels_it);
1065  if (op_name == std::string("LogicalAggregate")) {
1066  ++rels_it;
1067  if (rels_it == rels_end) {
1068  return true;
1069  }
1070  op_name = get_op_name(*rels_it);
1071  if (op_name == std::string("LogicalProject")) {
1072  ++rels_it;
1073  }
1074  }
1075  return true;
1076 }
const std::string get_op_name(const rapidjson::Value &obj)
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ match_filter_project_seq()

bool anonymous_namespace{CalciteAdapter.cpp}::match_filter_project_seq ( rapidjson::Value::ConstValueIterator &  rels_it,
const rapidjson::Value::ConstValueIterator  rels_end 
)

Definition at line 1078 of file CalciteAdapter.cpp.

References CHECK, and get_op_name().

Referenced by query_is_supported().

1079  {
1080  CHECK(rels_it != rels_end);
1081  auto op_name = get_op_name(*rels_it++);
1082  if (op_name != std::string("LogicalFilter")) {
1083  return false;
1084  }
1085  if (rels_it != rels_end && get_op_name(*rels_it) == std::string("LogicalProject")) {
1086  ++rels_it;
1087  }
1088  return true;
1089 }
const std::string get_op_name(const rapidjson::Value &obj)
#define CHECK(condition)
Definition: Logger.h:187
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ match_sort_seq()

bool anonymous_namespace{CalciteAdapter.cpp}::match_sort_seq ( rapidjson::Value::ConstValueIterator &  rels_it,
const rapidjson::Value::ConstValueIterator  rels_end 
)

Definition at line 1091 of file CalciteAdapter.cpp.

References get_op_name().

Referenced by query_is_supported().

1092  {
1093  auto op_name = get_op_name(*rels_it++);
1094  if (op_name != std::string("LogicalSort")) {
1095  return false;
1096  }
1097  if (rels_it == rels_end) {
1098  return true;
1099  }
1100  op_name = get_op_name(*rels_it++);
1101  if (op_name != std::string("LogicalProject")) {
1102  return false;
1103  }
1104  op_name = get_op_name(*rels_it++);
1105  if (op_name != std::string("LogicalSort")) {
1106  return false;
1107  }
1108  return rels_it == rels_end;
1109 }
const std::string get_op_name(const rapidjson::Value &obj)
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ needs_result_plan()

bool anonymous_namespace{CalciteAdapter.cpp}::needs_result_plan ( const rapidjson::Value &  exprs)

Definition at line 809 of file CalciteAdapter.cpp.

References CHECK.

Referenced by handle_logical_project().

809  {
810  for (auto exprs_it = exprs.Begin(); exprs_it != exprs.End(); ++exprs_it) {
811  const auto& expr = *exprs_it;
812  CHECK(expr.IsObject());
813  if (!expr.HasMember("input")) {
814  return true;
815  }
816  }
817  return false;
818 }
#define CHECK(condition)
Definition: Logger.h:187
+ Here is the caller graph for this function:

◆ parse_literal()

std::tuple<const rapidjson::Value*, SQLTypeInfo, SQLTypeInfo> anonymous_namespace{CalciteAdapter.cpp}::parse_literal ( const rapidjson::Value &  expr)

Definition at line 44 of file CalciteAdapter.cpp.

References CHECK, and to_sql_type().

Referenced by get_logical_sort_info(), and anonymous_namespace{CalciteAdapter.cpp}::CalciteAdapter::translateTypedLiteral().

45  {
46  CHECK(expr.IsObject());
47  auto val_it = expr.FindMember("literal");
48  CHECK(val_it != expr.MemberEnd());
49  auto type_it = expr.FindMember("type");
50  CHECK(type_it != expr.MemberEnd());
51  CHECK(type_it->value.IsString());
52  const auto type_name = std::string(type_it->value.GetString());
53  auto target_type_it = expr.FindMember("target_type");
54  CHECK(target_type_it != expr.MemberEnd());
55  CHECK(target_type_it->value.IsString());
56  const auto target_type_name = std::string(target_type_it->value.GetString());
57  auto scale_it = expr.FindMember("scale");
58  CHECK(scale_it != expr.MemberEnd());
59  CHECK(scale_it->value.IsInt());
60  const int scale = scale_it->value.GetInt();
61  auto type_scale_it = expr.FindMember("type_scale");
62  CHECK(type_scale_it != expr.MemberEnd());
63  CHECK(type_scale_it->value.IsInt());
64  const int type_scale = type_scale_it->value.GetInt();
65  auto precision_it = expr.FindMember("precision");
66  CHECK(precision_it != expr.MemberEnd());
67  CHECK(precision_it->value.IsInt());
68  const int precision = precision_it->value.GetInt();
69  auto type_precision_it = expr.FindMember("type_precision");
70  CHECK(type_precision_it != expr.MemberEnd());
71  CHECK(type_precision_it->value.IsInt());
72  const int type_precision = type_precision_it->value.GetInt();
73  SQLTypeInfo ti(to_sql_type(type_name), precision, scale, false);
74  SQLTypeInfo target_ti(to_sql_type(target_type_name), type_precision, type_scale, false);
75  return std::make_tuple(&(val_it->value), ti, target_ti);
76 }
SQLTypes to_sql_type(const std::string &type_name)
#define CHECK(condition)
Definition: Logger.h:187
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ pg_shim_impl()

std::string anonymous_namespace{CalciteAdapter.cpp}::pg_shim_impl ( const std::string &  query)

Definition at line 1320 of file CalciteAdapter.cpp.

References apply_shim(), LOG, anonymous_namespace{UpdateMetadataTest.cpp}::query, run-benchmark-import::result, and logger::WARNING.

Referenced by pg_shim().

1320  {
1321  auto result = query;
1322  {
1323  boost::regex unnest_expr{R"((\s+|,)(unnest)\s*\()",
1324  boost::regex::extended | boost::regex::icase};
1325  apply_shim(result, unnest_expr, [](std::string& result, const boost::smatch& what) {
1326  result.replace(what.position(), what.length(), what[1] + "PG_UNNEST(");
1327  });
1328  }
1329  {
1330  boost::regex cast_true_expr{R"(CAST\s*\(\s*'t'\s+AS\s+boolean\s*\))",
1331  boost::regex::extended | boost::regex::icase};
1332  apply_shim(
1333  result, cast_true_expr, [](std::string& result, const boost::smatch& what) {
1334  result.replace(what.position(), what.length(), "true");
1335  });
1336  }
1337  {
1338  boost::regex cast_false_expr{R"(CAST\s*\(\s*'f'\s+AS\s+boolean\s*\))",
1339  boost::regex::extended | boost::regex::icase};
1340  apply_shim(
1341  result, cast_false_expr, [](std::string& result, const boost::smatch& what) {
1342  result.replace(what.position(), what.length(), "false");
1343  });
1344  }
1345  {
1346  boost::regex ilike_expr{
1347  R"((\s+|\()((?!\()[^\s]+)\s+ilike\s+('(?:[^']+|'')+')(\s+escape(\s+('[^']+')))?)",
1348  boost::regex::perl | boost::regex::icase};
1349  apply_shim(result, ilike_expr, [](std::string& result, const boost::smatch& what) {
1350  std::string esc = what[6];
1351  result.replace(what.position(),
1352  what.length(),
1353  what[1] + "PG_ILIKE(" + what[2] + ", " + what[3] +
1354  (esc.empty() ? "" : ", " + esc) + ")");
1355  });
1356  }
1357  {
1358  boost::regex regexp_expr{
1359  R"((\s+)([^\s]+)\s+REGEXP\s+('(?:[^']+|'')+')(\s+escape(\s+('[^']+')))?)",
1360  boost::regex::perl | boost::regex::icase};
1361  apply_shim(result, regexp_expr, [](std::string& result, const boost::smatch& what) {
1362  std::string esc = what[6];
1363  result.replace(what.position(),
1364  what.length(),
1365  what[1] + "REGEXP_LIKE(" + what[2] + ", " + what[3] +
1366  (esc.empty() ? "" : ", " + esc) + ")");
1367  });
1368  }
1369  {
1370  boost::regex extract_expr{R"(extract\s*\(\s*(\w+)\s+from\s+(.+)\))",
1371  boost::regex::extended | boost::regex::icase};
1372  apply_shim(result, extract_expr, [](std::string& result, const boost::smatch& what) {
1373  result.replace(what.position(),
1374  what.length(),
1375  "PG_EXTRACT('" + what[1] + "', " + what[2] + ")");
1376  });
1377  }
1378  {
1379  boost::regex date_trunc_expr{R"(date_trunc\s*\(\s*(\w+)\s*,(.*)\))",
1380  boost::regex::extended | boost::regex::icase};
1381  apply_shim(
1382  result, date_trunc_expr, [](std::string& result, const boost::smatch& what) {
1383  result.replace(what.position(),
1384  what.length(),
1385  "PG_DATE_TRUNC('" + what[1] + "', " + what[2] + ")");
1386  });
1387  }
1388  {
1389  boost::regex quant_expr{R"(\s(any|all)\s+([^(\s|;)]+))",
1390  boost::regex::extended | boost::regex::icase};
1391  apply_shim(result, quant_expr, [](std::string& result, const boost::smatch& what) {
1392  std::string qual_name = what[1];
1393  std::string quant_fname{boost::iequals(qual_name, "any") ? "PG_ANY" : "PG_ALL"};
1394  result.replace(what.position(), what.length(), quant_fname + "(" + what[2] + ")");
1395  });
1396  }
1397  {
1398  boost::regex immediate_cast_expr{R"(TIMESTAMP\(([0369])\)\s+('[^']+'))",
1399  boost::regex::extended | boost::regex::icase};
1400  apply_shim(
1401  result, immediate_cast_expr, [](std::string& result, const boost::smatch& what) {
1402  result.replace(what.position(),
1403  what.length(),
1404  "CAST(" + what[2] + " AS TIMESTAMP(" + what[1] + "))");
1405  });
1406  }
1407  {
1408  boost::regex timestampadd_expr{R"(TIMESTAMPADD\s*\(\s*(\w+)\s*,)",
1409  boost::regex::extended | boost::regex::icase};
1410  apply_shim(
1411  result, timestampadd_expr, [](std::string& result, const boost::smatch& what) {
1412  result.replace(what.position(), what.length(), "DATEADD('" + what[1] + "',");
1413  });
1414  }
1415  {
1416  boost::regex us_timestamp_cast_expr{
1417  R"(CAST\s*\(\s*('[^']+')\s*AS\s*TIMESTAMP\(6\)\s*\))",
1418  boost::regex::extended | boost::regex::icase};
1419  apply_shim(result,
1420  us_timestamp_cast_expr,
1421  [](std::string& result, const boost::smatch& what) {
1422  result.replace(
1423  what.position(), what.length(), "usTIMESTAMP(" + what[1] + ")");
1424  });
1425  }
1426  {
1427  boost::regex ns_timestamp_cast_expr{
1428  R"(CAST\s*\(\s*('[^']+')\s*AS\s*TIMESTAMP\(9\)\s*\))",
1429  boost::regex::extended | boost::regex::icase};
1430  apply_shim(result,
1431  ns_timestamp_cast_expr,
1432  [](std::string& result, const boost::smatch& what) {
1433  result.replace(
1434  what.position(), what.length(), "nsTIMESTAMP(" + what[1] + ")");
1435  });
1436  }
1437  {
1438  boost::regex corr_expr{R"((\s+|,|\()(corr)\s*\()",
1439  boost::regex::extended | boost::regex::icase};
1440  apply_shim(result, corr_expr, [](std::string& result, const boost::smatch& what) {
1441  result.replace(what.position(), what.length(), what[1] + "CORRELATION(");
1442  });
1443  }
1444  {
1445  try {
1446  // the geography regex pattern is expensive and can sometimes run out of stack space
1447  // on long queries. Treat it separately from the other shims.
1448  boost::regex cast_to_geography_expr{
1449  R"(CAST\s*\(\s*(((?!geography).)+)\s+AS\s+geography\s*\))",
1450  boost::regex::perl | boost::regex::icase};
1451  apply_shim(result,
1452  cast_to_geography_expr,
1453  [](std::string& result, const boost::smatch& what) {
1454  result.replace(what.position(),
1455  what.length(),
1456  "CastToGeography(" + what[1] + ")");
1457  });
1458  } catch (const std::exception& e) {
1459  LOG(WARNING) << "Error apply geography cast shim: " << e.what()
1460  << "\nContinuing query parse...";
1461  }
1462  }
1463  return result;
1464 }
#define LOG(tag)
Definition: Logger.h:182
void apply_shim(std::string &result, const boost::regex &reg_expr, const std::function< void(std::string &, const boost::smatch &)> &shim_fn)
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ query_is_supported()

bool anonymous_namespace{CalciteAdapter.cpp}::query_is_supported ( const rapidjson::Value &  rels)

Definition at line 1113 of file CalciteAdapter.cpp.

References CHECK, get_op_name(), match_compound_seq(), match_filter_project_seq(), and match_sort_seq().

Referenced by translate_query().

1113  {
1114  rapidjson::Value::ConstValueIterator rels_it = rels.Begin();
1115  if (std::string("EnumerableTableScan") != get_op_name(*rels_it++)) {
1116  return false;
1117  }
1118  const auto op_name = get_op_name(*rels_it);
1119  if (op_name == std::string("EnumerableTableScan")) {
1120  ++rels_it;
1121  CHECK(rels_it != rels.End());
1122  if (get_op_name(*rels_it++) != std::string("LogicalJoin")) {
1123  return false;
1124  }
1125  }
1126  if (!match_compound_seq(rels_it, rels.End())) {
1127  return false;
1128  }
1129  if (rels_it == rels.End()) {
1130  return true;
1131  }
1132  if (get_op_name(*rels_it) == std::string("LogicalSort")) {
1133  return match_sort_seq(rels_it, rels.End());
1134  }
1135  // HAVING query
1136  if (!match_filter_project_seq(rels_it, rels.End())) {
1137  return false;
1138  }
1139  if (rels_it == rels.End()) {
1140  return true;
1141  }
1142  if (!match_sort_seq(rels_it, rels.End())) {
1143  return false;
1144  }
1145  return rels_it == rels.End();
1146 }
bool match_sort_seq(rapidjson::Value::ConstValueIterator &rels_it, const rapidjson::Value::ConstValueIterator rels_end)
const std::string get_op_name(const rapidjson::Value &obj)
#define CHECK(condition)
Definition: Logger.h:187
bool match_filter_project_seq(rapidjson::Value::ConstValueIterator &rels_it, const rapidjson::Value::ConstValueIterator rels_end)
bool match_compound_seq(rapidjson::Value::ConstValueIterator &rels_it, const rapidjson::Value::ConstValueIterator rels_end)
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ reproject_target_entries()

void anonymous_namespace{CalciteAdapter.cpp}::reproject_target_entries ( std::vector< std::shared_ptr< Analyzer::TargetEntry >> &  agg_targets,
const std::vector< size_t > &  result_proj_indices,
const rapidjson::Value &  fields 
)

Definition at line 628 of file CalciteAdapter.cpp.

References CHECK, CHECK_EQ, and CHECK_LT.

Referenced by handle_logical_project().

631  {
632  CHECK(fields.IsArray());
633  CHECK_EQ(static_cast<size_t>(fields.Size()), result_proj_indices.size());
634  if (result_proj_indices.empty()) {
635  return;
636  }
637  std::vector<std::shared_ptr<Analyzer::TargetEntry>> agg_targets_reproj;
638  auto fields_it = fields.Begin();
639  for (const auto proj_idx : result_proj_indices) {
640  CHECK_LT(proj_idx, agg_targets.size());
641  CHECK(fields_it != fields.End());
642  CHECK(fields_it->IsString());
643  const auto te = agg_targets[proj_idx];
644  agg_targets_reproj.emplace_back(new Analyzer::TargetEntry(
645  fields_it->GetString(), te->get_own_expr(), te->get_unnest()));
646  ++fields_it;
647  }
648  agg_targets.swap(agg_targets_reproj);
649 }
#define CHECK_EQ(x, y)
Definition: Logger.h:195
Definition: Analyzer.h:1406
#define CHECK_LT(x, y)
Definition: Logger.h:197
#define CHECK(condition)
Definition: Logger.h:187
+ Here is the caller graph for this function:

◆ separate_join_quals()

void anonymous_namespace{CalciteAdapter.cpp}::separate_join_quals ( std::unordered_map< int, std::list< std::shared_ptr< Analyzer::Expr >>> &  quals,
std::list< std::shared_ptr< Analyzer::Expr >> &  join_quals,
const std::list< std::shared_ptr< Analyzer::Expr >> &  all_quals 
)

Definition at line 1024 of file CalciteAdapter.cpp.

References CHECK, CHECK_EQ, collect_used_columns(), and get_used_table_ids().

Referenced by translate_query().

1027  {
1028  for (auto qual_candidate : all_quals) {
1029  std::vector<std::shared_ptr<Analyzer::ColumnVar>> used_columns;
1030  collect_used_columns(used_columns, qual_candidate);
1031  const auto used_table_ids = get_used_table_ids(used_columns);
1032  if (used_table_ids.size() > 1) {
1033  CHECK_EQ(size_t(2), used_table_ids.size());
1034  join_quals.push_back(qual_candidate);
1035  } else {
1036  CHECK(!used_table_ids.empty());
1037  quals[*used_table_ids.begin()].push_back(qual_candidate);
1038  }
1039  }
1040 }
#define CHECK_EQ(x, y)
Definition: Logger.h:195
std::unordered_set< int > get_used_table_ids(const std::vector< std::shared_ptr< Analyzer::ColumnVar >> &used_cols)
void collect_used_columns(std::vector< std::shared_ptr< Analyzer::ColumnVar >> &used_cols, const std::shared_ptr< Analyzer::Expr > expr)
#define CHECK(condition)
Definition: Logger.h:187
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ set_transient_dict()

std::shared_ptr<Analyzer::Expr> anonymous_namespace{CalciteAdapter.cpp}::set_transient_dict ( const std::shared_ptr< Analyzer::Expr expr)

Definition at line 78 of file CalciteAdapter.cpp.

References kENCODING_DICT, kENCODING_NONE, and TRANSIENT_DICT_ID.

Referenced by handle_logical_aggregate().

79  {
80  const auto& ti = expr->get_type_info();
81  if (!ti.is_string() || ti.get_compression() != kENCODING_NONE) {
82  return expr;
83  }
84  auto transient_dict_ti = ti;
85  transient_dict_ti.set_compression(kENCODING_DICT);
86  transient_dict_ti.set_comp_param(TRANSIENT_DICT_ID);
87  transient_dict_ti.set_fixed_size();
88  return expr->add_cast(transient_dict_ti);
89 }
#define TRANSIENT_DICT_ID
Definition: sqltypes.h:186
+ Here is the caller graph for this function:

◆ targets_are_refs()

bool anonymous_namespace{CalciteAdapter.cpp}::targets_are_refs ( const std::vector< std::shared_ptr< Analyzer::TargetEntry >> &  in_targets)

Definition at line 854 of file CalciteAdapter.cpp.

References CHECK.

Referenced by handle_logical_project().

855  {
856  CHECK(!in_targets.empty());
857  for (const auto target : in_targets) {
858  if (!dynamic_cast<const Analyzer::Var*>(target->get_expr())) {
859  return false;
860  }
861  }
862  return true;
863 }
#define CHECK(condition)
Definition: Logger.h:187
+ Here is the caller graph for this function: