21 : ra_exe_unit_(ra_exe_unit) {}
26 return visit(it->get());
43 if (constant_ti.is_string()) {
52 const auto operand_str =
visit(operand);
56 return "NOT (" + operand_str +
")";
59 return "-" + operand_str;
62 return operand_str +
" IS NULL";
65 const auto& operand_ti = operand->get_type_info();
68 throw std::runtime_error(
"Type not supported yet for extern execution: " +
69 target_ti.get_type_name());
71 if ((operand_ti.get_type() == target_ti.get_type()) ||
72 ((operand_ti.is_string() && target_ti.is_string()))) {
75 return "CAST(" + operand_str +
" AS " + target_ti.
get_type_name() +
")";
78 throw std::runtime_error(
"Unary operator type: " +
std::to_string(optype) +
99 const auto result = str +
" LIKE " + pattern;
102 return result +
" ESCAPE " + escape;
108 std::string case_str =
"CASE ";
110 for (
const auto& expr_pair : expr_pair_list) {
111 const auto when =
"WHEN " +
visit(expr_pair.first.get());
112 const auto then =
" THEN " +
visit(expr_pair.second.get());
113 case_str += when + then;
127 return agg_type +
"(" + distinct + arg +
")";
135 if (result ==
"||") {
139 if (result ==
"SUBSTRING") {
142 std::vector<std::string> arg_strs;
143 for (
size_t i = 0; i < func_oper->
getArity(); ++i) {
159 if (!partition_strs.empty()) {
164 std::vector<std::string> order_strs;
167 CHECK_EQ(order_keys.size(), collation.size());
168 for (
size_t i = 0; i < order_keys.size(); ++i) {
169 std::string order_str =
visit(order_keys[i].
get());
170 order_str += collation[i].is_desc ?
" DESC" :
" ASC";
172 order_strs.push_back(order_str);
174 if (!order_strs.empty()) {
217 return "BBOX_INTERSECT";
219 LOG(
FATAL) <<
"Invalid operator type: " << op_type;
224 template <
typename List>
226 std::vector<std::string>
result;
227 for (
const auto& expression : expressions) {
228 result.push_back(
visit(expression.get()));
237 auto qual_strings = scalar_expr_to_sql.
visitList(ra_exe_unit->
quals);
238 const auto simple_qual_strings =
241 qual_strings.end(), simple_qual_strings.begin(), simple_qual_strings.end());
247 std::vector<std::string> qual_strings;
248 for (
const auto& join_level_quals : ra_exe_unit->
join_quals) {
249 const auto level_qual_strings = scalar_expr_to_sql.
visitList(join_level_quals.quals);
251 qual_strings.end(), level_qual_strings.begin(), level_qual_strings.end());
258 std::vector<std::string> target_strings;
260 target_strings.push_back(scalar_expr_to_sql.
visit(target));
275 std::vector<std::string> from_strings;
276 for (
const auto& input_desc : ra_exe_unit->
input_descs) {
277 const auto& table_key = input_desc.getTableKey();
281 from_strings.push_back(table_ref);
286 std::string
maybe(
const std::string& prefix,
const std::string& clause) {
287 return clause.empty() ?
"" :
" " + prefix +
" " + clause;
298 return td->tableName;
310 return cd->columnName;
321 return {
"SELECT " + targets +
" FROM " + from +
maybe(
"ON", join_on) +
322 maybe(
"WHERE", where) +
maybe(
"GROUP BY", group),
bool is_supported_type_for_extern_execution(const SQLTypeInfo &ti)
std::vector< Analyzer::Expr * > target_exprs
SqlWindowFunctionKind getKind() const
std::string join_condition_to_string(const RelAlgExecutionUnit *ra_exe_unit)
std::string group_by_to_string(const RelAlgExecutionUnit *ra_exe_unit)
std::string visitColumnVar(const Analyzer::ColumnVar *col_var) const override
const Expr * get_else_expr() const
std::string DatumToString(Datum d, const SQLTypeInfo &ti)
const Expr * get_escape_expr() const
class for a per-database catalog. also includes metadata for the current database and the current use...
const Expr * get_right_operand() const
std::string maybe(const std::string &prefix, const std::string &clause)
std::vector< InputDescriptor > input_descs
std::string visitWindowFunction(const Analyzer::WindowFunction *window_func) const override
std::string targets_to_string(const RelAlgExecutionUnit *ra_exe_unit)
ScalarExprToSql(const RelAlgExecutionUnit *ra_exe_unit)
std::string visit(const Analyzer::Expr *expr) const
const std::list< std::shared_ptr< Analyzer::Expr > > groupby_exprs
const std::vector< std::shared_ptr< Analyzer::Expr > > & getOrderKeys() const
std::string visitBinOper(const Analyzer::BinOper *bin_oper) const override
const std::vector< OrderEntry > & getCollation() const
const Expr * get_arg() const
std::vector< std::string > visitList(const List &expressions) const
std::string visitConstant(const Analyzer::Constant *constant) const override
std::string serialize_column_ref(const int table_id, const int column_id, const Catalog_Namespace::Catalog *catalog)
std::string visitAggExpr(const Analyzer::AggExpr *agg) const override
SQLOps get_optype() const
static SysCatalog & instance()
const std::vector< std::shared_ptr< Analyzer::Expr > > & getArgs() const
const JoinQualsPerNestingLevel join_quals
std::string visitCaseExpr(const Analyzer::CaseExpr *case_) const override
const ColumnDescriptor * getMetadataForColumn(int tableId, const std::string &colName) const
int32_t get_varno() const
bool get_is_distinct() const
std::string toString(const Executor::ExtModuleKinds &kind)
const SQLTypeInfo & get_type_info() const
std::string visitVar(const Analyzer::Var *) const override
std::string visitLikeExpr(const Analyzer::LikeExpr *like) const override
std::shared_ptr< Catalog > getCatalog(const std::string &dbName)
const shared::ColumnKey & getColumnKey() const
static std::string binOpTypeToString(const SQLOps op_type)
const Expr * get_like_expr() const
const Analyzer::Expr * getArg(const size_t i) const
const Expr * get_operand() const
Datum get_constval() const
const std::list< std::shared_ptr< Analyzer::Expr > > & get_value_list() const
ExecutionUnitSql serialize_to_sql(const RelAlgExecutionUnit *ra_exe_unit)
std::string get_type_name() const
const RelAlgExecutionUnit * ra_exe_unit_
std::string from_to_string(const RelAlgExecutionUnit *ra_exe_unit)
SQLAgg get_aggtype() const
std::list< std::shared_ptr< Analyzer::Expr > > quals
std::string agg_to_string(const Analyzer::AggExpr *agg_expr, const RelAlgExecutionUnit *ra_exe_unit)
std::string visitFunctionOper(const Analyzer::FunctionOper *func_oper) const override
std::string visitUOper(const Analyzer::UOper *uoper) const override
const Expr * get_left_operand() const
std::string where_to_string(const RelAlgExecutionUnit *ra_exe_unit)
const TableDescriptor * getMetadataForTable(const std::string &tableName, const bool populateFragmenter=true) const
Returns a pointer to a const TableDescriptor struct matching the provided tableName.
std::string getName() const
std::string visitInValues(const Analyzer::InValues *in_values) const override
const std::vector< std::shared_ptr< Analyzer::Expr > > & getPartitionKeys() const
std::string serialize_table_ref(const int table_id, const Catalog_Namespace::Catalog *catalog)
const Expr * get_arg() const
SQLOps get_optype() const
const std::list< std::pair< std::shared_ptr< Analyzer::Expr >, std::shared_ptr< Analyzer::Expr > > > & get_expr_pair_list() const
std::list< std::shared_ptr< Analyzer::Expr > > simple_quals