26 #include <boost/algorithm/string.hpp>
27 #include <boost/core/null_deleter.hpp>
28 #include <boost/filesystem.hpp>
29 #include <boost/function.hpp>
31 #include <rapidjson/document.h>
32 #include <rapidjson/stringbuffer.h>
33 #include <rapidjson/writer.h>
42 #include <type_traits>
76 #include "gen-cpp/CalciteServer.h"
84 #ifdef ENABLE_IMPORT_PARQUET
85 bool g_enable_legacy_parquet_import{
false};
94 using namespace std::string_literals;
98 const std::list<ColumnDescriptor>& columns)>;
103 const std::list<ColumnDescriptor>& columns)>;
112 executor->getSessionLock());
113 return executor->checkIsQuerySessionInterrupted(query_session, session_read_lock);
120 std::vector<int> table_chunk_key_prefix;
123 table_chunk_key_prefix = td->
fragmenter->getFragmentsForQuery().chunkKeyPrefix;
126 table_chunk_key_prefix.push_back(td->
tableId);
129 return table_chunk_key_prefix;
132 std::shared_ptr<Analyzer::Expr> NullLiteral::analyze(
136 return makeExpr<Analyzer::Constant>(
kNULLT,
true);
139 std::shared_ptr<Analyzer::Expr> StringLiteral::analyze(
143 return analyzeValue(*stringval_,
false);
146 std::shared_ptr<Analyzer::Expr> StringLiteral::analyzeValue(
const std::string& stringval,
151 d.
stringval =
new std::string(stringval);
152 return makeExpr<Analyzer::Constant>(ti,
false, d);
155 return makeExpr<Analyzer::Constant>(
kVARCHAR,
true);
158 std::shared_ptr<Analyzer::Expr> IntLiteral::analyze(
162 return analyzeValue(intval_);
165 std::shared_ptr<Analyzer::Expr> IntLiteral::analyzeValue(
const int64_t intval) {
168 if (intval >= INT16_MIN && intval <= INT16_MAX) {
171 }
else if (intval >= INT32_MIN && intval <= INT32_MAX) {
173 d.
intval = (int32_t)intval;
178 return makeExpr<Analyzer::Constant>(t,
false, d);
181 std::shared_ptr<Analyzer::Expr> FixedPtLiteral::analyze(
187 return makeExpr<Analyzer::Constant>(ti,
false, d);
190 std::shared_ptr<Analyzer::Expr> FixedPtLiteral::analyzeValue(
const int64_t numericval,
192 const int precision) {
198 return makeExpr<Analyzer::Constant>(ti,
false, d);
201 std::shared_ptr<Analyzer::Expr> FloatLiteral::analyze(
207 return makeExpr<Analyzer::Constant>(
kFLOAT,
false, d);
210 std::shared_ptr<Analyzer::Expr> DoubleLiteral::analyze(
216 return makeExpr<Analyzer::Constant>(
kDOUBLE,
false, d);
219 std::shared_ptr<Analyzer::Expr> TimestampLiteral::analyze(
223 return get(timestampval_);
226 std::shared_ptr<Analyzer::Expr> TimestampLiteral::get(
const int64_t timestampval) {
229 return makeExpr<Analyzer::Constant>(
kTIMESTAMP,
false, d);
232 std::shared_ptr<Analyzer::Expr> UserLiteral::analyze(
237 return makeExpr<Analyzer::Constant>(
kTEXT,
false, d);
240 std::shared_ptr<Analyzer::Expr> UserLiteral::get(
const std::string& user) {
243 return makeExpr<Analyzer::Constant>(
kTEXT,
false, d);
246 std::shared_ptr<Analyzer::Expr> ArrayLiteral::analyze(
251 bool set_subtype =
true;
252 std::list<std::shared_ptr<Analyzer::Expr>> value_exprs;
253 for (
auto& p : value_list_) {
254 auto e = p->analyze(catalog, query, allow_tlist_ref);
257 if (c !=
nullptr && c->get_is_null()) {
258 value_exprs.push_back(c);
264 }
else if (set_subtype) {
268 value_exprs.push_back(e);
270 std::shared_ptr<Analyzer::Expr>
result =
271 makeExpr<Analyzer::Constant>(ti,
false, value_exprs);
276 std::string str =
"{";
277 bool notfirst =
false;
278 for (
auto& p : value_list_) {
284 str += p->to_string();
290 std::shared_ptr<Analyzer::Expr> OperExpr::analyze(
294 auto left_expr = left_->analyze(catalog, query, allow_tlist_ref);
295 const auto& left_type = left_expr->get_type_info();
296 if (right_ ==
nullptr) {
297 return makeExpr<Analyzer::UOper>(
298 left_type, left_expr->get_contains_agg(), optype_, left_expr->decompress());
301 if (left_type.get_type() !=
kARRAY) {
302 throw std::runtime_error(left_->to_string() +
" is not of array type.");
304 auto right_expr = right_->analyze(catalog, query, allow_tlist_ref);
305 const auto& right_type = right_expr->get_type_info();
306 if (!right_type.is_integer()) {
307 throw std::runtime_error(right_->to_string() +
" is not of integer type.");
309 return makeExpr<Analyzer::BinOper>(
310 left_type.get_elem_type(),
false,
kARRAY_AT,
kONE, left_expr, right_expr);
312 auto right_expr = right_->analyze(catalog, query, allow_tlist_ref);
313 return normalize(optype_, opqualifier_, left_expr, right_expr);
317 const std::shared_ptr<Analyzer::Expr>& rhs_expr) {
318 if (dynamic_cast<Analyzer::Constant*>(rhs_expr.get())) {
322 std::set<int> lhs_rte_idx;
323 lhs_expr->collect_rte_idx(lhs_rte_idx);
324 CHECK(!lhs_rte_idx.empty());
325 std::set<int> rhs_rte_idx;
326 rhs_expr->collect_rte_idx(rhs_rte_idx);
327 CHECK(!rhs_rte_idx.empty());
328 return lhs_rte_idx.size() == 1UL && lhs_rte_idx == rhs_rte_idx;
333 const Executor* executor) {
340 CHECK_NE(lhs_dict_key, rhs_dict_key);
341 if (lhs_dict_key.isTransientDict()) {
342 return rhs_type_info;
344 if (rhs_dict_key.isTransientDict()) {
345 return lhs_type_info;
349 const auto lhs_sdp = executor->getStringDictionaryProxy(lhs_dict_key,
true);
350 const auto rhs_sdp = executor->getStringDictionaryProxy(rhs_dict_key,
true);
351 return lhs_sdp->entryCount() >= rhs_sdp->entryCount() ? lhs_type_info : rhs_type_info;
356 const Executor* executor) {
362 if (lhs_dict_key == rhs_dict_key ||
363 (lhs_dict_key.db_id == rhs_dict_key.db_id &&
365 return lhs_dict_key.
dict_id <= rhs_dict_key.dict_id ? lhs_type_info : rhs_type_info;
372 if (ret_ti.is_none_encoded_string()) {
379 std::shared_ptr<Analyzer::Expr> OperExpr::normalize(
382 std::shared_ptr<Analyzer::Expr> left_expr,
383 std::shared_ptr<Analyzer::Expr> right_expr,
384 const Executor* executor) {
385 if (left_expr->get_type_info().is_date_in_days() ||
386 right_expr->get_type_info().is_date_in_days()) {
388 left_expr = left_expr->decompress();
389 right_expr = right_expr->decompress();
391 const auto& left_type = left_expr->get_type_info();
392 auto right_type = right_expr->get_type_info();
395 CHECK(!std::dynamic_pointer_cast<Analyzer::Subquery>(right_expr));
396 if (right_type.get_type() !=
kARRAY) {
397 throw std::runtime_error(
398 "Existential or universal qualifiers can only be used in front of a subquery "
400 "expression of array type.");
402 right_type = right_type.get_elem_type();
407 optype, left_type, right_type, &new_left_type, &new_right_type);
408 if (result_type.is_timeinterval()) {
409 return makeExpr<Analyzer::BinOper>(
410 result_type,
false, optype, qual, left_expr, right_expr);
412 if (left_type != new_left_type) {
413 left_expr = left_expr->add_cast(new_left_type);
415 if (right_type != new_right_type) {
417 right_expr = right_expr->add_cast(new_right_type);
419 right_expr = right_expr->add_cast(new_right_type.
get_array_type());
426 throw std::runtime_error(
427 "Comparison operators are not yet supported for geospatial types.");
433 if (optype ==
kEQ || optype ==
kNE) {
445 auto& expr_to_cast = ti == new_left_type ? right_expr : left_expr;
448 expr_to_cast = expr_to_cast->add_cast(ti);
453 left_expr = left_expr->decompress();
454 right_expr = right_expr->decompress();
460 left_expr = left_expr->decompress();
461 right_expr = right_expr->decompress();
464 if (!(optype ==
kEQ || optype ==
kNE)) {
467 left_expr = left_expr->decompress();
468 right_expr = right_expr->decompress();
482 right_expr = right_expr->add_cast(ti);
490 left_expr = left_expr->add_cast(ti);
492 left_expr = left_expr->decompress();
493 right_expr = right_expr->decompress();
497 left_expr = left_expr->decompress();
498 right_expr = right_expr->decompress();
500 bool has_agg = (left_expr->get_contains_agg() || right_expr->get_contains_agg());
501 return makeExpr<Analyzer::BinOper>(
502 result_type, has_agg, optype, qual, left_expr, right_expr);
505 std::shared_ptr<Analyzer::Expr> SubqueryExpr::analyze(
509 throw std::runtime_error(
"Subqueries are not supported yet.");
513 std::shared_ptr<Analyzer::Expr> IsNullExpr::analyze(
517 auto arg_expr = arg_->analyze(catalog, query, allow_tlist_ref);
525 std::shared_ptr<Analyzer::Expr> InSubquery::analyze(
529 throw std::runtime_error(
"Subqueries are not supported yet.");
533 std::shared_ptr<Analyzer::Expr> InValues::analyze(
537 auto arg_expr = arg_->analyze(catalog, query, allow_tlist_ref);
540 std::list<std::shared_ptr<Analyzer::Expr>> value_exprs;
541 for (
auto& p : value_list_) {
542 auto e = p->analyze(catalog, query, allow_tlist_ref);
543 if (ti != e->get_type_info()) {
544 if (ti.
is_string() && e->get_type_info().is_string()) {
547 }
else if (ti.
is_number() && e->get_type_info().is_number()) {
550 throw std::runtime_error(
"IN expressions must contain compatible types.");
554 value_exprs.push_back(e->add_cast(arg_expr->get_type_info()));
556 value_exprs.push_back(e);
560 arg_expr = arg_expr->decompress();
561 arg_expr = arg_expr->add_cast(ti);
562 std::list<std::shared_ptr<Analyzer::Expr>> cast_vals;
563 for (
auto p : value_exprs) {
564 cast_vals.push_back(p->add_cast(ti));
566 value_exprs.swap(cast_vals);
568 std::shared_ptr<Analyzer::Expr>
result =
569 makeExpr<Analyzer::InValues>(arg_expr, value_exprs);
576 std::shared_ptr<Analyzer::Expr> BetweenExpr::analyze(
580 auto arg_expr = arg_->analyze(catalog, query, allow_tlist_ref);
581 auto lower_expr = lower_->analyze(catalog, query, allow_tlist_ref);
582 auto upper_expr = upper_->analyze(catalog, query, allow_tlist_ref);
585 arg_expr->get_type_info(),
586 lower_expr->get_type_info(),
590 makeExpr<Analyzer::BinOper>(
kBOOLEAN,
593 arg_expr->add_cast(new_left_type)->decompress(),
594 lower_expr->add_cast(new_right_type)->decompress());
596 arg_expr->get_type_info(),
597 lower_expr->get_type_info(),
600 auto upper_pred = makeExpr<Analyzer::BinOper>(
604 arg_expr->deep_copy()->add_cast(new_left_type)->decompress(),
605 upper_expr->add_cast(new_right_type)->decompress());
606 std::shared_ptr<Analyzer::Expr>
result =
614 std::shared_ptr<Analyzer::Expr> CharLengthExpr::analyze(
618 auto arg_expr = arg_->analyze(catalog, query, allow_tlist_ref);
619 if (!arg_expr->get_type_info().is_string()) {
620 throw std::runtime_error(
621 "expression in char_length clause must be of a string type.");
623 std::shared_ptr<Analyzer::Expr>
result =
624 makeExpr<Analyzer::CharLengthExpr>(arg_expr->decompress(), calc_encoded_length_);
628 std::shared_ptr<Analyzer::Expr> CardinalityExpr::analyze(
632 auto arg_expr = arg_->analyze(catalog, query, allow_tlist_ref);
633 if (!arg_expr->get_type_info().is_array()) {
634 throw std::runtime_error(
635 "expression in cardinality clause must be of an array type.");
637 std::shared_ptr<Analyzer::Expr>
result =
638 makeExpr<Analyzer::CardinalityExpr>(arg_expr->decompress());
642 void LikeExpr::check_like_expr(
const std::string& like_str,
char escape_char) {
643 if (like_str.back() == escape_char) {
644 throw std::runtime_error(
"LIKE pattern must not end with escape character.");
648 bool LikeExpr::test_is_simple_expr(
const std::string& like_str,
char escape_char) {
650 if (like_str.size() < 2 || like_str[0] !=
'%' || like_str[like_str.size() - 1] !=
'%') {
654 if (like_str[like_str.size() - 2] == escape_char &&
655 like_str[like_str.size() - 3] != escape_char) {
658 for (
size_t i = 1; i < like_str.size() - 1; i++) {
659 if (like_str[i] ==
'%' || like_str[i] ==
'_' || like_str[i] ==
'[' ||
660 like_str[i] ==
']') {
661 if (like_str[i - 1] != escape_char) {
669 void LikeExpr::erase_cntl_chars(std::string& like_str,
char escape_char) {
670 char prev_char =
'\0';
675 for (
char& cur_char : like_str) {
676 if (cur_char ==
'%' || cur_char == escape_char) {
677 if (prev_char != escape_char) {
678 prev_char = cur_char;
682 new_str.push_back(cur_char);
683 prev_char = cur_char;
688 std::shared_ptr<Analyzer::Expr> LikeExpr::analyze(
692 auto arg_expr = arg_->analyze(catalog, query, allow_tlist_ref);
693 auto like_expr = like_string_->analyze(catalog, query, allow_tlist_ref);
694 auto escape_expr = escape_string_ ==
nullptr
696 : escape_string_->analyze(catalog, query, allow_tlist_ref);
697 return LikeExpr::get(arg_expr, like_expr, escape_expr, is_ilike_, is_not_);
700 std::shared_ptr<Analyzer::Expr> LikeExpr::get(std::shared_ptr<Analyzer::Expr> arg_expr,
701 std::shared_ptr<Analyzer::Expr> like_expr,
702 std::shared_ptr<Analyzer::Expr> escape_expr,
705 if (!arg_expr->get_type_info().is_string()) {
706 throw std::runtime_error(
"expression before LIKE must be of a string type.");
708 if (!like_expr->get_type_info().is_string()) {
709 throw std::runtime_error(
"expression after LIKE must be of a string type.");
711 char escape_char =
'\\';
712 if (escape_expr !=
nullptr) {
713 if (!escape_expr->get_type_info().is_string()) {
714 throw std::runtime_error(
"expression after ESCAPE must be of a string type.");
716 if (!escape_expr->get_type_info().is_string()) {
717 throw std::runtime_error(
"expression after ESCAPE must be of a string type.");
720 if (c !=
nullptr && c->get_constval().stringval->length() > 1) {
721 throw std::runtime_error(
"String after ESCAPE must have a single character.");
723 escape_char = (*c->get_constval().stringval)[0];
726 bool is_simple =
false;
730 std::transform(pattern.begin(), pattern.end(), pattern.begin(), ::tolower);
732 check_like_expr(pattern, escape_char);
733 is_simple = test_is_simple_expr(pattern, escape_char);
735 erase_cntl_chars(pattern, escape_char);
738 std::shared_ptr<Analyzer::Expr>
result = makeExpr<Analyzer::LikeExpr>(
739 arg_expr->decompress(), like_expr, escape_expr, is_ilike, is_simple);
746 void RegexpExpr::check_pattern_expr(
const std::string& pattern_str,
char escape_char) {
747 if (pattern_str.back() == escape_char) {
748 throw std::runtime_error(
"REGEXP pattern must not end with escape character.");
752 bool RegexpExpr::translate_to_like_pattern(std::string& pattern_str,
char escape_char) {
753 char prev_char =
'\0';
754 char prev_prev_char =
'\0';
755 std::string like_str;
756 for (
char& cur_char : pattern_str) {
757 if (prev_char == escape_char || isalnum(cur_char) || cur_char ==
' ' ||
759 like_str.push_back((cur_char ==
'.') ?
'_' : cur_char);
760 prev_prev_char = prev_char;
761 prev_char = cur_char;
764 if (prev_char ==
'.' && prev_prev_char != escape_char) {
765 if (cur_char ==
'*' || cur_char ==
'+') {
766 if (cur_char ==
'*') {
771 like_str.push_back(
'%');
772 prev_prev_char = prev_char;
773 prev_char = cur_char;
779 pattern_str = like_str;
783 std::shared_ptr<Analyzer::Expr> RegexpExpr::analyze(
787 auto arg_expr = arg_->analyze(catalog, query, allow_tlist_ref);
788 auto pattern_expr = pattern_string_->analyze(catalog, query, allow_tlist_ref);
789 auto escape_expr = escape_string_ ==
nullptr
791 : escape_string_->analyze(catalog, query, allow_tlist_ref);
792 return RegexpExpr::get(arg_expr, pattern_expr, escape_expr, is_not_);
795 std::shared_ptr<Analyzer::Expr> RegexpExpr::get(
796 std::shared_ptr<Analyzer::Expr> arg_expr,
797 std::shared_ptr<Analyzer::Expr> pattern_expr,
798 std::shared_ptr<Analyzer::Expr> escape_expr,
800 if (!arg_expr->get_type_info().is_string()) {
801 throw std::runtime_error(
"expression before REGEXP must be of a string type.");
803 if (!pattern_expr->get_type_info().is_string()) {
804 throw std::runtime_error(
"expression after REGEXP must be of a string type.");
806 char escape_char =
'\\';
807 if (escape_expr !=
nullptr) {
808 if (!escape_expr->get_type_info().is_string()) {
809 throw std::runtime_error(
"expression after ESCAPE must be of a string type.");
811 if (!escape_expr->get_type_info().is_string()) {
812 throw std::runtime_error(
"expression after ESCAPE must be of a string type.");
815 if (c !=
nullptr && c->get_constval().stringval->length() > 1) {
816 throw std::runtime_error(
"String after ESCAPE must have a single character.");
818 escape_char = (*c->get_constval().stringval)[0];
819 if (escape_char !=
'\\') {
820 throw std::runtime_error(
"Only supporting '\\' escape character.");
826 if (translate_to_like_pattern(pattern, escape_char)) {
827 return LikeExpr::get(arg_expr, pattern_expr, escape_expr,
false, is_not);
830 std::shared_ptr<Analyzer::Expr>
result =
831 makeExpr<Analyzer::RegexpExpr>(arg_expr->decompress(), pattern_expr, escape_expr);
838 std::shared_ptr<Analyzer::Expr> LikelihoodExpr::analyze(
842 auto arg_expr = arg_->analyze(catalog, query, allow_tlist_ref);
843 return LikelihoodExpr::get(arg_expr, likelihood_, is_not_);
846 std::shared_ptr<Analyzer::Expr> LikelihoodExpr::get(
847 std::shared_ptr<Analyzer::Expr> arg_expr,
850 if (!arg_expr->get_type_info().is_boolean()) {
851 throw std::runtime_error(
"likelihood expression expects boolean type.");
853 std::shared_ptr<Analyzer::Expr>
result = makeExpr<Analyzer::LikelihoodExpr>(
854 arg_expr->decompress(), is_not ? 1 - likelihood : likelihood);
858 std::shared_ptr<Analyzer::Expr> WidthBucketExpr::analyze(
862 auto target_value = target_value_->analyze(catalog, query, allow_tlist_ref);
863 auto lower_bound = lower_bound_->analyze(catalog, query, allow_tlist_ref);
864 auto upper_bound = upper_bound_->analyze(catalog, query, allow_tlist_ref);
865 auto partition_count = partition_count_->analyze(catalog, query, allow_tlist_ref);
869 std::shared_ptr<Analyzer::Expr> WidthBucketExpr::get(
870 std::shared_ptr<Analyzer::Expr> target_value,
873 std::shared_ptr<Analyzer::Expr> partition_count) {
874 std::shared_ptr<Analyzer::Expr>
result = makeExpr<Analyzer::WidthBucketExpr>(
879 std::shared_ptr<Analyzer::Expr> ExistsExpr::analyze(
883 throw std::runtime_error(
"Subqueries are not supported yet.");
887 std::shared_ptr<Analyzer::Expr> ColumnRef::analyze(
894 if (column_ ==
nullptr) {
895 throw std::runtime_error(
"invalid column name *.");
897 if (table_ !=
nullptr) {
900 throw std::runtime_error(
"range variable or table name " + *table_ +
906 throw std::runtime_error(
"Column name " + *column_ +
" does not exist.");
913 cd = rte->get_column_desc(catalog, *column_);
914 if (cd !=
nullptr && !found) {
917 table_id = rte->get_table_id();
918 }
else if (cd !=
nullptr && found) {
919 throw std::runtime_error(
"Column name " + *column_ +
" is ambiguous.");
923 if (cd ==
nullptr && allow_tlist_ref != TlistRefType::TLIST_NONE) {
928 std::shared_ptr<Analyzer::TargetEntry> tle;
930 if (*column_ == p->get_resname() && !found) {
934 }
else if (*column_ == p->get_resname() && found) {
935 throw std::runtime_error(
"Output alias " + *column_ +
" is ambiguous.");
940 if (dynamic_cast<Analyzer::Var*>(tle->get_expr())) {
946 if (allow_tlist_ref == TlistRefType::TLIST_COPY) {
947 return tle->get_expr()->deep_copy();
949 return makeExpr<Analyzer::Var>(
955 throw std::runtime_error(
"Column name " + *column_ +
" does not exist.");
958 return makeExpr<Analyzer::ColumnVar>(
964 std::shared_ptr<Analyzer::Expr> FunctionRef::analyze(
970 std::shared_ptr<Analyzer::Expr> arg_expr;
972 if (boost::iequals(*name_,
"count")) {
976 arg_expr = arg_->analyze(catalog, query, allow_tlist_ref);
979 throw std::runtime_error(
980 "Strings must be dictionary-encoded in COUNT(DISTINCT).");
983 throw std::runtime_error(
"Only COUNT(DISTINCT) is supported on arrays.");
986 is_distinct = distinct_;
989 throw std::runtime_error(
"Cannot compute " + *name_ +
" with argument '*'.");
991 if (boost::iequals(*name_,
"min")) {
993 arg_expr = arg_->analyze(catalog, query, allow_tlist_ref);
994 arg_expr = arg_expr->decompress();
995 result_type = arg_expr->get_type_info();
996 }
else if (boost::iequals(*name_,
"max")) {
998 arg_expr = arg_->analyze(catalog, query, allow_tlist_ref);
999 arg_expr = arg_expr->decompress();
1000 result_type = arg_expr->get_type_info();
1001 }
else if (boost::iequals(*name_,
"avg")) {
1003 arg_expr = arg_->analyze(catalog, query, allow_tlist_ref);
1004 if (!arg_expr->get_type_info().is_number()) {
1005 throw std::runtime_error(
"Cannot compute AVG on non-number-type arguments.");
1007 arg_expr = arg_expr->decompress();
1009 }
else if (boost::iequals(*name_,
"sum")) {
1011 arg_expr = arg_->analyze(catalog, query, allow_tlist_ref);
1012 if (!arg_expr->get_type_info().is_number()) {
1013 throw std::runtime_error(
"Cannot compute SUM on non-number-type arguments.");
1015 arg_expr = arg_expr->decompress();
1017 : arg_expr->get_type_info();
1018 }
else if (boost::iequals(*name_,
"unnest")) {
1019 arg_expr = arg_->analyze(catalog, query, allow_tlist_ref);
1020 const SQLTypeInfo& arg_ti = arg_expr->get_type_info();
1022 throw std::runtime_error(arg_->to_string() +
" is not of array type.");
1026 throw std::runtime_error(
"invalid function name: " + *name_);
1028 if (arg_expr->get_type_info().is_string() ||
1029 arg_expr->get_type_info().get_type() ==
kARRAY) {
1030 throw std::runtime_error(
1031 "Only COUNT(DISTINCT ) aggregate is supported on strings and arrays.");
1036 return makeExpr<Analyzer::AggExpr>(
1037 result_type, agg_type, arg_expr,
is_distinct,
nullptr);
1040 std::shared_ptr<Analyzer::Expr> CastExpr::analyze(
1044 target_type_->check_type();
1045 auto arg_expr = arg_->analyze(catalog, query, allow_tlist_ref);
1047 target_type_->get_param1(),
1048 target_type_->get_param2(),
1049 arg_expr->get_type_info().get_notnull());
1050 if (arg_expr->get_type_info().get_type() != target_type_->get_type() &&
1052 arg_expr->decompress();
1054 return arg_expr->add_cast(ti);
1057 std::shared_ptr<Analyzer::Expr> CaseExpr::analyze(
1062 std::list<std::pair<std::shared_ptr<Analyzer::Expr>, std::shared_ptr<Analyzer::Expr>>>
1064 for (
auto& p : when_then_list_) {
1065 auto e1 = p->get_expr1()->analyze(catalog, query, allow_tlist_ref);
1066 if (e1->get_type_info().get_type() !=
kBOOLEAN) {
1067 throw std::runtime_error(
"Only boolean expressions can be used after WHEN.");
1069 auto e2 = p->get_expr2()->analyze(catalog, query, allow_tlist_ref);
1070 expr_pair_list.emplace_back(e1, e2);
1073 else_expr_ ? else_expr_->analyze(catalog, query, allow_tlist_ref) :
nullptr;
1074 return normalize(expr_pair_list, else_e);
1081 if (*s ==
"t" || *s ==
"true" || *s ==
"T" || *s ==
"True") {
1083 }
else if (*s ==
"f" || *s ==
"false" || *s ==
"F" || *s ==
"False") {
1086 throw std::runtime_error(
"Invalid string for boolean " + *s);
1092 std::vector<std::string>& warnings,
1093 std::string& deferred_copy_from_partitions_) {
1094 if (!options_.empty()) {
1095 for (
auto& p : options_) {
1096 if (boost::iequals(*p->get_name(),
"max_reject")) {
1098 if (int_literal ==
nullptr) {
1099 throw std::runtime_error(
"max_reject option must be an integer.");
1102 }
else if (boost::iequals(*p->get_name(),
"max_import_batch_row_count")) {
1104 if (int_literal ==
nullptr) {
1105 throw std::runtime_error(
1106 "max_import_batch_row_count option must be an integer.");
1109 throw std::runtime_error(
1110 "max_import_batch_row_count option must be a positive integer (greater "
1114 }
else if (boost::iequals(*p->get_name(),
"buffer_size")) {
1116 if (int_literal ==
nullptr) {
1117 throw std::runtime_error(
"buffer_size option must be an integer.");
1120 }
else if (boost::iequals(*p->get_name(),
"threads")) {
1122 if (int_literal ==
nullptr) {
1123 throw std::runtime_error(
"Threads option must be an integer.");
1126 }
else if (boost::iequals(*p->get_name(),
"delimiter")) {
1129 if (str_literal ==
nullptr) {
1130 throw std::runtime_error(
"Delimiter option must be a string.");
1132 throw std::runtime_error(
"Delimiter must be a single character string.");
1135 }
else if (boost::iequals(*p->get_name(),
"nulls")) {
1138 if (str_literal ==
nullptr) {
1139 throw std::runtime_error(
"Nulls option must be a string.");
1142 }
else if (boost::iequals(*p->get_name(),
"header")) {
1145 if (str_literal ==
nullptr) {
1146 throw std::runtime_error(
"Header option must be a boolean.");
1151 #ifdef ENABLE_IMPORT_PARQUET
1152 }
else if (boost::iequals(*p->get_name(),
"parquet")) {
1153 warnings.emplace_back(
1154 "Deprecation Warning: COPY FROM WITH (parquet='true') is deprecated. Use "
1155 "WITH (source_type='parquet_file') instead.");
1158 if (str_literal ==
nullptr) {
1159 throw std::runtime_error(
"'parquet' option must be a boolean.");
1166 #endif // ENABLE_IMPORT_PARQUET
1167 }
else if (boost::iequals(*p->get_name(),
"s3_access_key")) {
1170 if (str_literal ==
nullptr) {
1171 throw std::runtime_error(
"Option s3_access_key must be a string.");
1174 }
else if (boost::iequals(*p->get_name(),
"s3_secret_key")) {
1177 if (str_literal ==
nullptr) {
1178 throw std::runtime_error(
"Option s3_secret_key must be a string.");
1181 }
else if (boost::iequals(*p->get_name(),
"s3_session_token")) {
1184 if (str_literal ==
nullptr) {
1185 throw std::runtime_error(
"Option s3_session_token must be a string.");
1188 }
else if (boost::iequals(*p->get_name(),
"s3_region")) {
1191 if (str_literal ==
nullptr) {
1192 throw std::runtime_error(
"Option s3_region must be a string.");
1195 }
else if (boost::iequals(*p->get_name(),
"s3_endpoint")) {
1198 if (str_literal ==
nullptr) {
1199 throw std::runtime_error(
"Option s3_endpoint must be a string.");
1202 }
else if (boost::iequals(*p->get_name(),
"s3_max_concurrent_downloads")) {
1204 if (int_literal ==
nullptr) {
1205 throw std::runtime_error(
1206 "'s3_max_concurrent_downloads' option must be an integer");
1208 const int s3_max_concurrent_downloads = int_literal->
get_intval();
1209 if (s3_max_concurrent_downloads > 0) {
1212 throw std::runtime_error(
1213 "Invalid value for 's3_max_concurrent_downloads' option (must be > 0): " +
1216 }
else if (boost::iequals(*p->get_name(),
"quote")) {
1219 if (str_literal ==
nullptr) {
1220 throw std::runtime_error(
"Quote option must be a string.");
1222 throw std::runtime_error(
"Quote must be a single character string.");
1225 }
else if (boost::iequals(*p->get_name(),
"escape")) {
1228 if (str_literal ==
nullptr) {
1229 throw std::runtime_error(
"Escape option must be a string.");
1231 throw std::runtime_error(
"Escape must be a single character string.");
1234 }
else if (boost::iequals(*p->get_name(),
"line_delimiter")) {
1237 if (str_literal ==
nullptr) {
1238 throw std::runtime_error(
"Line_delimiter option must be a string.");
1240 throw std::runtime_error(
"Line_delimiter must be a single character string.");
1243 }
else if (boost::iequals(*p->get_name(),
"quoted")) {
1246 if (str_literal ==
nullptr) {
1247 throw std::runtime_error(
"Quoted option must be a boolean.");
1250 }
else if (boost::iequals(*p->get_name(),
"plain_text")) {
1253 if (str_literal ==
nullptr) {
1254 throw std::runtime_error(
"plain_text option must be a boolean.");
1257 }
else if (boost::iequals(*p->get_name(),
"trim_spaces")) {
1260 if (str_literal ==
nullptr) {
1261 throw std::runtime_error(
"trim_spaces option must be a boolean.");
1264 }
else if (boost::iequals(*p->get_name(),
"array_marker")) {
1267 if (str_literal ==
nullptr) {
1268 throw std::runtime_error(
"Array Marker option must be a string.");
1270 throw std::runtime_error(
1271 "Array Marker option must be exactly two characters. Default is {}.");
1275 }
else if (boost::iequals(*p->get_name(),
"array_delimiter")) {
1278 if (str_literal ==
nullptr) {
1279 throw std::runtime_error(
"Array Delimiter option must be a string.");
1281 throw std::runtime_error(
"Array Delimiter must be a single character string.");
1284 }
else if (boost::iequals(*p->get_name(),
"lonlat")) {
1287 if (str_literal ==
nullptr) {
1288 throw std::runtime_error(
"Lonlat option must be a boolean.");
1291 }
else if (boost::iequals(*p->get_name(),
"geo")) {
1292 warnings.emplace_back(
1293 "Deprecation Warning: COPY FROM WITH (geo='true') is deprecated. Use WITH "
1294 "(source_type='geo_file') instead.");
1297 if (str_literal ==
nullptr) {
1298 throw std::runtime_error(
"'geo' option must be a boolean.");
1303 }
else if (boost::iequals(*p->get_name(),
"source_type")) {
1306 if (str_literal ==
nullptr) {
1307 throw std::runtime_error(
"'source_type' option must be a string.");
1310 if (boost::iequals(*s,
"delimited_file")) {
1312 }
else if (boost::iequals(*s,
"geo_file")) {
1314 #if ENABLE_IMPORT_PARQUET
1315 }
else if (boost::iequals(*s,
"parquet_file")) {
1318 }
else if (boost::iequals(*s,
"raster_file")) {
1320 }
else if (boost::iequals(*s,
"regex_parsed_file")) {
1323 throw std::runtime_error(
1324 "Invalid string for 'source_type' option (must be 'GEO_FILE', 'RASTER_FILE'"
1325 #
if ENABLE_IMPORT_PARQUET
1328 ", 'REGEX_PARSED_FILE'"
1329 " or 'DELIMITED_FILE'): " +
1332 }
else if (boost::iequals(*p->get_name(),
"geo_coords_type")) {
1335 if (str_literal ==
nullptr) {
1336 throw std::runtime_error(
"'geo_coords_type' option must be a string");
1339 if (boost::iequals(*s,
"geography")) {
1340 throw std::runtime_error(
1341 "GEOGRAPHY coords type not yet supported. Please use GEOMETRY.");
1343 }
else if (boost::iequals(*s,
"geometry")) {
1346 throw std::runtime_error(
1347 "Invalid string for 'geo_coords_type' option (must be 'GEOGRAPHY' or "
1351 }
else if (boost::iequals(*p->get_name(),
"raster_point_type")) {
1354 if (str_literal ==
nullptr) {
1355 throw std::runtime_error(
"'raster_point_type' option must be a string");
1358 if (boost::iequals(*s,
"none")) {
1360 }
else if (boost::iequals(*s,
"auto")) {
1362 }
else if (boost::iequals(*s,
"smallint")) {
1364 }
else if (boost::iequals(*s,
"int")) {
1366 }
else if (boost::iequals(*s,
"float")) {
1368 }
else if (boost::iequals(*s,
"double")) {
1370 }
else if (boost::iequals(*s,
"point")) {
1373 throw std::runtime_error(
1374 "Invalid string for 'raster_point_type' option (must be 'NONE', 'AUTO', "
1375 "'SMALLINT', 'INT', 'FLOAT', 'DOUBLE' or 'POINT'): " +
1378 }
else if (boost::iequals(*p->get_name(),
"raster_point_transform")) {
1381 if (str_literal ==
nullptr) {
1382 throw std::runtime_error(
"'raster_point_transform' option must be a string");
1385 if (boost::iequals(*s,
"none")) {
1387 }
else if (boost::iequals(*s,
"auto")) {
1389 }
else if (boost::iequals(*s,
"file")) {
1391 }
else if (boost::iequals(*s,
"world")) {
1395 throw std::runtime_error(
1396 "Invalid string for 'raster_point_transform' option (must be 'NONE', "
1397 "'AUTO', 'FILE' or 'WORLD'): " +
1400 }
else if (boost::iequals(*p->get_name(),
"raster_import_bands")) {
1403 if (str_literal ==
nullptr) {
1404 throw std::runtime_error(
"'raster_import_bands' option must be a string");
1406 const std::string* raster_import_bands = str_literal->
get_stringval();
1407 if (raster_import_bands) {
1410 throw std::runtime_error(
"Invalid value for 'raster_import_bands' option");
1412 }
else if (boost::iequals(*p->get_name(),
"raster_import_dimensions")) {
1415 if (str_literal ==
nullptr) {
1416 throw std::runtime_error(
"'raster_import_dimensions' option must be a string");
1418 const std::string* raster_import_dimensions = str_literal->
get_stringval();
1419 if (raster_import_dimensions) {
1422 throw std::runtime_error(
"Invalid value for 'raster_import_dimensions' option");
1424 }
else if (boost::iequals(*p->get_name(),
"geo_coords_encoding")) {
1427 if (str_literal ==
nullptr) {
1428 throw std::runtime_error(
"'geo_coords_encoding' option must be a string");
1431 if (boost::iequals(*s,
"none")) {
1434 }
else if (boost::iequals(*s,
"compressed(32)")) {
1438 throw std::runtime_error(
1439 "Invalid string for 'geo_coords_encoding' option (must be 'NONE' or "
1440 "'COMPRESSED(32)'): " +
1443 }
else if (boost::iequals(*p->get_name(),
"raster_scanlines_per_thread")) {
1445 if (int_literal ==
nullptr) {
1446 throw std::runtime_error(
1447 "'raster_scanlines_per_thread' option must be an integer");
1449 const int raster_scanlines_per_thread = int_literal->
get_intval();
1450 if (raster_scanlines_per_thread < 0) {
1451 throw std::runtime_error(
1452 "'raster_scanlines_per_thread' option must be >= 0, with 0 denoting auto "
1456 }
else if (boost::iequals(*p->get_name(),
"geo_coords_srid")) {
1458 if (int_literal ==
nullptr) {
1459 throw std::runtime_error(
"'geo_coords_srid' option must be an integer");
1462 if (srid == 4326 || srid == 3857 || srid == 900913) {
1465 throw std::runtime_error(
1466 "Invalid value for 'geo_coords_srid' option (must be 4326, 3857, or "
1470 }
else if (boost::iequals(*p->get_name(),
"geo_layer_name")) {
1473 if (str_literal ==
nullptr) {
1474 throw std::runtime_error(
"'geo_layer_name' option must be a string");
1476 const std::string* layer_name = str_literal->
get_stringval();
1480 throw std::runtime_error(
"Invalid value for 'geo_layer_name' option");
1482 }
else if (boost::iequals(*p->get_name(),
"partitions")) {
1483 const auto partitions =
1484 static_cast<const StringLiteral*
>(p->get_value())->get_stringval();
1486 const auto partitions_uc = boost::to_upper_copy<std::string>(*partitions);
1487 if (partitions_uc !=
"REPLICATED") {
1488 throw std::runtime_error(
1489 "Invalid value for 'partitions' option. Must be 'REPLICATED'.");
1491 deferred_copy_from_partitions_ = partitions_uc;
1492 }
else if (boost::iequals(*p->get_name(),
"geo_explode_collections")) {
1495 if (str_literal ==
nullptr) {
1496 throw std::runtime_error(
"geo_explode_collections option must be a boolean.");
1499 }
else if (boost::iequals(*p->get_name(),
"geo_validate_geometry")) {
1502 if (str_literal ==
nullptr) {
1503 throw std::runtime_error(
"geo_validate_geometry option must be a boolean.");
1511 throw std::runtime_error(
"GEOS geometry validation is not available.");
1514 }
else if (boost::iequals(*p->get_name(),
"source_srid")) {
1516 if (int_literal ==
nullptr) {
1517 throw std::runtime_error(
"'source_srid' option must be an integer");
1523 throw std::runtime_error(
1524 "'source_srid' option can only be used on csv/tsv files");
1526 }
else if (boost::iequals(*p->get_name(),
"regex_path_filter")) {
1529 if (str_literal ==
nullptr) {
1530 throw std::runtime_error(
"Option regex_path_filter must be a string.");
1534 string_val.empty() ? std::nullopt : std::optional<std::string>{string_val};
1535 }
else if (boost::iequals(*p->get_name(),
"file_sort_order_by")) {
1538 if (str_literal ==
nullptr) {
1539 throw std::runtime_error(
"Option file_sort_order_by must be a string.");
1543 string_val.empty() ? std::nullopt : std::optional<std::string>{string_val};
1544 }
else if (boost::iequals(*p->get_name(),
"file_sort_regex")) {
1547 if (str_literal ==
nullptr) {
1548 throw std::runtime_error(
"Option file_sort_regex must be a string.");
1552 string_val.empty() ? std::nullopt : std::optional<std::string>{string_val};
1553 }
else if (boost::iequals(*p->get_name(),
"raster_point_compute_angle")) {
1556 if (str_literal ==
nullptr) {
1557 throw std::runtime_error(
1558 "'raster_point_compute_angle' option must be a boolean.");
1563 }
else if (boost::iequals(*p->get_name(),
"sql_order_by")) {
1564 if (
auto str_literal = dynamic_cast<const StringLiteral*>(p->get_value())) {
1565 copy_params.
sql_order_by = *str_literal->get_stringval();
1567 throw std::runtime_error(
"Option sql_order_by must be a string.");
1569 }
else if (boost::iequals(*p->get_name(),
"username")) {
1572 if (str_literal ==
nullptr) {
1573 throw std::runtime_error(
"Option username must be a string.");
1577 }
else if (boost::iequals(*p->get_name(),
"password")) {
1580 if (str_literal ==
nullptr) {
1581 throw std::runtime_error(
"Option password must be a string.");
1585 }
else if (boost::iequals(*p->get_name(),
"credential_string")) {
1588 if (str_literal ==
nullptr) {
1589 throw std::runtime_error(
"Option credential_string must be a string.");
1593 }
else if (boost::iequals(*p->get_name(),
"data_source_name")) {
1596 if (str_literal ==
nullptr) {
1597 throw std::runtime_error(
"Option data_source_name must be a string.");
1600 copy_params.
dsn = string_val;
1601 }
else if (boost::iequals(*p->get_name(),
"connection_string")) {
1604 if (str_literal ==
nullptr) {
1605 throw std::runtime_error(
"Option connection_string must be a string.");
1609 }
else if (boost::iequals(*p->get_name(),
"line_start_regex")) {
1612 if (str_literal ==
nullptr) {
1613 throw std::runtime_error(
"Option line_start_regex must be a string.");
1617 }
else if (boost::iequals(*p->get_name(),
"line_regex")) {
1620 if (str_literal ==
nullptr) {
1621 throw std::runtime_error(
"Option line_regex must be a string.");
1625 }
else if (boost::iequals(*p->get_name(),
"add_metadata_columns") &&
1629 if (str_literal ==
nullptr) {
1630 throw std::runtime_error(
"'add_metadata_columns' option must be a string.");
1634 throw std::runtime_error(
"Invalid option for COPY: " + *p->get_name());
1645 if (array_expr && array_expr->isNull()) {
1654 std::shared_ptr<Analyzer::Expr> CaseExpr::normalize(
1655 const std::list<std::pair<std::shared_ptr<Analyzer::Expr>,
1656 std::shared_ptr<Analyzer::Expr>>>& expr_pair_list,
1657 const std::shared_ptr<Analyzer::Expr> else_e_in,
1658 const Executor* executor) {
1660 bool has_agg =
false;
1671 for (
auto& p : expr_pair_list) {
1673 CHECK(e1->get_type_info().is_boolean());
1675 if (e2->get_contains_agg()) {
1678 const auto& e2_ti = e2->get_type_info();
1680 if (e2_ti.is_string() && !e2_ti.is_dict_encoded_string() && !col_var) {
1681 CHECK(e2_ti.is_none_encoded_string());
1682 none_encoded_literal_ti =
1694 e2->set_type_info(ti);
1695 }
else if (ti != e2_ti) {
1696 if (ti.
is_string() && e2_ti.is_string()) {
1700 }
else if (ti.
is_number() && e2_ti.is_number()) {
1702 }
else if (ti.
is_boolean() && e2_ti.is_boolean()) {
1705 throw std::runtime_error(
1706 "Expressions in THEN clause must be of the same or compatible types.");
1710 auto else_e = else_e_in;
1711 const auto& else_ti = else_e->get_type_info();
1714 if (else_e->get_contains_agg()) {
1717 if (else_ti.is_string() && !else_ti.is_dict_encoded_string() && !col_var) {
1718 CHECK(else_ti.is_none_encoded_string());
1719 none_encoded_literal_ti =
1728 else_e->set_type_info(ti);
1729 }
else if (ti != else_ti) {
1731 if (ti.
is_string() && else_ti.is_string()) {
1735 }
else if (ti.
is_number() && else_ti.is_number()) {
1737 }
else if (ti.
is_boolean() && else_ti.is_boolean()) {
1740 throw std::runtime_error(
1742 "Expressions in ELSE clause must be of the same or compatible types as "
1743 "those in the THEN clauses.");
1757 std::list<std::pair<std::shared_ptr<Analyzer::Expr>, std::shared_ptr<Analyzer::Expr>>>
1758 cast_expr_pair_list;
1759 for (
auto p : expr_pair_list) {
1761 cast_expr_pair_list.emplace_back(p.first, p.second->add_cast(ti));
1763 if (else_e !=
nullptr) {
1764 else_e = else_e->add_cast(ti);
1769 else_e = makeExpr<Analyzer::Constant>(ti,
true, d);
1772 throw std::runtime_error(
1773 "Cannot deduce the type for case expressions, all branches null");
1776 auto case_expr = makeExpr<Analyzer::CaseExpr>(ti, has_agg, cast_expr_pair_list, else_e);
1781 std::string str(
"CASE ");
1782 for (
auto& p : when_then_list_) {
1783 str +=
"WHEN " + p->get_expr1()->to_string() +
" THEN " +
1784 p->get_expr2()->to_string() +
" ";
1786 if (else_expr_ !=
nullptr) {
1787 str +=
"ELSE " + else_expr_->to_string();
1795 left_->analyze(catalog, query);
1797 right_->analyze(catalog, *right_query);
1804 std::shared_ptr<Analyzer::Expr> p;
1805 if (having_clause_ !=
nullptr) {
1806 p = having_clause_->analyze(catalog, query, Expr::TlistRefType::TLIST_COPY);
1807 if (p->get_type_info().get_type() !=
kBOOLEAN) {
1808 throw std::runtime_error(
"Only boolean expressions can be in HAVING clause.");
1817 std::list<std::shared_ptr<Analyzer::Expr>> groupby;
1818 if (!groupby_clause_.empty()) {
1820 std::shared_ptr<Analyzer::Expr> gexpr;
1821 const std::vector<std::shared_ptr<Analyzer::TargetEntry>>& tlist =
1823 for (
auto& c : groupby_clause_) {
1825 if (dynamic_cast<Literal*>(c.get())) {
1828 throw std::runtime_error(
"Invalid literal in GROUP BY clause.");
1831 if (varno <= 0 || varno > static_cast<int>(tlist.size())) {
1832 throw std::runtime_error(
"Invalid ordinal number in GROUP BY clause.");
1834 if (tlist[varno - 1]->get_expr()->get_contains_agg()) {
1835 throw std::runtime_error(
1836 "Ordinal number in GROUP BY cannot reference an expression containing "
1840 gexpr = makeExpr<Analyzer::Var>(
1843 gexpr = c->analyze(catalog, query, Expr::TlistRefType::TLIST_REF);
1846 bool set_new_type =
false;
1849 set_new_type =
true;
1855 std::shared_ptr<Analyzer::Var> v;
1856 if (std::dynamic_pointer_cast<Analyzer::Var>(gexpr)) {
1858 int n = v->get_varno();
1859 gexpr = tlist[n - 1]->get_own_expr();
1861 if (cv !=
nullptr) {
1866 v->set_varno(gexpr_no);
1867 tlist[n - 1]->set_expr(v);
1871 groupby.push_back(new_e);
1873 v->set_type_info(new_e->get_type_info());
1876 groupby.push_back(gexpr);
1883 auto e = t->get_expr();
1884 e->check_group_by(groupby);
1892 if (where_clause_ ==
nullptr) {
1896 auto p = where_clause_->analyze(catalog, query, Expr::TlistRefType::TLIST_COPY);
1897 if (p->get_type_info().get_type() !=
kBOOLEAN) {
1898 throw std::runtime_error(
"Only boolean expressions can be in WHERE clause.");
1905 std::vector<std::shared_ptr<Analyzer::TargetEntry>>& tlist =
1907 if (select_clause_.empty()) {
1911 rte->expand_star_in_targetlist(catalog, tlist, rte_idx++);
1914 for (
auto& p : select_clause_) {
1915 const Parser::Expr* select_expr = p->get_select_expr();
1917 if (
typeid(*select_expr) ==
typeid(
ColumnRef) &&
1918 dynamic_cast<const ColumnRef*>(select_expr)->get_column() ==
nullptr) {
1919 const std::string* range_var_name =
1920 dynamic_cast<const ColumnRef*
>(select_expr)->get_table();
1923 throw std::runtime_error(
"invalid range variable name: " + *range_var_name);
1928 auto e = select_expr->
analyze(catalog, query);
1929 std::string resname;
1931 if (p->get_alias() !=
nullptr) {
1932 resname = *p->get_alias();
1933 }
else if (std::dynamic_pointer_cast<Analyzer::ColumnVar>(e) &&
1934 !std::dynamic_pointer_cast<Analyzer::Var>(e)) {
1941 if (e->get_type_info().get_type() ==
kNULLT) {
1942 throw std::runtime_error(
1943 "Untyped NULL in SELECT clause. Use CAST to specify a type.");
1946 bool unnest = (o !=
nullptr && o->get_optype() ==
kUNNEST);
1947 auto tle = std::make_shared<Analyzer::TargetEntry>(resname, e, unnest);
1948 tlist.push_back(tle);
1957 for (
auto& p : from_clause_) {
1960 if (table_desc ==
nullptr) {
1961 throw std::runtime_error(
"Table " + *p->get_table_name() +
" does not exist.");
1963 std::string range_var;
1964 if (p->get_range_var() ==
nullptr) {
1965 range_var = *p->get_table_name();
1967 range_var = *p->get_range_var();
1977 analyze_from_clause(catalog, query);
1978 analyze_select_clause(catalog, query);
1979 analyze_where_clause(catalog, query);
1980 analyze_group_by(catalog, query);
1981 analyze_having_clause(catalog, query);
1988 boost::replace_all(s,
"\\\\t",
"\t");
1989 boost::replace_all(s,
"\\t",
"\t");
1990 boost::replace_all(s,
"\\\\n",
"\n");
1991 boost::replace_all(s,
"\\n",
"\n");
1997 std::regex e1(
"(\\\\x[0-9A-Fa-f][0-9A-Fa-f])");
1998 while (std::regex_search(s, m, e1)) {
1999 std::string original(m[0].first, m[0].second);
2000 std::string replacement;
2001 long val = strtol(original.substr(2, 2).c_str(), NULL, 16);
2002 replacement.push_back(val);
2003 boost::replace_all(s, original, replacement);
2007 std::regex e2(
"(\\\\u[0-9A-Fa-f][0-9A-Fa-f][0-9A-Fa-f][0-9A-Fa-f])");
2008 while (std::regex_search(s, m, e2)) {
2009 std::string original(m[0].first, m[0].second);
2010 std::string replacement;
2011 long val = strtol(original.substr(2, 4).c_str(), NULL, 16);
2012 replacement.push_back(val);
2013 boost::replace_all(s, original, replacement);
2020 std::list<std::unique_ptr<NameValueAssign>>& nameValueList,
2021 bool stringToNull =
false,
2022 bool stringToInteger =
false) {
2023 if (payload.HasMember(
"options") && payload[
"options"].IsObject()) {
2024 const auto& options = payload[
"options"];
2025 for (
auto itr = options.MemberBegin(); itr != options.MemberEnd(); ++itr) {
2026 auto option_name = std::make_unique<std::string>(itr->name.GetString());
2027 std::unique_ptr<Literal> literal_value;
2028 if (itr->value.IsString()) {
2029 std::string str = itr->value.GetString();
2030 if (stringToNull && str ==
"") {
2031 literal_value = std::make_unique<NullLiteral>();
2032 }
else if (stringToInteger && std::all_of(str.begin(), str.end(), ::isdigit)) {
2033 int iVal = std::stoi(str);
2034 literal_value = std::make_unique<IntLiteral>(iVal);
2038 auto unique_literal_string = std::make_unique<std::string>(
unescape(str));
2040 std::make_unique<StringLiteral>(unique_literal_string.release());
2042 }
else if (itr->value.IsInt() || itr->value.IsInt64()) {
2043 literal_value = std::make_unique<IntLiteral>(
json_i64(itr->value));
2044 }
else if (itr->value.IsDouble()) {
2045 literal_value = std::make_unique<DoubleLiteral>(
json_double(itr->value));
2046 }
else if (itr->value.IsNull()) {
2047 literal_value = std::make_unique<NullLiteral>();
2049 throw std::runtime_error(
"Unable to handle literal for " + *option_name);
2051 CHECK(literal_value);
2053 nameValueList.emplace_back(std::make_unique<NameValueAssign>(
2054 option_name.release(), literal_value.release()));
2065 throw std::runtime_error(
"OFFSET cannot be negative.");
2068 query_expr_->analyze(catalog, query);
2073 const std::vector<std::shared_ptr<Analyzer::TargetEntry>>& tlist =
2075 std::list<Analyzer::OrderEntry>* order_by =
new std::list<Analyzer::OrderEntry>();
2076 if (!orderby_clause_.empty()) {
2077 for (
auto& p : orderby_clause_) {
2078 int tle_no = p->get_colno();
2082 const std::string*
name = p->get_column()->get_column();
2085 for (
auto tle : tlist) {
2086 if (tle->get_resname() == *
name) {
2093 throw std::runtime_error(
"invalid name in order by: " + *name);
2096 order_by->push_back(
2102 for (
int i = 1; i <= static_cast<int>(tlist.size()); i++) {
2103 bool in_orderby =
false;
2104 std::for_each(order_by->begin(),
2107 in_orderby = in_orderby || (i == oe.tle_no);
2118 std::string str = select_expr_->to_string();
2119 if (alias_ !=
nullptr) {
2120 str +=
" AS " + *alias_;
2126 std::string str = *table_name_;
2127 if (range_var_ !=
nullptr) {
2128 str +=
" " + *range_var_;
2135 if (table_ ==
nullptr) {
2137 }
else if (column_ ==
nullptr) {
2138 str = *table_ +
".*";
2140 str = *table_ +
"." + *column_;
2146 std::string op_str[] = {
2147 "=",
"===",
"<>",
"<",
">",
"<=",
">=",
" AND ",
" OR ",
"NOT",
"-",
"+",
"*",
"/"};
2150 str =
"-(" + left_->to_string() +
")";
2151 }
else if (optype_ ==
kNOT) {
2152 str =
"NOT (" + left_->to_string() +
")";
2154 str = left_->to_string() +
"[" + right_->to_string() +
"]";
2155 }
else if (optype_ ==
kUNNEST) {
2156 str =
"UNNEST(" + left_->to_string() +
")";
2157 }
else if (optype_ ==
kIN) {
2158 str =
"(" + left_->to_string() +
" IN " + right_->to_string() +
")";
2160 str =
"(" + left_->to_string() + op_str[optype_] + right_->to_string() +
")";
2166 std::string str = arg_->to_string();
2176 return "EXISTS (" + query_->to_string() +
")";
2182 str += query_->to_string();
2188 std::string str = arg_->to_string();
2190 str +=
" IS NOT NULL";
2199 str += subquery_->to_string();
2205 bool notfirst =
false;
2206 for (
auto& p : value_list_) {
2212 str += p->to_string();
2219 std::string str = arg_->to_string();
2221 str +=
" NOT BETWEEN ";
2225 str += lower_->to_string() +
" AND " + upper_->to_string();
2231 if (calc_encoded_length_) {
2232 str =
"CHAR_LENGTH (" + arg_->to_string() +
")";
2234 str =
"LENGTH (" + arg_->to_string() +
")";
2240 std::string str =
"CARDINALITY(" + arg_->to_string() +
")";
2245 std::string str = arg_->to_string();
2247 str +=
" NOT LIKE ";
2251 str += like_string_->to_string();
2252 if (escape_string_ !=
nullptr) {
2253 str +=
" ESCAPE " + escape_string_->to_string();
2259 std::string str = arg_->to_string();
2261 str +=
" NOT REGEXP ";
2265 str += pattern_string_->to_string();
2266 if (escape_string_ !=
nullptr) {
2267 str +=
" ESCAPE " + escape_string_->to_string();
2273 std::string str =
" WIDTH_BUCKET ";
2274 str += target_value_->to_string();
2276 str += lower_bound_->to_string();
2278 str += upper_bound_->to_string();
2280 str += partition_count_->to_string();
2286 std::string str =
" LIKELIHOOD ";
2287 str += arg_->to_string();
2289 str += boost::lexical_cast<std::string>(is_not_ ? 1.0 - likelihood_ : likelihood_);
2294 std::string str = *name_ +
"(";
2298 if (arg_ ==
nullptr) {
2301 str += arg_->to_string() +
")";
2307 std::string query_str =
"SELECT ";
2309 query_str +=
"DISTINCT ";
2311 if (select_clause_.empty()) {
2314 bool notfirst =
false;
2315 for (
auto& p : select_clause_) {
2321 query_str += p->to_string();
2324 query_str +=
" FROM ";
2325 bool notfirst =
false;
2326 for (
auto& p : from_clause_) {
2332 query_str += p->to_string();
2334 if (where_clause_) {
2335 query_str +=
" WHERE " + where_clause_->to_string();
2337 if (!groupby_clause_.empty()) {
2338 query_str +=
" GROUP BY ";
2339 bool notfirst =
false;
2340 for (
auto& p : groupby_clause_) {
2346 query_str += p->to_string();
2349 if (having_clause_) {
2350 query_str +=
" HAVING " + having_clause_->to_string();
2360 if (td ==
nullptr) {
2361 throw std::runtime_error(
"Table " + *table_ +
" does not exist.");
2364 throw std::runtime_error(
"Insert to views is not supported yet.");
2368 std::list<int> result_col_list;
2369 if (column_list_.empty()) {
2370 const std::list<const ColumnDescriptor*> all_cols =
2372 for (
auto cd : all_cols) {
2373 result_col_list.push_back(cd->columnId);
2376 for (
auto& c : column_list_) {
2378 if (cd ==
nullptr) {
2379 throw std::runtime_error(
"Column " + *c +
" does not exist.");
2381 result_col_list.push_back(cd->
columnId);
2383 if (col_ti.get_physical_cols() > 0) {
2385 for (
auto i = 1; i <= col_ti.get_physical_cols(); i++) {
2388 if (pcd ==
nullptr) {
2389 throw std::runtime_error(
"Column " + *c +
"'s metadata is incomplete.");
2391 result_col_list.push_back(pcd->
columnId);
2401 CHECK(literal.IsObject());
2402 CHECK(literal.HasMember(
"literal"));
2403 CHECK(literal.HasMember(
"type"));
2405 if (type ==
"NULL") {
2407 }
else if (type ==
"CHAR" || type ==
"BOOLEAN") {
2408 auto* val =
new std::string(
json_str(literal[
"literal"]));
2410 }
else if (type ==
"DECIMAL") {
2411 CHECK(literal.HasMember(
"scale"));
2412 CHECK(literal.HasMember(
"precision"));
2413 auto scale =
json_i64(literal[
"scale"]);
2414 auto precision =
json_i64(literal[
"precision"]);
2416 auto int_val = std::stol(
json_str(literal[
"literal"]));
2419 auto dbl_val = std::stod(
json_str(literal[
"literal"]));
2422 auto* val =
new std::string(
json_str(literal[
"literal"]));
2425 }
else if (type ==
"DOUBLE") {
2426 auto dbl_val = std::stod(
json_str(literal[
"literal"]));
2429 CHECK(
false) <<
"Unexpected calcite data type: " <<
type;
2435 CHECK(array.IsArray());
2436 auto json_elements = array.GetArray();
2437 auto* elements =
new std::list<Expr*>();
2438 for (
const auto& e : json_elements) {
2446 const rapidjson::Value& payload)
2448 CHECK(payload.HasMember(
"name"));
2449 table_ = std::make_unique<std::string>(
json_str(payload[
"name"]));
2451 if (payload.HasMember(
"columns")) {
2452 CHECK(payload[
"columns"].IsArray());
2453 for (
auto& column : payload[
"columns"].GetArray()) {
2455 column_list_.emplace_back(std::make_unique<std::string>(s));
2459 CHECK(payload.HasMember(
"values") && payload[
"values"].IsArray());
2460 auto tuples = payload[
"values"].GetArray();
2461 if (tuples.Empty()) {
2462 throw std::runtime_error(
"Values statement cannot be empty");
2465 int column_offset = 0;
2467 for (
const auto& json_tuple : tuples) {
2468 auto values_list = std::make_unique<ValuesList>();
2469 CHECK(json_tuple.IsArray());
2470 auto tuple = json_tuple.GetArray();
2472 for (
const auto& value : tuple) {
2473 CHECK(value.IsObject());
2474 if (value.HasMember(
"array")) {
2483 }
catch (std::out_of_range
const& e) {
2487 auto target_col_iter = cds.begin();
2488 std::advance(target_col_iter, column_offset);
2489 auto* cd = *target_col_iter;
2491 auto const col_identifier = td->tableName +
"." + cd->columnName;
2492 throw std::runtime_error(
2493 "Detected an out-of-range exception when inserting a value into column \"" +
2494 col_identifier +
"\"");
2501 size_t list_size =
values_lists_[0]->get_value_list().size();
2504 throw std::runtime_error(
2505 "Numbers of columns and values don't match for the "
2510 const std::list<const ColumnDescriptor*> non_phys_cols =
2512 if (non_phys_cols.size() != list_size) {
2513 throw std::runtime_error(
2514 "Number of columns in table does not match the list of values given in the "
2518 std::vector<const ColumnDescriptor*> cds;
2528 const auto& values_list =
values_lists_[i]->get_value_list();
2529 if (values_list.size() != list_size) {
2530 throw std::runtime_error(
2531 "Insert values lists should be of the same size. Expected: " +
2534 auto& query_values_list = query_values_lists[i];
2536 for (
auto& v : values_list) {
2537 auto e = v->analyze(catalog, query);
2538 const auto* cd = cds[cds_id];
2539 const auto& col_ti = cd->columnType;
2540 if (col_ti.get_notnull()) {
2542 if (c !=
nullptr && c->get_is_null()) {
2543 throw std::runtime_error(
"Cannot insert NULL into column " + cd->columnName);
2546 e = e->add_cast(col_ti);
2550 if (col_ti.get_physical_cols() > 0) {
2551 CHECK(cd->columnType.is_geometry());
2555 if (uoper && uoper->get_optype() ==
kCAST) {
2560 std::string* geo_string{
nullptr};
2562 is_null = c->get_is_null();
2564 geo_string = c->get_constval().stringval;
2567 if (!is_null && !geo_string) {
2568 throw std::runtime_error(
"Expecting a WKT or WKB hex string for column " +
2571 std::vector<double> coords;
2572 std::vector<double> bounds;
2573 std::vector<int> ring_sizes;
2574 std::vector<int> poly_rings;
2577 const bool validate_with_geos_if_available =
false;
2585 validate_with_geos_if_available)) {
2586 throw std::runtime_error(
"Cannot read geometry to insert into column " +
2589 if (coords.empty()) {
2594 throw std::runtime_error(
2595 "Imported geometry doesn't match the type of column " + cd->columnName);
2599 if (cd->columnType.get_type() ==
kPOINT) {
2600 if (!coords.empty()) {
2601 throw std::runtime_error(
2602 "NULL POINT with unexpected coordinates in column " + cd->columnName);
2612 const auto* cd_coords = cds[cds_id];
2615 std::list<std::shared_ptr<Analyzer::Expr>> value_exprs;
2616 if (!is_null || cd->columnType.get_type() ==
kPOINT) {
2618 for (
auto cc : compressed_coords) {
2621 auto e = makeExpr<Analyzer::Constant>(
kTINYINT,
false, d);
2622 value_exprs.push_back(e);
2627 makeExpr<Analyzer::Constant>(cd_coords->columnType, is_null, value_exprs),
2632 cd->columnType.get_type() ==
kPOLYGON ||
2635 const auto* cd_ring_sizes = cds[cds_id];
2636 CHECK(cd_ring_sizes);
2638 CHECK_EQ(cd_ring_sizes->columnType.get_subtype(),
kINT);
2639 std::list<std::shared_ptr<Analyzer::Expr>> value_exprs;
2641 for (
auto c : ring_sizes) {
2644 auto e = makeExpr<Analyzer::Constant>(
kINT,
false, d);
2645 value_exprs.push_back(e);
2650 makeExpr<Analyzer::Constant>(
2651 cd_ring_sizes->columnType, is_null, value_exprs),
2657 const auto* cd_poly_rings = cds[cds_id];
2658 CHECK(cd_poly_rings);
2660 CHECK_EQ(cd_poly_rings->columnType.get_subtype(),
kINT);
2661 std::list<std::shared_ptr<Analyzer::Expr>> value_exprs;
2663 for (
auto c : poly_rings) {
2666 auto e = makeExpr<Analyzer::Constant>(
kINT,
false, d);
2667 value_exprs.push_back(e);
2672 makeExpr<Analyzer::Constant>(
2673 cd_poly_rings->columnType, is_null, value_exprs),
2682 cd->columnType.get_type() ==
kPOLYGON ||
2684 const auto* cd_bounds = cds[cds_id];
2688 std::list<std::shared_ptr<Analyzer::Expr>> value_exprs;
2690 for (
auto b : bounds) {
2693 auto e = makeExpr<Analyzer::Constant>(
kDOUBLE,
false, d);
2694 value_exprs.push_back(e);
2699 makeExpr<Analyzer::Constant>(cd_bounds->columnType, is_null, value_exprs),
2709 bool read_only_mode) {
2710 if (read_only_mode) {
2711 throw std::runtime_error(
"INSERT values invalid in read only mode.");
2715 const auto td_with_lock =
2721 throw std::runtime_error(
"User has no insert privileges on " + *
table_ +
".");
2727 const auto insert_data_lock =
2733 auto td = td_with_lock();
2736 throw std::runtime_error(
"Singleton inserts on views is not supported.");
2744 leafs_connector_ = std::make_unique<Fragmenter_Namespace::LocalInsertConnector>();
2748 ra_executor.executeSimpleInsert(query, insert_data_loader, session);
2752 }
catch (std::exception& e) {
2753 LOG(
ERROR) <<
"An error occurred during insert rollback attempt. Table id: "
2754 << td->tableId <<
", Error: " << e.what();
2758 if (!td->isTemporaryTable()) {
2765 throw std::runtime_error(
"UPDATE statement not supported yet.");
2770 throw std::runtime_error(
"DELETE statement not supported yet.");
2777 if (!col_ti.is_integer() && !col_ti.is_time() &&
2778 !(col_ti.is_string() && col_ti.get_compression() ==
kENCODING_DICT)) {
2779 throw std::runtime_error(
"Cannot shard on type " + col_ti.get_type_name() +
2780 ", encoding " + col_ti.get_compression_name());
2785 const std::list<ColumnDescriptor>& columns) {
2787 for (
const auto& cd : columns) {
2788 if (cd.columnName == name) {
2793 if (cd.columnType.is_geometry()) {
2794 index += cd.columnType.get_physical_cols();
2802 const std::list<ColumnDescriptor>& columns) {
2804 for (
const auto& cd : columns) {
2805 if (boost::to_upper_copy<std::string>(cd.columnName) == name) {
2809 if (cd.columnType.is_geometry()) {
2810 index += cd.columnType.get_physical_cols();
2818 const std::string& field_name,
2819 const std::string& field_value,
2820 rapidjson::Document& document) {
2821 rapidjson::Value field_name_json_str;
2822 field_name_json_str.SetString(
2823 field_name.c_str(), field_name.size(), document.GetAllocator());
2824 rapidjson::Value field_value_json_str;
2825 field_value_json_str.SetString(
2826 field_value.c_str(), field_value.size(), document.GetAllocator());
2827 obj.AddMember(field_name_json_str, field_value_json_str, document.GetAllocator());
2832 const std::vector<SharedDictionaryDef>& shared_dict_defs) {
2833 rapidjson::Document document;
2834 auto& allocator = document.GetAllocator();
2835 rapidjson::Value arr(rapidjson::kArrayType);
2836 if (shard_key_def) {
2837 rapidjson::Value shard_key_obj(rapidjson::kObjectType);
2840 arr.PushBack(shard_key_obj, allocator);
2842 for (
const auto& shared_dict_def : shared_dict_defs) {
2843 rapidjson::Value shared_dict_obj(rapidjson::kObjectType);
2845 set_string_field(shared_dict_obj,
"name", shared_dict_def.get_column(), document);
2847 shared_dict_obj,
"foreign_table", shared_dict_def.get_foreign_table(), document);
2850 shared_dict_def.get_foreign_column(),
2852 arr.PushBack(shared_dict_obj, allocator);
2854 rapidjson::StringBuffer buffer;
2855 rapidjson::Writer<rapidjson::StringBuffer> writer(buffer);
2857 return buffer.GetString();
2860 template <
typename LITERAL_TYPE,
2861 typename ASSIGNMENT,
2865 VALIDATE validate = VALIDATE()) {
2866 const auto val = validate(p);
2873 auto assignment = [&td](
const auto val) { td.storageType = val; };
2874 return get_property_value<StringLiteral, decltype(assignment), CaseSensitiveValidate>(
2881 return get_property_value<IntLiteral>(p, [&td](
const auto val) {
2889 return get_property_value<IntLiteral>(
2890 p, [&df_td](
const auto val) { df_td.maxFragRows = val; });
2896 return get_property_value<IntLiteral>(p,
2897 [&td](
const auto val) { td.maxChunkSize = val; });
2904 return get_property_value<IntLiteral>(
2905 p, [&df_td](
const auto val) { df_td.maxChunkSize = val; });
2911 return get_property_value<StringLiteral>(p, [&df_td](
const auto val) {
2912 if (val.size() != 1) {
2913 throw std::runtime_error(
"Length of DELIMITER must be equal to 1.");
2915 df_td.delimiter = val;
2922 return get_property_value<StringLiteral>(p, [&df_td](
const auto val) {
2923 if (val ==
"FALSE") {
2924 df_td.hasHeader =
false;
2925 }
else if (val ==
"TRUE") {
2926 df_td.hasHeader =
true;
2928 throw std::runtime_error(
"Option HEADER support only 'true' or 'false' values.");
2936 return get_property_value<IntLiteral>(p,
2937 [&td](
const auto val) { td.fragPageSize = val; });
2942 return get_property_value<IntLiteral>(p, [&td](
const auto val) { td.maxRows = val; });
2948 return get_property_value<IntLiteral>(
2949 p, [&df_td](
const auto val) { df_td.skipRows = val; });
2955 return get_property_value<StringLiteral>(p, [&td](
const auto partitions_uc) {
2956 if (partitions_uc !=
"SHARDED" && partitions_uc !=
"REPLICATED") {
2957 throw std::runtime_error(
"PARTITIONS must be SHARDED or REPLICATED");
2959 if (td.shardedColumnId != 0 && partitions_uc ==
"REPLICATED") {
2960 throw std::runtime_error(
2961 "A table cannot be sharded and replicated at the same time");
2963 td.partitions = partitions_uc;
2969 if (!td.shardedColumnId) {
2970 throw std::runtime_error(
"SHARD KEY must be defined.");
2972 return get_property_value<IntLiteral>(p, [&td](
const auto shard_count) {
2974 throw std::runtime_error(
2975 "SHARD_COUNT must be a multiple of the number of leaves in the cluster.");
2977 td.nShards = g_leaf_count ? shard_count / g_leaf_count : shard_count;
2978 if (!td.shardedColumnId && !td.nShards) {
2979 throw std::runtime_error(
2980 "Must specify the number of shards through the SHARD_COUNT option");
2988 return get_property_value<StringLiteral>(p, [&td](
const auto vacuum_uc) {
2989 if (vacuum_uc !=
"IMMEDIATE" && vacuum_uc !=
"DELAYED") {
2990 throw std::runtime_error(
"VACUUM must be IMMEDIATE or DELAYED");
2992 td.hasDeletedCol = boost::iequals(vacuum_uc,
"IMMEDIATE") ?
false :
true;
2999 return get_property_value<StringLiteral>(p, [&td, &columns](
const auto sort_upper) {
3001 if (!td.sortedColumnId) {
3002 throw std::runtime_error(
"Specified sort column " + sort_upper +
" doesn't exist");
3010 auto assignment = [&td](
const auto val) {
3011 td.maxRollbackEpochs =
3016 return get_property_value<IntLiteral, decltype(assignment), PositiveOrZeroValidate>(
3033 const std::unique_ptr<NameValueAssign>& p,
3034 const std::list<ColumnDescriptor>& columns) {
3035 const auto it = tableDefFuncMap.find(boost::to_lower_copy<std::string>(*p->get_name()));
3036 if (it == tableDefFuncMap.end()) {
3037 throw std::runtime_error(
3038 "Invalid CREATE TABLE option " + *p->get_name() +
3039 ". Should be FRAGMENT_SIZE, MAX_CHUNK_SIZE, PAGE_SIZE, MAX_ROLLBACK_EPOCHS, "
3041 "PARTITIONS, SHARD_COUNT, VACUUM, SORT_COLUMN, STORAGE_TYPE.");
3043 return it->second(td, p.get(), columns);
3047 const std::unique_ptr<NameValueAssign>& p,
3048 const std::list<ColumnDescriptor>& columns) {
3049 const auto it = tableDefFuncMap.find(boost::to_lower_copy<std::string>(*p->get_name()));
3050 if (it == tableDefFuncMap.end()) {
3051 throw std::runtime_error(
3052 "Invalid CREATE TABLE AS option " + *p->get_name() +
3053 ". Should be FRAGMENT_SIZE, MAX_CHUNK_SIZE, PAGE_SIZE, MAX_ROLLBACK_EPOCHS, "
3055 "PARTITIONS, SHARD_COUNT, VACUUM, SORT_COLUMN, STORAGE_TYPE, "
3056 "USE_SHARED_DICTIONARIES or FORCE_GEO_COMPRESSION.");
3058 return it->second(td, p.get(), columns);
3069 const std::unique_ptr<NameValueAssign>& p,
3070 const std::list<ColumnDescriptor>& columns) {
3072 dataframeDefFuncMap.find(boost::to_lower_copy<std::string>(*p->get_name()));
3073 if (it == dataframeDefFuncMap.end()) {
3074 throw std::runtime_error(
3075 "Invalid CREATE DATAFRAME option " + *p->get_name() +
3076 ". Should be FRAGMENT_SIZE, MAX_CHUNK_SIZE, SKIP_ROWS, DELIMITER or HEADER.");
3078 return it->second(df_td, p.get(), columns);
3082 std::string element_name,
3083 std::string& table_name,
3084 std::list<std::unique_ptr<TableElement>>& table_element_list) {
3085 const auto elements = payload[element_name].GetArray();
3086 for (
const auto& element : elements) {
3087 CHECK(element.IsObject());
3088 CHECK(element.HasMember(
"type"));
3089 if (
json_str(element[
"type"]) ==
"SQL_COLUMN_DECLARATION") {
3091 table_element_list.emplace_back(std::move(col_def));
3092 }
else if (
json_str(element[
"type"]) ==
"SQL_COLUMN_CONSTRAINT") {
3093 CHECK(element.HasMember(
"name"));
3094 if (
json_str(element[
"name"]) ==
"SHARD_KEY") {
3095 CHECK(element.HasMember(
"columns"));
3096 CHECK(element[
"columns"].IsArray());
3097 const auto& columns = element[
"columns"].GetArray();
3098 if (columns.Size() != size_t(1)) {
3099 throw std::runtime_error(
"Only one shard column is currently supported.");
3101 auto shard_key_def = std::make_unique<ShardKeyDef>(
json_str(columns[0]));
3102 table_element_list.emplace_back(std::move(shard_key_def));
3103 }
else if (
json_str(element[
"name"]) ==
"SHARED_DICT") {
3104 CHECK(element.HasMember(
"columns"));
3105 CHECK(element[
"columns"].IsArray());
3106 const auto& columns = element[
"columns"].GetArray();
3107 if (columns.Size() != size_t(1)) {
3108 throw std::runtime_error(
3109 R
"(Only one column per shared dictionary entry is currently supported. Use multiple SHARED DICT statements to share dictionaries from multiple columns.)");
3111 CHECK(element.HasMember("references") && element[
"references"].IsObject());
3112 const auto& references = element[
"references"].GetObject();
3113 std::string references_table_name;
3114 if (references.HasMember(
"table")) {
3115 references_table_name =
json_str(references[
"table"]);
3117 references_table_name = table_name;
3119 CHECK(references.HasMember(
"column"));
3121 auto shared_dict_def = std::make_unique<SharedDictionaryDef>(
3122 json_str(columns[0]), references_table_name,
json_str(references[
"column"]));
3123 table_element_list.emplace_back(std::move(shared_dict_def));
3126 LOG(
FATAL) <<
"Unsupported type for SQL_COLUMN_CONSTRAINT: "
3130 LOG(
FATAL) <<
"Unsupported element type for CREATE TABLE: "
3131 << element[
"type"].GetString();
3138 CHECK(element.HasMember(
"name"));
3139 auto col_name = std::make_unique<std::string>(
json_str(element[
"name"]));
3140 CHECK(element.HasMember(
"sqltype"));
3146 if (element.HasMember(
"precision")) {
3147 precision =
json_i64(element[
"precision"]);
3149 if (element.HasMember(
"scale")) {
3150 scale =
json_i64(element[
"scale"]);
3153 std::optional<int64_t> array_size;
3154 if (element.HasMember(
"arraySize")) {
3156 array_size =
json_i64(element[
"arraySize"]);
3158 std::unique_ptr<SQLType> sql_type;
3159 if (element.HasMember(
"subtype")) {
3160 CHECK(element.HasMember(
"coordinateSystem"));
3163 std::make_unique<SQLType>(subtype_sql_types,
3164 static_cast<int>(sql_types),
3165 static_cast<int>(
json_i64(element[
"coordinateSystem"])),
3167 }
else if (precision > 0 && scale > 0) {
3168 sql_type = std::make_unique<SQLType>(sql_types,
3171 array_size.has_value(),
3172 array_size ? *array_size : -1);
3173 }
else if (precision > 0) {
3174 sql_type = std::make_unique<SQLType>(sql_types,
3177 array_size.has_value(),
3178 array_size ? *array_size : -1);
3180 sql_type = std::make_unique<SQLType>(sql_types,
3181 array_size.has_value(),
3182 array_size ? *array_size : -1);
3186 CHECK(element.HasMember(
"nullable"));
3187 const auto nullable =
json_bool(element[
"nullable"]);
3188 std::unique_ptr<ColumnConstraintDef> constraint_def;
3190 if (element.HasMember(
"default") && !element[
"default"].IsNull()) {
3191 std::string* defaultval =
new std::string(
json_str(element[
"default"]));
3192 boost::algorithm::trim_if(*defaultval, boost::is_any_of(
" \"'`"));
3196 constraint_def = std::make_unique<ColumnConstraintDef>(!nullable,
3200 std::unique_ptr<CompressDef> compress_def;
3201 if (element.HasMember(
"encodingType") && !element[
"encodingType"].IsNull()) {
3202 std::string encoding_type =
json_str(element[
"encodingType"]);
3203 CHECK(element.HasMember(
"encodingSize"));
3204 auto encoding_name = std::make_unique<std::string>(
json_str(element[
"encodingType"]));
3205 compress_def = std::make_unique<CompressDef>(encoding_name.release(),
3206 json_i64(element[
"encodingSize"]));
3208 return std::make_unique<ColumnDef>(col_name.release(),
3210 compress_def ? compress_def.release() :
nullptr,
3211 constraint_def ? constraint_def.release() :
nullptr);
3215 const rapidjson::Value& payload) {
3216 std::list<ColumnDef> table_element_list;
3217 CHECK(payload[payload_key].IsArray());
3219 const auto elements = payload[payload_key].GetArray();
3220 for (
const auto& element : elements) {
3221 CHECK(element.IsObject());
3222 CHECK(element.HasMember(
"type"));
3223 if (
json_str(element[
"type"]) ==
"SQL_COLUMN_DECLARATION") {
3225 table_element_list.emplace_back(std::move(*col_def));
3227 LOG(
FATAL) <<
"Unsupported element type for ALTER TABLE: "
3228 << element[
"type"].GetString();
3231 return table_element_list;
3235 CHECK(payload.HasMember(
"name"));
3236 table_ = std::make_unique<std::string>(
json_str(payload[
"name"]));
3237 CHECK(payload.HasMember(
"elements"));
3238 CHECK(payload[
"elements"].IsArray());
3241 if (payload.HasMember(
"temporary")) {
3246 if (payload.HasMember(
"ifNotExists")) {
3257 std::list<ColumnDescriptor>& columns,
3258 std::vector<SharedDictionaryDef>& shared_dict_defs) {
3259 std::unordered_set<std::string> uc_col_names;
3263 if (dynamic_cast<SharedDictionaryDef*>(e.get())) {
3266 this, shared_dict_def, columns, shared_dict_defs, catalog);
3267 shared_dict_defs.push_back(*shared_dict_def);
3270 if (dynamic_cast<ShardKeyDef*>(e.get())) {
3271 if (shard_key_def) {
3272 throw std::runtime_error(
"Specified more than one shard key");
3274 shard_key_def =
static_cast<const ShardKeyDef*
>(e.get());
3277 if (!dynamic_cast<ColumnDef*>(e.get())) {
3278 throw std::runtime_error(
"Table constraints are not supported yet.");
3285 columns.push_back(cd);
3290 if (shard_key_def) {
3293 throw std::runtime_error(
"Specified shard column " + shard_key_def->get_column() +
3308 throw std::runtime_error(
"SHARD_COUNT needs to be specified with SHARD_KEY.");
3314 bool read_only_mode) {
3315 if (read_only_mode) {
3316 throw std::runtime_error(
"CREATE TABLE invalid in read only mode.");
3328 throw std::runtime_error(
"Table " + *
table_ +
3329 " will not be created. User has no create privileges.");
3337 std::list<ColumnDescriptor> columns;
3338 std::vector<SharedDictionaryDef> shared_dict_defs;
3343 catalog.createShardedTable(td, columns, shared_dict_defs);
3346 SysCatalog::instance().createDBObject(
3351 CHECK(payload.HasMember(
"name"));
3352 table_ = std::make_unique<std::string>(
json_str(payload[
"name"]));
3354 CHECK(payload.HasMember(
"elementList"));
3357 CHECK(payload.HasMember(
"filePath"));
3358 std::string fs =
json_str(payload[
"filePath"]);
3360 boost::algorithm::trim_if(fs, boost::is_any_of(
" \"'`"));
3361 filename_ = std::make_unique<std::string>(fs);
3367 bool read_only_mode) {
3368 if (read_only_mode) {
3369 throw std::runtime_error(
"CREATE DATAFRAME invalid in read only mode.");
3378 throw std::runtime_error(
"Table " + *
table_ +
3379 " will not be created. User has no create privileges.");
3382 if (catalog.getMetadataForTable(*
table_) !=
nullptr) {
3383 throw std::runtime_error(
"Table " + *
table_ +
" already exists.");
3386 std::list<ColumnDescriptor> columns;
3387 std::vector<SharedDictionaryDef> shared_dict_defs;
3389 std::unordered_set<std::string> uc_col_names;
3391 if (dynamic_cast<SharedDictionaryDef*>(e.get())) {
3394 this, shared_dict_def, columns, shared_dict_defs, catalog);
3395 shared_dict_defs.push_back(*shared_dict_def);
3398 if (!dynamic_cast<ColumnDef*>(e.get())) {
3399 throw std::runtime_error(
"Table constraints are not supported yet.");
3404 const auto uc_col_name = boost::to_upper_copy<std::string>(cd.
columnName);
3405 const auto it_ok = uc_col_names.insert(uc_col_name);
3406 if (!it_ok.second) {
3407 throw std::runtime_error(
"Column '" + cd.
columnName +
"' defined more than once");
3410 columns.push_back(cd);
3432 catalog.createShardedTable(df_td, columns, shared_dict_defs);
3435 SysCatalog::instance().createDBObject(
3441 throw std::runtime_error(
"Cannot create model. ML functions are disabled.");
3443 CHECK(payload.HasMember(
"name"));
3444 const std::string model_type_str =
json_str(payload[
"type"]);
3448 if (payload.HasMember(
"replace")) {
3453 if (payload.HasMember(
"ifNotExists")) {
3457 CHECK(payload.HasMember(
"query"));
3459 std::regex newline_re(
"\\n");
3460 std::regex backtick_re(
"`");
3461 select_query_ = std::regex_replace(select_query_, newline_re,
" ");
3462 select_query_ = std::regex_replace(select_query_, backtick_re,
"");
3470 const std::vector<std::string>& features,
3471 const std::string& training_query,
3472 const double data_split_train_fraction,
3473 const double data_split_eval_fraction,
3474 const std::vector<int64_t>& feature_permutations) {
3476 rapidjson::Document doc;
3480 rapidjson::Value predicted_value;
3481 predicted_value.SetString(predicted.c_str(), predicted.length(), doc.GetAllocator());
3482 doc.AddMember(
"predicted", predicted_value, doc.GetAllocator());
3484 rapidjson::Value features_array(rapidjson::kArrayType);
3485 for (
const auto& feature : features) {
3486 rapidjson::Value feature_value;
3487 feature_value.SetString(feature.c_str(), feature.length(), doc.GetAllocator());
3488 features_array.PushBack(feature_value, doc.GetAllocator());
3490 doc.AddMember(
"features", features_array, doc.GetAllocator());
3492 rapidjson::Value training_query_value;
3493 training_query_value.SetString(
3494 training_query.c_str(), training_query.length(), doc.GetAllocator());
3495 doc.AddMember(
"training_query", training_query_value, doc.GetAllocator());
3497 rapidjson::Value data_split_train_fraction_key(
"data_split_train_fraction",
3498 doc.GetAllocator());
3500 rapidjson::Value data_split_train_fraction_value(data_split_train_fraction);
3503 data_split_train_fraction_key, data_split_train_fraction_value, doc.GetAllocator());
3505 rapidjson::Value data_split_eval_fraction_key(
"data_split_eval_fraction",
3506 doc.GetAllocator());
3508 rapidjson::Value data_split_eval_fraction_value(data_split_eval_fraction);
3511 data_split_eval_fraction_key, data_split_eval_fraction_value, doc.GetAllocator());
3513 rapidjson::Value feature_permutations_array(rapidjson::kArrayType);
3514 for (
const auto& feature_permutation : feature_permutations) {
3515 rapidjson::Value feature_permutation_value;
3516 feature_permutation_value.SetInt64(feature_permutation);
3517 feature_permutations_array.PushBack(feature_permutation_value, doc.GetAllocator());
3519 doc.AddMember(
"feature_permutations", feature_permutations_array, doc.GetAllocator());
3522 rapidjson::StringBuffer buffer;
3523 rapidjson::Writer<rapidjson::StringBuffer> writer(buffer);
3526 return buffer.GetString();
3537 std::ostringstream error_oss;
3539 throw std::runtime_error(error_oss.str());
3548 bool train_fraction_specified =
false;
3549 bool eval_fraction_specified =
false;
3551 const auto key = boost::to_lower_copy<std::string>(*p->get_name());
3552 if (key ==
"train_fraction" || key ==
"data_split_train_fraction") {
3553 if (train_fraction_specified) {
3554 throw std::runtime_error(
3555 "Error parsing DATA_SPLIT_TRAIN_FRACTION value. "
3556 "Expected only one value.");
3560 if (fp_literal !=
nullptr) {
3562 if (data_split_train_fraction_ <= 0.0 || data_split_train_fraction_ > 1.0) {
3563 throw std::runtime_error(
3564 "Error parsing DATA_SPLIT_TRAIN_FRACTION value. "
3565 "Expected value between 0.0 and 1.0.");
3568 throw std::runtime_error(
3569 "Error parsing DATA_SPLIT_TRAIN_FRACTION value. "
3570 "Expected floating point value betwen 0.0 and 1.0.");
3572 train_fraction_specified =
true;
3575 if (key ==
"eval_fraction" || key ==
"data_split_eval_fraction") {
3576 if (eval_fraction_specified) {
3577 throw std::runtime_error(
3578 "Error parsing DATA_SPLIT_EVAL_FRACTION value. "
3579 "Expected only one value.");
3583 if (fp_literal !=
nullptr) {
3585 if (data_split_eval_fraction_ < 0.0 || data_split_eval_fraction_ >= 1.0) {
3586 throw std::runtime_error(
3587 "Error parsing DATA_SPLIT_EVAL_FRACTION value. "
3588 "Expected value between 0.0 and 1.0.");
3591 throw std::runtime_error(
3592 "Error parsing DATA_SPLIT_EVAL_FRACTION value. "
3593 "Expected floating point value betwen 0.0 and 1.0.");
3595 eval_fraction_specified =
true;
3604 if (str_literal !=
nullptr) {
3606 << boost::to_lower_copy<std::string>(*str_literal->
get_stringval())
3611 if (int_literal !=
nullptr) {
3616 if (fp_literal !=
nullptr) {
3620 throw std::runtime_error(
"Error parsing value.");
3638 throw std::runtime_error(
3639 "Error parsing DATA_SPLIT_TRAIN_FRACTION and DATA_SPLIT_EVAL_FRACTION values. "
3640 "Expected sum of values to be less than or equal to 1.0.");
3644 const std::shared_ptr<Catalog_Namespace::SessionInfo> session_ptr) {
3649 auto validate_result = local_connector.
query(
3650 validate_query_state->createQueryStateProxy(),
select_query_, {},
true,
false);
3652 auto column_descriptors_for_model_create =
3655 std::vector<size_t> categorical_feature_idxs;
3656 std::vector<size_t> numeric_feature_idxs;
3657 bool numeric_feature_seen =
false;
3658 bool all_categorical_features_placed_first =
true;
3661 (model_has_predicted_var ? 1 : 0));
3662 bool is_predicted = model_has_predicted_var ?
true :
false;
3663 size_t feature_idx = 0;
3664 for (
auto& cd : column_descriptors_for_model_create) {
3667 if (cd.columnName.rfind(
"EXPR$", 0) == 0) {
3668 throw std::runtime_error(
3669 "All projected expressions (i.e. col * 2) that are not column references (i.e. "
3670 "col) must be aliased.");
3674 if (!cd.columnType.is_number()) {
3675 throw std::runtime_error(
3676 "Numeric predicted column expression should be first argument to CREATE "
3679 is_predicted =
false;
3681 if (cd.columnType.is_number()) {
3682 numeric_feature_idxs.emplace_back(feature_idx);
3683 numeric_feature_seen =
true;
3684 }
else if (cd.columnType.is_string()) {
3685 categorical_feature_idxs.emplace_back(feature_idx);
3686 if (numeric_feature_seen) {
3687 all_categorical_features_placed_first =
false;
3690 throw std::runtime_error(
"Feature column expression should be numeric or TEXT.");
3697 if (!all_categorical_features_placed_first) {
3698 std::ostringstream modified_query_oss;
3699 modified_query_oss <<
"SELECT ";
3700 if (model_has_predicted_var) {
3703 for (
auto categorical_feature_idx : categorical_feature_idxs) {
3707 for (
auto numeric_feature_idx : numeric_feature_idxs) {
3710 if (numeric_feature_idx != numeric_feature_idxs.back()) {
3711 modified_query_oss <<
", ";
3714 modified_query_oss <<
" FROM (" << modified_select_query <<
")";
3715 modified_select_query = modified_query_oss.str();
3719 std::ostringstream modified_query_oss;
3720 if (all_categorical_features_placed_first) {
3721 modified_query_oss <<
"SELECT * FROM (" << modified_select_query <<
")";
3723 modified_query_oss << modified_select_query;
3726 modified_select_query = modified_query_oss.str();
3728 return modified_select_query;
3740 auto session_copy = session;
3741 auto session_ptr = std::shared_ptr<Catalog_Namespace::SessionInfo>(
3742 &session_copy, boost::null_deleter());
3757 const auto model_metadata =
3769 options_oss_ <<
"model_metadata => '" << model_metadata <<
"'";
3775 std::ostringstream model_query_oss;
3776 model_query_oss <<
"SELECT * FROM TABLE(" << model_train_func <<
"(model_name=>'"
3777 <<
get_model_name() <<
"', data=>CURSOR(" << modified_select_query
3779 model_query_oss <<
", " << options_str;
3780 model_query_oss <<
"))";
3782 std::string wrapped_model_query = model_query_oss.str();
3786 local_connector.
query(
3787 query_state->createQueryStateProxy(), wrapped_model_query, {},
false);
3791 bool read_only_mode) {
3792 if (read_only_mode) {
3793 throw std::runtime_error(
"CREATE MODEL invalid in read only mode.");
3798 }
catch (std::exception& e) {
3799 std::ostringstream error_oss;
3810 auto get_error_substring = [](
const std::string& message) -> std::string {
3811 size_t colon_position = std::string::npos;
3812 for (
int i = 0; i < 3; ++i) {
3813 colon_position = message.find(
':', colon_position + 1);
3814 if (colon_position == std::string::npos) {
3819 if (colon_position + 2 >= message.length()) {
3822 return message.substr(colon_position + 2);
3825 const auto error_substr = get_error_substring(e.what());
3827 error_oss <<
"Could not create model " <<
model_name_ <<
". " << error_substr;
3828 throw std::runtime_error(error_oss.str());
3833 CHECK(payload.HasMember(
"modelName"));
3837 if (payload.HasMember(
"ifExists")) {
3843 bool read_only_mode) {
3844 if (read_only_mode) {
3845 throw std::runtime_error(
"DROP MODEL invalid in read only mode.");
3849 }
catch (std::runtime_error& e) {
3858 const std::string select_stmt,
3859 std::vector<TargetMetaInfo>& targets,
3860 bool validate_only =
false,
3861 std::vector<size_t> outer_fragment_indices = {},
3862 bool allow_interrupt =
false) {
3864 auto& catalog = session->getCatalog();
3868 const auto device_type = session->get_executor_device_type();
3872 auto calcite_mgr = catalog.getCalciteMgr();
3876 const auto calciteQueryParsingOption =
3877 calcite_mgr->getCalciteQueryParsingOption(
true,
false,
true,
false);
3878 const auto calciteOptimizationOption = calcite_mgr->getCalciteOptimizationOption(
3883 const auto query_ra = calcite_mgr
3884 ->process(query_state_proxy,
3886 calciteQueryParsingOption,
3887 calciteOptimizationOption)
3890 executor.get(), query_ra, query_state_proxy->shared_from_this());
3912 std::numeric_limits<size_t>::max(),
3914 outer_fragment_indices};
3923 result = ra_executor.executeRelAlgQuery(co, eo,
false,
false,
nullptr);
3924 targets =
result.getTargetsMeta();
3930 std::string& sql_query_string) {
3932 auto& catalog = session->getCatalog();
3936 const auto device_type = session->get_executor_device_type();
3940 auto calcite_mgr = catalog.getCalciteMgr();
3944 const auto calciteQueryParsingOption =
3945 calcite_mgr->getCalciteQueryParsingOption(
true,
false,
true,
false);
3946 const auto calciteOptimizationOption = calcite_mgr->getCalciteOptimizationOption(
3951 const auto query_ra = calcite_mgr
3952 ->process(query_state_proxy,
3954 calciteQueryParsingOption,
3955 calciteOptimizationOption)
3976 return ra_executor.getOuterFragmentCount(co, eo);
3980 std::string& sql_query_string,
3981 std::vector<size_t> outer_frag_indices,
3983 bool allow_interrupt) {
3985 std::string pg_shimmed_select_query =
pg_shim(sql_query_string);
3987 std::vector<TargetMetaInfo> target_metainfos;
3990 auto query_session = session ? session->get_session_id() :
"";
3992 if (allow_interrupt && !validate_only && !query_session.empty()) {
3993 executor->enrollQuerySession(query_session,
3995 query_submitted_time,
3997 QuerySessionStatus::QueryStatus::PENDING_EXECUTOR);
4011 std::string& sql_query_string,
4012 std::vector<size_t> outer_frag_indices,
4013 bool allow_interrupt) {
4015 query_state_proxy, sql_query_string, outer_frag_indices,
false, allow_interrupt);
4022 std::list<ColumnDescriptor> column_descriptors;
4023 std::list<ColumnDescriptor> column_descriptors_for_create;
4025 int rowid_suffix = 0;
4026 for (
const auto& target_metainfo : result.
targets_meta) {
4028 cd.
columnName = target_metainfo.get_resname();
4032 cd.
columnType = target_metainfo.get_physical_type_info();
4052 column_descriptors_for_create.push_back(cd_for_create);
4053 column_descriptors.push_back(cd);
4057 return column_descriptors_for_create;
4060 return column_descriptors;
4064 const rapidjson::Value& payload) {
4065 CHECK(payload.HasMember(
"name"));
4068 CHECK(payload.HasMember(
"query"));
4071 boost::replace_all(select_query_,
"\n",
" ");
4072 select_query_ =
"(" + select_query_ +
")";
4074 if (payload.HasMember(
"columns")) {
4075 CHECK(payload[
"columns"].IsArray());
4076 for (
auto& column : payload[
"columns"].GetArray()) {
4078 column_list_.emplace_back(std::unique_ptr<std::string>(
new std::string(s)));
4085 bool validate_table,
4088 auto& catalog = session->getCatalog();
4090 bool populate_table =
false;
4093 populate_table =
true;
4097 populate_table =
true;
4101 auto get_target_column_descriptors = [
this, &catalog](
const TableDescriptor* td) {
4102 std::vector<const ColumnDescriptor*> target_column_descriptors;
4104 auto list = catalog.getAllColumnMetadataForTable(td->
tableId,
false,
false,
false);
4105 target_column_descriptors = {std::begin(list), std::end(list)};
4109 if (cd ==
nullptr) {
4110 throw std::runtime_error(
"Column " + *c +
" does not exist.");
4112 target_column_descriptors.push_back(cd);
4116 return target_column_descriptors;
4121 if (validate_table) {
4124 throw std::runtime_error(
"Table " +
table_name_ +
" does not exist.");
4127 throw std::runtime_error(
"Insert to views is not supported yet.");
4133 throw std::runtime_error(
"User has no insert privileges on " +
table_name_ +
".");
4142 std::vector<const ColumnDescriptor*> target_column_descriptors =
4143 get_target_column_descriptors(td);
4145 if (source_column_descriptors.size() != target_column_descriptors.size()) {
4146 throw std::runtime_error(
"The number of source and target columns does not match.");
4149 for (
int i = 0; i < source_column_descriptors.size(); i++) {
4151 &(*std::next(source_column_descriptors.begin(), i));
4155 auto type_cannot_be_cast = [](
const auto& col_type) {
4156 return (col_type.is_time() || col_type.is_geometry() || col_type.is_array() ||
4157 col_type.is_boolean());
4160 if (type_cannot_be_cast(source_cd->
columnType) ||
4161 type_cannot_be_cast(target_cd->
columnType)) {
4162 throw std::runtime_error(
"Source '" + source_cd->
columnName +
" " +
4164 "' and target '" + target_cd->
columnName +
" " +
4166 "' column types do not match.");
4171 throw std::runtime_error(
"Source '" + source_cd->
columnName +
" " +
4173 "' and target '" + target_cd->
columnName +
" " +
4175 "' array column element types do not match.");
4180 throw std::runtime_error(
"Source '" + source_cd->
columnName +
" " +
4182 "' and target '" + target_cd->
columnName +
" " +
4184 "' column types do not match.");
4198 throw std::runtime_error(
"Source '" + source_cd->
columnName +
" " +
4200 "' and target '" + target_cd->
columnName +
" " +
4202 "' decimal columns scales do not match.");
4208 throw std::runtime_error(
"Source '" + source_cd->
columnName +
" " +
4210 "' and target '" + target_cd->
columnName +
" " +
4212 "' column types do not match.");
4216 throw std::runtime_error(
"Source '" + source_cd->
columnName +
" " +
4218 "' and target '" + target_cd->
columnName +
" " +
4220 "' columns string encodings do not match.");
4227 throw std::runtime_error(
"Source '" + source_cd->
columnName +
" " +
4229 "' and target '" + target_cd->
columnName +
" " +
4231 "' timestamp column precisions do not match.");
4240 throw std::runtime_error(
"Source '" + source_cd->
columnName +
" " +
4242 "' and target '" + target_cd->
columnName +
" " +
4244 "' column encoding sizes do not match.");
4249 if (!populate_table) {
4253 int64_t total_row_count = 0;
4254 int64_t total_source_query_time_ms = 0;
4255 int64_t total_target_value_translate_time_ms = 0;
4256 int64_t total_data_load_time_ms = 0;
4259 auto target_column_descriptors = get_target_column_descriptors(td);
4260 auto outer_frag_count =
4263 size_t outer_frag_end = outer_frag_count == 0 ? 1 : outer_frag_count;
4264 auto query_session = session ? session->get_session_id() :
"";
4266 std::string work_type_str = for_CTAS ?
"CTAS" :
"ITAS";
4268 for (
size_t outer_frag_idx = 0; outer_frag_idx < outer_frag_end; outer_frag_idx++) {
4269 std::vector<size_t> allowed_outer_fragment_indices;
4271 if (outer_frag_count) {
4272 allowed_outer_fragment_indices.push_back(outer_frag_idx);
4276 std::vector<AggregatedResult> query_results =
4279 allowed_outer_fragment_indices,
4281 total_source_query_time_ms +=
timer_stop(query_clock_begin);
4284 auto query_str =
"INSERT_DATA for " + work_type_str;
4289 executor->enrollQuerySession(query_session,
4293 QuerySessionStatus::QueryStatus::RUNNING_IMPORTER);
4300 executor->clearQuerySessionStatus(query_session,
start_time);
4304 for (
auto&
res : query_results) {
4306 throw std::runtime_error(
4307 "Query execution has been interrupted while performing " + work_type_str);
4309 auto& result_rows =
res.rs;
4311 const auto num_rows = result_rows->rowCount();
4313 if (0 == num_rows) {
4317 total_row_count += num_rows;
4322 const size_t rows_per_block =
4323 std::max(std::min(num_rows / leaf_count,
size_t(64 * 1024)),
size_t(1));
4325 std::vector<std::unique_ptr<TargetValueConverter>> value_converters;
4329 const int num_worker_threads = std::thread::hardware_concurrency();
4331 std::vector<size_t> thread_start_idx(num_worker_threads),
4332 thread_end_idx(num_worker_threads);
4333 bool can_go_parallel = !result_rows->isTruncated() && rows_per_block > 20000;
4335 std::atomic<size_t> crt_row_idx{0};
4337 auto do_work = [&result_rows, &value_converters, &crt_row_idx](
4339 const size_t block_end,
4340 const size_t num_cols,
4342 bool& stop_convert) {
4343 const auto result_row = result_rows->getRowAtNoTranslations(idx);
4344 if (!result_row.empty()) {
4345 size_t target_row = crt_row_idx.fetch_add(1);
4346 if (target_row >= block_end) {
4347 stop_convert =
true;
4350 for (
unsigned int col = 0; col < num_cols; col++) {
4351 const auto& mapd_variant = result_row[col];
4352 value_converters[col]->convertToColumnarFormat(target_row, &mapd_variant);
4357 auto convert_function = [&thread_start_idx,
4363 &do_work](
const int thread_id,
const size_t block_end) {
4364 const int num_cols = value_converters.size();
4365 const size_t start = thread_start_idx[
thread_id];
4366 const size_t end = thread_end_idx[
thread_id];
4368 bool stop_convert =
false;
4370 size_t local_idx = 0;
4371 for (idx = start; idx < end; ++idx, ++local_idx) {
4372 if (
UNLIKELY((local_idx & 0xFFFF) == 0 &&
4374 throw std::runtime_error(
4375 "Query execution has been interrupted while performing " +
4378 do_work(idx, block_end, num_cols, thread_id, stop_convert);
4384 for (idx = start; idx < end; ++idx) {
4385 do_work(idx, block_end, num_cols, thread_id, stop_convert);
4394 auto single_threaded_value_converter =
4395 [&crt_row_idx, &value_converters, &result_rows](
const size_t idx,
4396 const size_t block_end,
4397 const size_t num_cols,
4398 bool& stop_convert) {
4399 size_t target_row = crt_row_idx.fetch_add(1);
4400 if (target_row >= block_end) {
4401 stop_convert =
true;
4404 const auto result_row = result_rows->getNextRow(
false,
false);
4405 CHECK(!result_row.empty());
4406 for (
unsigned int col = 0; col < num_cols; col++) {
4407 const auto& mapd_variant = result_row[col];
4408 value_converters[col]->convertToColumnarFormat(target_row, &mapd_variant);
4412 auto single_threaded_convert_function = [&value_converters,
4418 &single_threaded_value_converter](
4420 const size_t block_end) {
4421 const int num_cols = value_converters.size();
4422 const size_t start = thread_start_idx[
thread_id];
4423 const size_t end = thread_end_idx[
thread_id];
4425 bool stop_convert =
false;
4427 size_t local_idx = 0;
4428 for (idx = start; idx < end; ++idx, ++local_idx) {
4429 if (
UNLIKELY((local_idx & 0xFFFF) == 0 &&
4431 throw std::runtime_error(
4432 "Query execution has been interrupted while performing " +
4435 single_threaded_value_converter(idx, block_end, num_cols, stop_convert);
4441 for (idx = start; idx < end; ++idx) {
4442 single_threaded_value_converter(idx, end, num_cols, stop_convert);
4451 if (can_go_parallel) {
4452 const size_t entry_count = result_rows->entryCount();
4456 stride = (entry_count + num_worker_threads - 1) / num_worker_threads;
4457 i < num_worker_threads && start_entry < entry_count;
4458 ++i, start_entry += stride) {
4459 const auto end_entry = std::min(start_entry + stride, entry_count);
4460 thread_start_idx[i] = start_entry;
4461 thread_end_idx[i] = end_entry;
4464 thread_start_idx[0] = 0;
4465 thread_end_idx[0] = result_rows->entryCount();
4468 for (
size_t block_start = 0; block_start < num_rows;
4469 block_start += rows_per_block) {
4470 const auto num_rows_this_itr = block_start + rows_per_block < num_rows
4472 : num_rows - block_start;
4474 value_converters.clear();
4476 for (
const auto targetDescriptor : target_column_descriptors) {
4477 auto sourceDataMetaInfo =
res.targets_meta[colNum++];
4483 targetDescriptor->columnType,
4484 !targetDescriptor->columnType.get_notnull(),
4485 result_rows->getRowSetMemOwner()->getLiteralStringDictProxy(),
4487 sourceDataMetaInfo.get_type_info().is_dict_encoded_string()
4488 ? executor->getStringDictionaryProxy(
4489 sourceDataMetaInfo.get_type_info().getStringDictKey(),
4490 result_rows->getRowSetMemOwner(),
4493 auto converter = factory.
create(param);
4494 value_converters.push_back(std::move(converter));
4498 if (can_go_parallel) {
4499 std::vector<std::future<void>> worker_threads;
4500 for (
int i = 0; i < num_worker_threads; ++i) {
4501 worker_threads.push_back(
4505 for (
auto& child : worker_threads) {
4508 for (
auto& child : worker_threads) {
4513 single_threaded_convert_function(0, num_rows_this_itr);
4517 auto finalizer_func =
4518 [](std::unique_ptr<TargetValueConverter>::pointer targetValueConverter) {
4519 targetValueConverter->finalizeDataBlocksForInsertData();
4522 std::vector<std::future<void>> worker_threads;
4523 for (
auto& converterPtr : value_converters) {
4524 worker_threads.push_back(
4528 for (
auto& child : worker_threads) {
4531 for (
auto& child : worker_threads) {
4536 insert_data.
databaseId = catalog.getCurrentDB().dbId;
4539 insert_data.
numRows = num_rows_this_itr;
4541 for (
int col_idx = 0; col_idx < target_column_descriptors.size(); col_idx++) {
4544 throw std::runtime_error(
4545 "Query execution has been interrupted while performing " +
4548 value_converters[col_idx]->addDataBlocksToInsertData(insert_data);
4550 total_target_value_translate_time_ms +=
timer_stop(translate_clock_begin);
4553 auto data_memory_holder =
4555 insertDataLoader.
insertData(*session, insert_data);
4556 total_data_load_time_ms +=
timer_stop(data_load_clock_begin);
4563 }
catch (std::exception& e) {
4564 LOG(
ERROR) <<
"An error occurred during ITAS rollback attempt. Table id: "
4565 << td->
tableId <<
", Error: " << e.what();
4570 int64_t total_time_ms = total_source_query_time_ms +
4571 total_target_value_translate_time_ms + total_data_load_time_ms;
4573 VLOG(1) <<
"CTAS/ITAS " << total_row_count <<
" rows loaded in " << total_time_ms
4574 <<
"ms (outer_frag_count=" << outer_frag_count
4575 <<
", query_time=" << total_source_query_time_ms
4576 <<
"ms, translation_time=" << total_target_value_translate_time_ms
4577 <<
"ms, data_load_time=" << total_data_load_time_ms
4580 if (!is_temporary) {
4587 const auto catalog = SysCatalog::instance().getCatalog(table[1]);
4589 const auto table_id = catalog->getTableId(table[0]);
4590 if (!table_id.has_value()) {
4591 throw std::runtime_error{
"Table \"" + table[0] +
4592 "\" does not exist in catalog: " + table[1] +
"."};
4594 return {catalog->getDatabaseId(), table_id.value()};
4598 const std::string& insert_table_db_name,
4599 const std::string& query_str,
4601 const std::optional<std::string>& insert_table_name = {}) {
4602 auto& sys_catalog = SysCatalog::instance();
4603 auto& calcite_mgr = sys_catalog.getCalciteMgr();
4604 const auto calciteQueryParsingOption =
4605 calcite_mgr.getCalciteQueryParsingOption(
true,
false,
true,
false);
4606 const auto calciteOptimizationOption = calcite_mgr.getCalciteOptimizationOption(
4608 const auto result = calcite_mgr.process(query_state_proxy,
4610 calciteQueryParsingOption,
4611 calciteOptimizationOption);
4614 auto comparator = [](
const std::vector<std::string>& table_1,
4615 const std::vector<std::string>& table_2) {
4618 std::set<std::vector<std::string>, decltype(comparator)>
tables(comparator);
4619 for (
auto& tab :
result.resolved_accessed_objects.tables_selected_from) {
4622 if (insert_table_name.has_value()) {
4624 std::vector<std::string>{insert_table_name.value(), insert_table_db_name});
4627 for (
const auto& table :
tables) {
4628 const auto catalog = sys_catalog.getCatalog(table[1]);
4633 *catalog, table[0])));
4634 if (insert_table_name.has_value() && table[0] == insert_table_name.value() &&
4635 table[1] == insert_table_db_name) {
4639 catalog->getDatabaseId(), (*locks.back())())));
4644 catalog->getDatabaseId(), (*locks.back())())));
4652 bool read_only_mode) {
4653 if (read_only_mode) {
4654 throw std::runtime_error(
"INSERT INTO TABLE invalid in read only mode.");
4656 auto session_copy = session;
4657 auto session_ptr = std::shared_ptr<Catalog_Namespace::SessionInfo>(
4658 &session_copy, boost::null_deleter());
4660 auto stdlog =
STDLOG(query_state);
4661 auto& catalog = session_ptr->getCatalog();
4665 if (catalog.getMetadataForTable(
table_name_) ==
nullptr) {
4666 throw std::runtime_error(
"ITAS failed: table " +
table_name_ +
" does not exist.");
4676 populateData(query_state->createQueryStateProxy(), td,
true,
false);
4684 if (payload.HasMember(
"temporary")) {
4690 if (payload.HasMember(
"ifNotExists")) {
4700 bool read_only_mode) {
4701 if (read_only_mode) {
4702 throw std::runtime_error(
"CREATE TABLE invalid in read only mode.");
4704 auto session_copy = session;
4705 auto session_ptr = std::shared_ptr<Catalog_Namespace::SessionInfo>(
4706 &session_copy, boost::null_deleter());
4708 auto stdlog =
STDLOG(query_state);
4713 std::set<std::string> select_tables;
4720 throw std::runtime_error(
"CTAS failed. Table " +
table_name_ +
4721 " will not be created. User has no create privileges.");
4724 if (catalog.getMetadataForTable(
table_name_) !=
nullptr) {
4729 " already exists and no data was loaded.");
4735 auto validate_result = local_connector.
query(
4736 query_state->createQueryStateProxy(),
select_query_, {},
true,
false);
4738 auto column_descriptors_for_create =
4742 for (
auto& cd : column_descriptors_for_create) {
4743 if (cd.columnType.is_decimal() &&
4745 throw std::runtime_error(cd.columnName +
": Precision too high, max " +
4754 td.
nColumns = column_descriptors_for_create.size();
4769 bool use_shared_dictionaries =
true;
4770 bool force_geo_compression =
true;
4774 if (boost::to_lower_copy<std::string>(*p->get_name()) ==
4775 "use_shared_dictionaries") {
4778 if (
nullptr == literal) {
4779 throw std::runtime_error(
4780 "USE_SHARED_DICTIONARIES must be a string parameter");
4782 std::string val = boost::to_lower_copy<std::string>(*literal->
get_stringval());
4783 use_shared_dictionaries = val ==
"true" || val ==
"1" || val ==
"t";
4784 }
else if (boost::to_lower_copy<std::string>(*p->get_name()) ==
4785 "force_geo_compression") {
4788 if (
nullptr == literal) {
4789 throw std::runtime_error(
"FORCE_GEO_COMPRESSION must be a string parameter");
4791 std::string val = boost::to_lower_copy<std::string>(*literal->
get_stringval());
4792 force_geo_compression = val ==
"true" || val ==
"1" || val ==
"t";
4799 std::vector<SharedDictionaryDef> sharedDictionaryRefs;
4801 if (use_shared_dictionaries) {
4802 const auto source_column_descriptors =
4804 const auto mapping = catalog.getDictionaryToColumnMapping();
4806 for (
auto& source_cd : source_column_descriptors) {
4807 const auto& ti = source_cd.columnType;
4808 if (ti.is_string()) {
4810 int dict_id = ti.get_comp_param();
4811 auto it = mapping.find(dict_id);
4812 if (mapping.end() != it) {
4813 const auto targetColumn = it->second;
4815 catalog.getMetadataForTable(targetColumn->tableId,
false);
4817 LOG(
INFO) <<
"CTAS: sharing text dictionary on column "
4818 << source_cd.columnName <<
" with " << targetTable->tableName
4819 <<
"." << targetColumn->columnName;
4820 sharedDictionaryRefs.emplace_back(
4821 source_cd.columnName, targetTable->tableName, targetColumn->columnName);
4828 if (force_geo_compression) {
4829 for (
auto& cd_for_create : column_descriptors_for_create) {
4830 auto& ti = cd_for_create.columnType;
4831 if (ti.is_geometry() && ti.get_output_srid() == 4326) {
4834 ti.set_comp_param(32);
4842 catalog.createTable(td, column_descriptors_for_create, sharedDictionaryRefs,
true);
4845 SysCatalog::instance().createDBObject(
4857 populateData(query_state->createQueryStateProxy(), td,
false,
true);
4862 catalog.dropTable(created_td);
4870 CHECK(payload.HasMember(
"tableName"));
4871 table_ = std::make_unique<std::string>(
json_str(payload[
"tableName"]));
4874 if (payload.HasMember(
"ifExists")) {
4875 if_exists_ =
json_bool(payload[
"ifExists"]);
4880 bool read_only_mode) {
4881 if (read_only_mode) {
4882 throw std::runtime_error(
"DROP TABLE invalid in read only mode.");
4890 std::unique_ptr<lockmgr::TableSchemaLockContainer<lockmgr::WriteLock>> td_with_lock;
4893 std::make_unique<lockmgr::TableSchemaLockContainer<lockmgr::WriteLock>>(
4895 catalog, *
table_,
false));
4896 td = (*td_with_lock)();
4897 }
catch (
const std::runtime_error& e) {
4906 CHECK(td_with_lock);
4911 throw std::runtime_error(
"Table " + *
table_ +
4912 " will not be dropped. User has no proper privileges.");
4918 auto table_data_read_lock =
4923 auto table_data_write_lock =
4925 catalog.dropTable(td);
4929 CHECK(payload.HasMember(
"tableName"));
4930 table_ = std::make_unique<std::string>(
json_str(payload[
"tableName"]));
4934 bool read_only_mode) {
4935 if (read_only_mode) {
4936 throw std::runtime_error(
"TRUNCATE TABLE invalid in read only mode.");
4940 const auto td_with_lock =
4943 const auto td = td_with_lock();
4945 throw std::runtime_error(
"Table " + *
table_ +
" does not exist.");
4949 std::vector<DBObject> privObjects;
4953 privObjects.push_back(dbObject);
4954 if (!SysCatalog::instance().checkPrivileges(session.
get_currentUser(), privObjects)) {
4955 throw std::runtime_error(
"Table " + *
table_ +
" will not be truncated. User " +
4957 " has no proper privileges.");
4961 throw std::runtime_error(*
table_ +
" is a view. Cannot Truncate.");
4967 auto table_data_read_lock =
4972 auto table_data_write_lock =
4974 catalog.truncateTable(td);
4978 CHECK(payload.HasMember(
"tableName"));
4979 table_ = std::make_unique<std::string>(
json_str(payload[
"tableName"]));
4989 std::vector<DBObject> privObjects;
4993 privObjects.push_back(dbObject);
4994 return SysCatalog::instance().checkPrivileges(session_info.
get_currentUser(),
5000 bool read_only_mode) {
5001 if (read_only_mode) {
5002 throw std::runtime_error(
"OPTIMIZE TABLE invalid in read only mode.");
5008 const auto td_with_lock =
5011 const auto td = td_with_lock();
5014 throw std::runtime_error(
"Table " + *
table_ +
" does not exist.");
5018 throw std::runtime_error(
"OPTIMIZE TABLE command is not supported on views.");
5032 bool repair_type(std::list<std::unique_ptr<NameValueAssign>>& options) {
5033 for (
const auto& opt : options) {
5034 if (boost::iequals(*opt->get_name(),
"REPAIR_TYPE")) {
5036 static_cast<const StringLiteral*
>(opt->get_value())->get_stringval();
5041 throw std::runtime_error(
"REPAIR_TYPE must be REMOVE.");
5044 throw std::runtime_error(
"The only VALIDATE WITH options is REPAIR_TYPE.");
5053 throw std::runtime_error(
"Validation Type is required for VALIDATE command.");
5055 std::list<std::unique_ptr<NameValueAssign>> options;
5057 for (
const auto e : *with_opts) {
5058 options.emplace_back(e);
5067 CHECK(payload.HasMember(
"type"));
5068 type_ = std::make_unique<std::string>(
json_str(payload[
"type"]));
5070 std::list<std::unique_ptr<NameValueAssign>> options;
5082 std::vector<DBObject> privObjects;
5086 privObjects.push_back(dbObject);
5087 if (!SysCatalog::instance().checkPrivileges(session.
get_currentUser(), privObjects)) {
5088 throw std::runtime_error(
"Current user does not have the privilege to alter table: " +
5094 CHECK(payload.HasMember(
"name"));
5096 CHECK(payload.HasMember(
"newName"));
5101 bool read_only_mode) {
5102 if (read_only_mode) {
5103 throw std::runtime_error(
"RENAME TABLE invalid in read only mode.");
5106 throw std::runtime_error(
"Only a super user can rename users.");
5110 if (!SysCatalog::instance().getMetadataForUser(*
username_, user)) {
5111 throw std::runtime_error(
"User " + *
username_ +
" does not exist.");
5118 CHECK(payload.HasMember(
"name"));
5120 CHECK(payload.HasMember(
"newName"));
5125 bool read_only_mode) {
5126 if (read_only_mode) {
5127 throw std::runtime_error(
"RENAME DATABASE invalid in read only mode.");
5134 if (!SysCatalog::instance().getMetadataForDB(*
database_name_, db)) {
5135 throw std::runtime_error(
"Database " + *
database_name_ +
" does not exist.");
5140 throw std::runtime_error(
"Only a super user or the owner can rename the database.");
5147 CHECK(payload.HasMember(
"tableNames"));
5148 CHECK(payload[
"tableNames"].IsArray());
5149 const auto elements = payload[
"tableNames"].GetArray();
5150 for (
const auto& element : elements) {
5151 CHECK(element.HasMember(
"name"));
5152 CHECK(element.HasMember(
"newName"));
5154 new std::string(
json_str(element[
"newName"])));
5163 std::list<std::pair<std::string, std::string>> tableNames) {
5164 for (
auto item : tableNames) {
5166 new std::string(item.second));
5181 std::time_t
result = std::time(
nullptr);
5186 sMap[oldName] = newName;
5191 std::string tableName) {
5192 if (sMap.find(tableName) != sMap.end()) {
5196 return sMap[tableName];
5201 sMap[tableName] = tableName;
5218 for (
auto it : sMap) {
5219 if ((it.second) !=
EMPTY_NAME && (it.first) != (it.second)) {
5220 throw std::runtime_error(
5221 "Error: Attempted to overwrite and lose data in table: \'" + (it.first) +
"\'");
5230 throw std::runtime_error(td->
tableName +
" is a foreign table. " +
5231 "Use ALTER FOREIGN TABLE.");
5237 bool read_only_mode) {
5238 if (read_only_mode) {
5239 throw std::runtime_error(
"RENAME TABLE invalid in read only mode.");
5247 std::vector<std::pair<std::string, std::string>> names;
5252 std::string curTableName = *(item.first);
5253 std::string newTableName = *(item.second);
5260 std::string altCurTableName =
loadTable(catalog, tableSubtituteMap, curTableName);
5261 std::string altNewTableName =
loadTable(catalog, tableSubtituteMap, newTableName);
5263 if (altCurTableName != curTableName && altCurTableName !=
EMPTY_NAME) {
5265 recordRename(tableSubtituteMap, curTableName, curTableName);
5276 if (
hasData(tableSubtituteMap, altCurTableName)) {
5277 const TableDescriptor* td = catalog.getMetadataForTable(altCurTableName);
5285 if (
hasData(tableSubtituteMap, altNewTableName)) {
5290 recordRename(tableSubtituteMap, altNewTableName, tmpNewTableName);
5291 recordRename(tableSubtituteMap, tmpNewTableName, tmpNewTableName);
5292 names.emplace_back(altNewTableName, tmpNewTableName);
5293 names.emplace_back(altCurTableName, altNewTableName);
5297 recordRename(tableSubtituteMap, altNewTableName, altNewTableName);
5298 names.emplace_back(altCurTableName, altNewTableName);
5301 throw std::runtime_error(
"Source table \'" + curTableName +
"\' does not exist.");
5306 catalog.renameTables(names);
5309 while (!tablesToRename_.empty()) {
5310 tablesToRename_.pop_front();
5317 if (cc ==
nullptr) {
5322 std::string default_value;
5323 const std::string* default_value_ptr =
nullptr;
5326 auto defaultsp =
dynamic_cast<const StringLiteral*
>(def_val_literal);
5328 defaultsp ? *defaultsp->
get_stringval() : def_val_literal->to_string();
5333 std::regex array_re(R
"(^ARRAY\s*\[(.*)\]$)", std::regex_constants::icase);
5334 default_value = std::regex_replace(default_value, array_re, "{$1}");
5335 boost::erase_all(default_value,
"\'");
5337 default_value_ptr = &default_value;
5356 throw std::runtime_error(
"Table " + *
table_ +
" does not exist.");
5359 throw std::runtime_error(
"Adding columns to a view is not supported.");
5363 throw std::runtime_error(
5364 "Adding columns to temporary tables is not yet supported.");
5374 for (
const auto& coldef :
coldefs_) {
5375 auto& new_column_name = *coldef->get_column_name();
5376 if (catalog.getMetadataForColumn(td->
tableId, new_column_name) !=
nullptr) {
5377 throw std::runtime_error(
"Column " + new_column_name +
" already exists.");
5383 bool read_only_mode) {
5384 if (read_only_mode) {
5385 throw std::runtime_error(
"ADD COLUMN invalid in read only mode.");
5390 const auto td_with_lock =
5393 const auto td = td_with_lock();
5398 if (std::dynamic_pointer_cast<Fragmenter_Namespace::SortedOrderFragmenter>(
5400 throw std::runtime_error(
5401 "Adding columns to a table is not supported when using the \"sort_column\" "
5412 catalog.getSqliteConnector().query(
"BEGIN TRANSACTION");
5414 std::map<const std::string, const ColumnDescriptor> cds;
5415 std::map<const int, const ColumnDef*> cid_coldefs;
5416 for (
const auto& coldef :
coldefs_) {
5419 catalog.addColumn(*td, cd);
5420 cds.emplace(*coldef->get_column_name(), cd);
5421 cid_coldefs.emplace(cd.
columnId, coldef.get());
5425 std::list<ColumnDescriptor> phy_geo_columns;
5426 catalog.expandGeoColumn(cd, phy_geo_columns);
5427 for (
auto& cd : phy_geo_columns) {
5428 catalog.addColumn(*td, cd);
5430 cid_coldefs.emplace(cd.
columnId,
nullptr);
5436 std::vector<std::unique_ptr<import_export::TypedImportBuffer>> import_buffers;
5437 for (
const auto& cd : cds) {
5438 import_buffers.emplace_back(std::make_unique<import_export::TypedImportBuffer>(
5439 &cd.second, loader->getStringDict(&cd.second)));
5441 loader->setAddingColumns(
true);
5445 import_buffers.end(),
5446 [](decltype(import_buffers[0])&
a, decltype(import_buffers[0])& b) {
5447 return a->getColumnDesc()->columnId < b->getColumnDesc()->columnId;
5453 const auto physical_tds = catalog.getPhysicalTablesDescriptors(td);
5455 std::for_each(physical_tds.begin(), physical_tds.end(), [&nrows](
const auto& td) {
5460 int skip_physical_cols = 0;
5461 for (
const auto cit : cid_coldefs) {
5462 const auto cd = catalog.getMetadataForColumn(td->
tableId, cit.first);
5463 const auto coldef = cit.second;
5464 const bool is_null = !cd->default_value.has_value();
5466 if (cd->columnType.get_notnull() &&
is_null) {
5467 throw std::runtime_error(
"Default value required for column " + cd->columnName +
5468 " because of NOT NULL constraint");
5471 for (
auto it = import_buffers.begin(); it < import_buffers.end(); ++it) {
5472 auto& import_buffer = *it;
5473 if (cd->columnId == import_buffer->getColumnDesc()->columnId) {
5474 if (coldef !=
nullptr ||
5475 skip_physical_cols-- <= 0) {
5476 import_buffer->add_value(cd,
5477 cd->default_value.value_or(
"NULL"),
5480 if (cd->columnType.is_geometry()) {
5481 std::vector<double> coords, bounds;
5482 std::vector<int> ring_sizes, poly_rings;
5484 const bool validate_with_geos_if_available =
false;
5486 cd->default_value.value_or(
"NULL"),
5492 validate_with_geos_if_available)) {
5493 throw std::runtime_error(
"Bad geometry data: '" +
5494 cd->default_value.value_or(
"NULL") +
"'");
5496 size_t col_idx = 1 + std::distance(import_buffers.begin(), it);
5506 skip_physical_cols = cd->columnType.get_physical_cols();
5515 if (!loader->loadNoCheckpoint(import_buffers, nrows, &session)) {
5516 throw std::runtime_error(
"loadNoCheckpoint failed!");
5518 catalog.rollLegacy(
true);
5519 catalog.resetTableEpochFloor(td->
tableId);
5520 loader->checkpoint();
5521 catalog.getSqliteConnector().query(
"END TRANSACTION");
5523 catalog.rollLegacy(
false);
5524 catalog.getSqliteConnector().query(
"ROLLBACK TRANSACTION");
5530 bool read_only_mode) {
5531 if (read_only_mode) {
5532 throw std::runtime_error(
"DROP COLUMN invalid in read only mode.");
5537 const auto td_with_lock =
5540 const auto td = td_with_lock();
5542 throw std::runtime_error(
"Table " + *
table_ +
" does not exist.");
5546 throw std::runtime_error(
"Dropping a column from a view is not supported.");
5549 throw std::runtime_error(
5550 "Dropping a column from a temporary table is not yet supported.");
5555 for (
const auto& column :
columns_) {
5556 if (
nullptr == catalog.getMetadataForColumn(td->
tableId, *column)) {
5557 throw std::runtime_error(
"Column " + *column +
" does not exist.");
5562 throw std::runtime_error(
"Table " + *
table_ +
" has only one column.");
5568 catalog.getSqliteConnector().query(
"BEGIN TRANSACTION");
5570 std::vector<int> columnIds;
5571 for (
const auto& column : columns_) {
5574 throw std::runtime_error(
"Dropping sharding column " + cd.
columnName +
5575 " is not supported.");
5577 catalog.dropColumn(*td, cd);
5580 const auto pcd = catalog.getMetadataForColumn(td->
tableId, cd.
columnId + i + 1);
5582 catalog.dropColumn(*td, *pcd);
5583 columnIds.push_back(cd.
columnId + i + 1);
5587 for (
auto shard : catalog.getPhysicalTablesDescriptors(td)) {
5588 shard->fragmenter->dropColumns(columnIds);
5592 throw std::runtime_error(
"lol!");
5594 catalog.rollLegacy(
true);
5596 catalog.resetTableEpochFloor(td->
tableId);
5597 catalog.checkpoint(td->
tableId);
5599 catalog.getSqliteConnector().query(
"END TRANSACTION");
5601 catalog.setForReload(td->
tableId);
5602 catalog.rollLegacy(
false);
5603 catalog.getSqliteConnector().query(
"ROLLBACK TRANSACTION");
5609 bool read_only_mode) {
5610 if (read_only_mode) {
5611 throw std::runtime_error(
"RENAME COLUMN invalid in read only mode.");
5617 const auto td_with_lock =
5619 catalog, *
table_,
false);
5620 const auto td = td_with_lock();
5626 if (cd ==
nullptr) {
5627 throw std::runtime_error(
"Column " + *
column_ +
" does not exist.");
5630 throw std::runtime_error(
"Column " + *
new_column_name_ +
" already exists.");
5636 bool read_only_mode) {
5637 if (read_only_mode) {
5638 throw std::runtime_error(
"ALTER TABLE invalid in read only mode.");
5640 enum TableParamType { MaxRollbackEpochs,
Epoch, MaxRows };
5641 static const std::unordered_map<std::string, TableParamType> param_map = {
5642 {
"max_rollback_epochs", TableParamType::MaxRollbackEpochs},
5643 {
"epoch", TableParamType::Epoch},
5644 {
"max_rows", TableParamType::MaxRows}};
5647 const auto td_with_lock =
5649 catalog, *
table_,
false);
5650 const auto td = td_with_lock();
5652 throw std::runtime_error(
"Table " + *
table_ +
" does not exist.");
5655 throw std::runtime_error(
"Setting parameters for a view is not supported.");
5658 throw std::runtime_error(
5659 "Setting parameters for a temporary table is not yet supported.");
5666 std::string param_name(*
param_->get_name());
5670 if (val_int_literal ==
nullptr) {
5671 throw std::runtime_error(
"Table parameters should be integers.");
5673 const int64_t param_val = val_int_literal->
get_intval();
5675 const auto param_it = param_map.find(param_name);
5676 if (param_it == param_map.end()) {
5677 throw std::runtime_error(param_name +
" is not a settable table parameter.");
5679 switch (param_it->second) {
5680 case MaxRollbackEpochs: {
5681 catalog.setMaxRollbackEpochs(td->
tableId, param_val);
5685 catalog.setTableEpoch(catalog.getDatabaseId(), td->
tableId, param_val);
5689 catalog.setMaxRows(td->
tableId, param_val);
5693 UNREACHABLE() <<
"Unexpected TableParamType value: " << param_it->second
5694 <<
", key: " << param_it->first;
5701 std::list<NameValueAssign*>* o)
5702 : table_(t), copy_from_source_pattern_(f), success_(
true) {
5704 for (
const auto e : *o) {
5712 CHECK(payload.HasMember(
"table"));
5713 table_ = std::make_unique<std::string>(
json_str(payload[
"table"]));
5715 CHECK(payload.HasMember(
"filePath"));
5716 std::string fs =
json_str(payload[
"filePath"]);
5718 boost::algorithm::trim_if(fs, boost::is_any_of(
" \"'`"));
5725 bool read_only_mode) {
5726 if (read_only_mode) {
5727 throw std::runtime_error(
"IMPORT invalid in read only mode.");
5731 const std::string& copy_from_source,
5733 -> std::unique_ptr<import_export::AbstractImporter> {
5736 return execute(session, read_only_mode, importer_factory);
5741 bool read_only_mode,
5742 const std::function<std::unique_ptr<import_export::AbstractImporter>(
5747 if (read_only_mode) {
5748 throw std::runtime_error(
"COPY FROM invalid in read only mode.");
5751 size_t total_time = 0;
5757 std::unique_ptr<lockmgr::TableSchemaLockContainer<lockmgr::ReadLock>> td_with_lock;
5758 std::unique_ptr<lockmgr::WriteLock> insert_data_lock;
5763 td_with_lock = std::make_unique<lockmgr::TableSchemaLockContainer<lockmgr::ReadLock>>(
5766 td = (*td_with_lock)();
5767 insert_data_lock = std::make_unique<lockmgr::WriteLock>(
5769 }
catch (
const std::runtime_error& e) {
5777 std::vector<DBObject> privObjects;
5781 privObjects.push_back(dbObject);
5782 if (!SysCatalog::instance().checkPrivileges(session.
get_currentUser(), privObjects)) {
5783 throw std::runtime_error(
"Violation of access privileges: user " +
5785 " has no insert privileges for table " + *
table_ +
".");
5793 std::vector<std::string> warnings;
5796 boost::regex non_local_file_regex{R
"(^\s*(s3|http|https)://.+)",
5797 boost::regex::extended | boost::regex::icase};
5812 throw std::runtime_error(
5813 "Option \"SQL ORDER BY\" must be specified when copying from an ODBC source.");
5819 for (
auto const& warning : warnings) {
5820 tr += warning +
"\n";
5836 tr += std::string(
"Appending geo to table '") + *
table_ + std::string(
"'...");
5838 tr += std::string(
"Creating table '") + *
table_ +
5839 std::string(
"' and importing geo...");
5843 CHECK(td_with_lock);
5846 auto importer = importer_factory(catalog, td, copy_from_source, copy_params);
5850 auto query_str =
"COPYING " + td->
tableName;
5852 executor->enrollQuerySession(query_session,
5856 QuerySessionStatus::QueryStatus::RUNNING_IMPORTER);
5860 [executor, &query_str, &query_session, &
start_time, &importer] {
5863 executor->clearQuerySessionStatus(query_session, start_time);
5873 LOG(
ERROR) <<
"COPY exited early due to reject records count during multi file "
5878 "COPY exited early due to reject records count during multi file "
5886 " recs in " +
std::to_string((
double)total_time / 1000.0) +
" secs");
5888 tr += std::string(
"Loader Failed due to : " + import_result.
load_msg +
" in " +
5892 throw std::runtime_error(
"Table '" + *
table_ +
"' must exist before COPY FROM");
5901 CHECK(payload.HasMember(
"role"));
5902 role_ = std::make_unique<std::string>(
json_str(payload[
"role"]));
5906 bool read_only_mode) {
5907 if (read_only_mode) {
5908 throw std::runtime_error(
"CREATE ROLE invalid in read only mode.");
5911 if (!currentUser.isSuper) {
5912 throw std::runtime_error(
"CREATE ROLE " +
get_role() +
5913 " failed. It can only be executed by super user.");
5915 SysCatalog::instance().createRole(
5921 CHECK(payload.HasMember(
"role"));
5922 role_ = std::make_unique<std::string>(
json_str(payload[
"role"]));
5925 if (payload.HasMember(
"ifExists")) {
5926 if_exists_ =
json_bool(payload[
"ifExists"]);
5931 bool read_only_mode) {
5932 if (read_only_mode) {
5933 throw std::runtime_error(
"DROP ROLE invalid in read only mode.");
5936 if (!currentUser.isSuper) {
5937 throw std::runtime_error(
"DROP ROLE " +
get_role() +
5938 " failed. It can only be executed by super user.");
5940 auto* rl = SysCatalog::instance().getRoleGrantee(
get_role());
5942 SysCatalog::instance().dropRole(
get_role(),
false);
5944 throw std::runtime_error(
"DROP ROLE " +
get_role() +
5945 " failed because role with this name does not exist.");
5950 std::vector<std::string> componentNames;
5951 boost::split(componentNames, hierName, boost::is_any_of(
"."));
5952 return componentNames;
5956 const std::string& objectType,
5958 std::string objectName;
5960 if (objectType.compare(
"DATABASE") == 0) {
5961 if (componentNames.size() == 1) {
5962 objectName = componentNames[0];
5964 throw std::runtime_error(
"DB object name is not correct " + objectHierName);
5967 if (objectType.compare(
"TABLE") == 0 || objectType.compare(
"DASHBOARD") == 0 ||
5968 objectType.compare(
"VIEW") == 0 || objectType.compare(
"SERVER") == 0) {
5969 switch (componentNames.size()) {
5971 objectName = componentNames[0];
5975 objectName = componentNames[1];
5979 throw std::runtime_error(
"DB object name is not correct " + objectHierName);
5983 throw std::runtime_error(
"DB object type " + objectType +
" is not supported.");
5990 const std::string& privs,
5992 const std::string& object_name) {
5993 static const std::map<std::pair<const std::string, const DBObjectType>,
5994 std::pair<const AccessPrivileges, const DBObjectType>>
6084 auto result = privileges_lookup.find(std::make_pair(privs, objectType));
6085 if (
result == privileges_lookup.end()) {
6086 throw std::runtime_error(
"Privileges " + privs +
" on DB object " + object_name +
6087 " are not correct.");
6094 int32_t dashboard_id = -1;
6095 if (!objectName.empty()) {
6097 dashboard_id = stoi(objectName);
6098 }
catch (
const std::exception&) {
6099 throw std::runtime_error(
6100 "Privileges on dashboards should be changed via integer dashboard ID");
6103 return DBObject(dashboard_id, objectType);
6105 return DBObject(objectName, objectType);
6112 const std::string& objectName,
6114 const std::string& command) {
6119 throw std::runtime_error(command +
" failed. Object '" + objectName +
"' of type " +
6125 if (!td || !td->
isView) {
6127 throw std::runtime_error(command +
" failed. Object '" + objectName +
"' of type " +
6135 CHECK(payload.HasMember(
"type"));
6136 type_ = std::make_unique<std::string>(
json_str(payload[
"type"]));
6138 CHECK(payload.HasMember(
"target"));
6141 if (payload.HasMember(
"privileges")) {
6142 CHECK(payload[
"privileges"].IsArray());
6143 for (
auto& privilege : payload[
"privileges"].GetArray()) {
6147 boost::algorithm::trim_if(r, boost::is_any_of(
" \"'`"));
6151 if (payload.HasMember(
"grantees")) {
6152 CHECK(payload[
"grantees"].IsArray());
6153 for (
auto& grantee : payload[
"grantees"].GetArray()) {
6161 bool read_only_mode) {
6162 if (read_only_mode) {
6163 throw std::runtime_error(
"GRANT invalid in read only mode.");
6167 const auto parserObjectType = boost::to_upper_copy<std::string>(
get_object_type());
6168 const auto objectName =
6172 throw std::runtime_error(
"GRANT failed. SERVER object unrecognized.");
6175 verifyObject(catalog, objectName, objectType,
"GRANT");
6179 if (!currentUser.isSuper) {
6180 if (!SysCatalog::instance().verifyDBObjectOwnership(currentUser, dbObject, catalog)) {
6181 throw std::runtime_error(
6182 "GRANT failed. It can only be executed by super user or owner of the "
6187 std::vector<DBObject> objects(
get_privs().size(), dbObject);
6188 for (
size_t i = 0; i <
get_privs().size(); ++i) {
6191 objects[i].setPrivileges(priv.first);
6192 objects[i].setPermissionType(priv.second);
6194 throw std::runtime_error(
"GRANT failed. SERVER object unrecognized.");
6197 SysCatalog::instance().grantDBObjectPrivilegesBatch(
grantees_, objects, catalog);
6202 CHECK(payload.HasMember(
"type"));
6203 type_ = std::make_unique<std::string>(
json_str(payload[
"type"]));
6205 CHECK(payload.HasMember(
"target"));
6208 if (payload.HasMember(
"privileges")) {
6209 CHECK(payload[
"privileges"].IsArray());
6210 for (
auto& privilege : payload[
"privileges"].GetArray()) {
6214 boost::algorithm::trim_if(r, boost::is_any_of(
" \"'`"));
6218 if (payload.HasMember(
"grantees")) {
6219 CHECK(payload[
"grantees"].IsArray());
6220 for (
auto& grantee : payload[
"grantees"].GetArray()) {
6228 bool read_only_mode) {
6229 if (read_only_mode) {
6230 throw std::runtime_error(
"REVOKE invalid in read only mode.");
6234 const auto parserObjectType = boost::to_upper_copy<std::string>(
get_object_type());
6235 const auto objectName =
6239 throw std::runtime_error(
"REVOKE failed. SERVER object unrecognized.");
6242 verifyObject(catalog, objectName, objectType,
"REVOKE");
6246 if (!currentUser.isSuper) {
6247 if (!SysCatalog::instance().verifyDBObjectOwnership(currentUser, dbObject, catalog)) {
6248 throw std::runtime_error(
6249 "REVOKE failed. It can only be executed by super user or owner of the "
6254 std::vector<DBObject> objects(
get_privs().size(), dbObject);
6255 for (
size_t i = 0; i <
get_privs().size(); ++i) {
6258 objects[i].setPrivileges(priv.first);
6259 objects[i].setPermissionType(priv.second);
6261 throw std::runtime_error(
"REVOKE failed. SERVER object unrecognized.");
6264 SysCatalog::instance().revokeDBObjectPrivilegesBatch(
grantees_, objects, catalog);
6270 bool read_only_mode) {
6275 const auto parserObjectType = boost::to_upper_copy<std::string>(
get_object_type());
6276 const auto objectName =
6284 if (!currentUser.isSuper) {
6285 if (!SysCatalog::instance().verifyDBObjectOwnership(currentUser, dbObject, catalog)) {
6286 throw std::runtime_error(
6288 " failed. It can only be executed by super user or owner of the object.");
6292 SysCatalog::instance().getDBObjectPrivileges(
get_role(), dbObject, catalog);
6294 printf(
"\nPRIVILEGES ON %s FOR %s ARE SET AS FOLLOWING: ",
6325 printf(
" TRUNCATE");
6368 if (payload.HasMember(
"roles")) {
6369 CHECK(payload[
"roles"].IsArray());
6370 for (
auto& role : payload[
"roles"].GetArray()) {
6375 if (payload.HasMember(
"grantees")) {
6376 CHECK(payload[
"grantees"].IsArray());
6377 for (
auto& grantee : payload[
"grantees"].GetArray()) {
6385 bool read_only_mode) {
6386 if (read_only_mode) {
6387 throw std::runtime_error(
"GRANT ROLE invalid in read only mode.");
6390 if (!currentUser.isSuper) {
6391 throw std::runtime_error(
6392 "GRANT failed, because it can only be executed by super user.");
6396 throw std::runtime_error(
6397 "Request to grant role failed because mapd root user has all privileges by "
6405 if (payload.HasMember(
"roles")) {
6406 CHECK(payload[
"roles"].IsArray());
6407 for (
auto& role : payload[
"roles"].GetArray()) {
6412 if (payload.HasMember(
"grantees")) {
6413 CHECK(payload[
"grantees"].IsArray());
6414 for (
auto& grantee : payload[
"grantees"].GetArray()) {
6422 bool read_only_mode) {
6423 if (read_only_mode) {
6424 throw std::runtime_error(
"REVOKE ROLE invalid in read only mode.");
6427 if (!currentUser.isSuper) {
6428 throw std::runtime_error(
6429 "REVOKE failed, because it can only be executed by super user.");
6433 throw std::runtime_error(
6434 "Request to revoke role failed because privileges can not be revoked from "
6441 CHECK(payload.HasMember(
"filePath"));
6444 CHECK(payload.HasMember(
"query"));
6447 if ((*select_stmt_).back() !=
';') {
6448 (*select_stmt_).push_back(
';');
6451 boost::replace_all((*select_stmt_),
"`",
"");
6457 bool read_only_mode) {
6459 auto session_copy = session;
6460 auto session_ptr = std::shared_ptr<Catalog_Namespace::SessionInfo>(
6461 &session_copy, boost::null_deleter());
6463 auto stdlog =
STDLOG(query_state);
6474 std::string layer_name;
6480 parseOptions(copy_params, file_type, layer_name, file_compression, array_null_handling);
6483 throw std::runtime_error(
"Invalid file path for COPY TO");
6484 }
else if (!boost::filesystem::path(*file_path_).is_absolute()) {
6485 std::string file_name = boost::filesystem::path(*file_path_).filename().string();
6488 if (!boost::filesystem::exists(file_dir)) {
6489 if (!boost::filesystem::create_directories(file_dir)) {
6490 throw std::runtime_error(
"Directory " + file_dir +
" cannot be created.");
6503 session_ptr->getCatalog().name(), *
select_stmt_, query_state_proxy);
6507 auto column_info_result =
6514 if (layer_name.size() == 0) {
6515 layer_name = boost::filesystem::path(*file_path_).stem().string();
6522 column_info_result.targets_meta,
6524 array_null_handling);
6527 size_t outer_frag_count =
6529 size_t outer_frag_end = outer_frag_count == 0 ? 1 : outer_frag_count;
6532 for (
size_t outer_frag_idx = 0; outer_frag_idx < outer_frag_end; outer_frag_idx++) {
6534 std::vector<size_t> allowed_outer_fragment_indices;
6535 if (outer_frag_count) {
6536 allowed_outer_fragment_indices.push_back(outer_frag_idx);
6541 query_state_proxy, *
select_stmt_, allowed_outer_fragment_indices,
false);
6544 query_exporter->exportResults(query_results);
6548 query_exporter->endExport();
6554 std::string& layer_name,
6564 if (boost::iequals(*p->get_name(),
"delimiter")) {
6567 if (str_literal ==
nullptr) {
6568 throw std::runtime_error(
"Delimiter option must be a string.");
6570 throw std::runtime_error(
"Delimiter must be a single character string.");
6573 }
else if (boost::iequals(*p->get_name(),
"nulls")) {
6576 if (str_literal ==
nullptr) {
6577 throw std::runtime_error(
"Nulls option must be a string.");
6580 }
else if (boost::iequals(*p->get_name(),
"header")) {
6583 if (str_literal ==
nullptr) {
6584 throw std::runtime_error(
"Header option must be a boolean.");
6589 }
else if (boost::iequals(*p->get_name(),
"quote")) {
6592 if (str_literal ==
nullptr) {
6593 throw std::runtime_error(
"Quote option must be a string.");
6595 throw std::runtime_error(
"Quote must be a single character string.");
6598 }
else if (boost::iequals(*p->get_name(),
"escape")) {
6601 if (str_literal ==
nullptr) {
6602 throw std::runtime_error(
"Escape option must be a string.");
6604 throw std::runtime_error(
"Escape must be a single character string.");
6607 }
else if (boost::iequals(*p->get_name(),
"line_delimiter")) {
6610 if (str_literal ==
nullptr) {
6611 throw std::runtime_error(
"Line_delimiter option must be a string.");
6613 throw std::runtime_error(
"Line_delimiter must be a single character string.");
6616 }
else if (boost::iequals(*p->get_name(),
"quoted")) {
6619 if (str_literal ==
nullptr) {
6620 throw std::runtime_error(
"Quoted option must be a boolean.");
6623 }
else if (boost::iequals(*p->get_name(),
"file_type")) {
6626 if (str_literal ==
nullptr) {
6627 throw std::runtime_error(
"File Type option must be a string.");
6629 auto file_type_str =
6630 boost::algorithm::to_lower_copy(*str_literal->
get_stringval());
6631 if (file_type_str ==
"csv") {
6633 }
else if (file_type_str ==
"geojson") {
6635 }
else if (file_type_str ==
"geojsonl") {
6637 }
else if (file_type_str ==
"shapefile") {
6639 }
else if (file_type_str ==
"flatgeobuf") {
6642 throw std::runtime_error(
6643 "File Type option must be 'CSV', 'GeoJSON', 'GeoJSONL', "
6644 "'Shapefile', or 'FlatGeobuf'");
6646 }
else if (boost::iequals(*p->get_name(),
"layer_name")) {
6649 if (str_literal ==
nullptr) {
6650 throw std::runtime_error(
"Layer Name option must be a string.");
6653 }
else if (boost::iequals(*p->get_name(),
"file_compression")) {
6656 if (str_literal ==
nullptr) {
6657 throw std::runtime_error(
"File Compression option must be a string.");
6659 auto file_compression_str =
6660 boost::algorithm::to_lower_copy(*str_literal->
get_stringval());
6661 if (file_compression_str ==
"none") {
6663 }
else if (file_compression_str ==
"gzip") {
6665 }
else if (file_compression_str ==
"zip") {
6668 throw std::runtime_error(
6669 "File Compression option must be 'None', 'GZip', or 'Zip'");
6671 }
else if (boost::iequals(*p->get_name(),
"array_null_handling")) {
6674 if (str_literal ==
nullptr) {
6675 throw std::runtime_error(
"Array Null Handling option must be a string.");
6677 auto array_null_handling_str =
6678 boost::algorithm::to_lower_copy(*str_literal->
get_stringval());
6679 if (array_null_handling_str ==
"abort") {
6680 array_null_handling =
6682 }
else if (array_null_handling_str ==
"raw") {
6683 array_null_handling =
6685 }
else if (array_null_handling_str ==
"zero") {
6686 array_null_handling =
6688 }
else if (array_null_handling_str ==
"nullfield") {
6689 array_null_handling =
6692 throw std::runtime_error(
6693 "Array Null Handling option must be 'Abort', 'Raw', 'Zero', or "
6697 throw std::runtime_error(
"Invalid option for COPY: " + *p->get_name());
6704 CHECK(payload.HasMember(
"name"));
6708 if (payload.HasMember(
"ifNotExists")) {
6712 CHECK(payload.HasMember(
"query"));
6714 std::regex newline_re(
"\\n");
6715 select_query_ = std::regex_replace(select_query_, newline_re,
" ");
6717 if (select_query_.back() !=
';') {
6718 select_query_.push_back(
';');
6723 bool read_only_mode) {
6724 if (read_only_mode) {
6725 throw std::runtime_error(
"CREATE VIEW invalid in read only mode.");
6727 auto session_copy = session;
6728 auto session_ptr = std::shared_ptr<Catalog_Namespace::SessionInfo>(
6729 &session_copy, boost::null_deleter());
6731 auto stdlog =
STDLOG(query_state);
6739 throw std::runtime_error(
"View " +
view_name_ +
6740 " will not be created. User has no create view privileges.");
6744 auto calcite_mgr = catalog.getCalciteMgr();
6747 const auto calciteQueryParsingOption =
6748 calcite_mgr->getCalciteQueryParsingOption(
true,
false,
true,
false);
6749 const auto calciteOptimizationOption = calcite_mgr->getCalciteOptimizationOption(
6751 calcite_mgr->process(query_state->createQueryStateProxy(),
6753 calciteQueryParsingOption,
6754 calciteOptimizationOption);
6764 td.
viewSQL = query_after_shim;
6773 catalog.createTable(td, {}, {},
true);
6777 SysCatalog::instance().createDBObject(
6782 CHECK(payload.HasMember(
"viewName"));
6786 if (payload.HasMember(
"ifExists")) {
6787 if_exists_ =
json_bool(payload[
"ifExists"]);
6792 bool read_only_mode) {
6793 if (read_only_mode) {
6794 throw std::runtime_error(
"DROP VIEW invalid in read only mode.");
6801 std::unique_ptr<lockmgr::TableSchemaLockContainer<lockmgr::WriteLock>> td_with_lock;
6805 std::make_unique<lockmgr::TableSchemaLockContainer<lockmgr::WriteLock>>(
6808 td = (*td_with_lock)();
6809 }
catch (
const std::runtime_error& e) {
6818 CHECK(td_with_lock);
6822 throw std::runtime_error(
"View " + *
view_name_ +
6823 " will not be dropped. User has no drop view privileges.");
6827 catalog.dropTable(td);
6831 const std::unique_ptr<NameValueAssign>& p) {
6833 if (!dynamic_cast<const StringLiteral*>(p->get_value())) {
6834 throw std::runtime_error(option_name +
" option must be a string literal.");
6839 CHECK(payload.HasMember(
"name"));
6843 if (payload.HasMember(
"ifNotExists")) {
6844 if_not_exists_ =
json_bool(payload[
"ifNotExists"]);
6851 bool read_only_mode) {
6852 if (read_only_mode) {
6853 throw std::runtime_error(
"CREATE DATABASE invalid in read only mode.");
6856 throw std::runtime_error(
6857 "CREATE DATABASE command can only be executed by super user.");
6869 if (boost::iequals(*p->get_name(),
"owner")) {
6871 const std::string* str =
6872 static_cast<const StringLiteral*
>(p->get_value())->get_stringval();
6874 if (!SysCatalog::instance().getMetadataForUser(*str, user)) {
6875 throw std::runtime_error(
"User " + *str +
" does not exist.");
6879 throw std::runtime_error(
"Invalid CREATE DATABASE option " + *p->get_name() +
6880 ". Only OWNER supported.");
6884 SysCatalog::instance().createDatabase(*
db_name_, ownerId);
6888 CHECK(payload.HasMember(
"name"));
6892 if (payload.HasMember(
"ifExists")) {
6893 if_exists_ =
json_bool(payload[
"ifExists"]);
6898 bool read_only_mode) {
6899 if (read_only_mode) {
6900 throw std::runtime_error(
"DROP DATABASE invalid in read only mode.");
6905 if (!SysCatalog::instance().getMetadataForDB(*
db_name_, db)) {
6909 throw std::runtime_error(
"Database " + *
db_name_ +
" does not exist.");
6914 throw std::runtime_error(
6915 "DROP DATABASE command can only be executed by the owner or by a super "
6919 SysCatalog::instance().dropDatabase(db);
6923 const std::unique_ptr<NameValueAssign>& p) {
6925 const std::string* str =
6926 static_cast<const StringLiteral*
>(p->get_value())->get_stringval();
6927 if (boost::iequals(*str,
"true")) {
6929 }
else if (boost::iequals(*str,
"false")) {
6932 throw std::runtime_error(
"Value to " + option_name +
" must be TRUE or FALSE.");
6937 CHECK(payload.HasMember(
"name"));
6944 bool read_only_mode) {
6945 if (read_only_mode) {
6946 throw std::runtime_error(
"CREATE USER invalid in read only mode.");
6950 if (boost::iequals(*p->get_name(),
"password")) {
6953 }
else if (boost::iequals(*p->get_name(),
"is_super")) {
6956 }
else if (boost::iequals(*p->get_name(),
"default_db")) {
6959 *
static_cast<const StringLiteral*
>(p->get_value())->get_stringval();
6960 }
else if (boost::iequals(*p->get_name(),
"can_login")) {
6964 throw std::runtime_error(
"Invalid CREATE USER option " + *p->get_name() +
6965 ". Should be PASSWORD, IS_SUPER, CAN_LOGIN"
6970 throw std::runtime_error(
"Only super user can create new users.");
6972 SysCatalog::instance().createUser(*
user_name_, alts,
false);
6976 CHECK(payload.HasMember(
"name"));
6983 bool read_only_mode) {
6984 if (read_only_mode) {
6985 throw std::runtime_error(
"ALTER USER invalid in read only mode.");
6990 if (boost::iequals(*p->get_name(),
"password")) {
6993 }
else if (boost::iequals(*p->get_name(),
"is_super")) {
6996 }
else if (boost::iequals(*p->get_name(),
"default_db")) {
6997 if (dynamic_cast<const StringLiteral*>(p->get_value())) {
6999 *
static_cast<const StringLiteral*
>(p->get_value())->get_stringval();
7000 }
else if (dynamic_cast<const NullLiteral*>(p->get_value())) {
7003 throw std::runtime_error(
7004 "DEFAULT_DB option must be either a string literal or a NULL "
7007 }
else if (boost::iequals(*p->get_name(),
"can_login")) {
7010 throw std::runtime_error(
"Invalid ALTER USER option " + *p->get_name() +
7011 ". Should be PASSWORD, DEFAULT_DB, CAN_LOGIN"
7018 if (!SysCatalog::instance().getMetadataForUser(*
user_name_, user)) {
7019 throw std::runtime_error(
"User " + *
user_name_ +
" does not exist.");
7023 throw std::runtime_error(
"Only super user can change another user's attributes.");
7025 throw std::runtime_error(
7026 "A user can only update their own password or default database.");
7030 SysCatalog::instance().alterUser(*
user_name_, alts);
7034 CHECK(payload.HasMember(
"name"));
7038 if (payload.HasMember(
"ifExists")) {
7039 if_exists_ =
json_bool(payload[
"ifExists"]);
7044 bool read_only_mode) {
7045 if (read_only_mode) {
7046 throw std::runtime_error(
"DROP USER invalid in read only mode.");
7050 throw std::runtime_error(
"Only super user can drop users.");
7056 namespace Compress {
7066 const std::string& option_name) {
7068 if (boost::iequals(*option->
get_name(), option_name)) {
7069 if (
const auto str_literal =
7070 dynamic_cast<const StringLiteral*>(option->
get_value())) {
7071 return *str_literal->get_stringval();
7073 throw std::runtime_error(
"\"" + option_name +
"\" option must be a string.");
7081 const bool is_restore) {
7082 CHECK(payload.HasMember(
"tableName"));
7083 table_ = std::make_unique<std::string>(
json_str(payload[
"tableName"]));
7085 CHECK(payload.HasMember(
"filePath"));
7086 path_ = std::make_unique<std::string>(
json_str(payload[
"filePath"]));
7090 std::list<std::unique_ptr<NameValueAssign>> options;
7093 if (!options.empty()) {
7094 for (
const auto& option : options) {
7096 compression.has_value()) {
7099 }
else if (
auto s3_access_key =
get_string_option(option.get(),
"s3_access_key");
7100 s3_access_key.has_value()) {
7102 }
else if (
auto s3_secret_key =
get_string_option(option.get(),
"s3_secret_key");
7103 s3_secret_key.has_value()) {
7105 }
else if (
auto s3_session_token =
7107 s3_session_token.has_value()) {
7110 s3_region.has_value()) {
7113 s3_endpoint.has_value()) {
7117 throw std::runtime_error(
"Invalid WITH option: " + *option->get_name());
7122 for (
const auto& program : {
"tar",
"rm",
"mkdir",
"mv",
"cat"}) {
7123 if (boost::process::search_path(program).empty()) {
7124 throw std::runtime_error{
"Required program \"" + std::string{program} +
7125 "\" was not found."};
7132 const bool is_restore) {
7146 const std::string& compression_type,
7147 const bool is_restore) {
7149 const std::string compression = boost::algorithm::to_lower_copy(compression_type);
7154 const auto prog_path = boost::process::search_path(prog_name);
7155 if (prog_path.string().empty()) {
7156 throw std::runtime_error(
"Compression program " + prog_name +
" is not found.");
7162 const auto prog_path = boost::process::search_path(prog_name);
7163 if (prog_path.string().empty()) {
7164 throw std::runtime_error(
"Compression program " + prog_name +
" is not found.");
7169 throw std::runtime_error(
"Compression program " + compression +
" is not supported.");
7177 const bool is_restore) {
7191 bool read_only_mode) {
7198 auto table_read_lock =
7205 throw std::runtime_error(
"Table " + *
table_ +
7206 " will not be dumped. User has no select privileges.");
7210 throw std::runtime_error(
"Table " + *
table_ +
7211 " will not be dumped. User has no create privileges.");
7222 bool read_only_mode) {
7223 if (read_only_mode) {
7224 throw std::runtime_error(
"RESTORE TABLE invalid in read only mode.");
7234 throw std::runtime_error(
"Table " + *
table_ +
" exists.");
7239 throw std::runtime_error(
"Table " + *
table_ +
7240 " will not be restored. User has no create privileges.");
7249 const std::string& queryStr,
7251 auto session_copy = session_info;
7252 auto session_ptr = std::shared_ptr<Catalog_Namespace::SessionInfo>(
7253 &session_copy, boost::null_deleter());
7256 auto calcite_mgr =
cat.getCalciteMgr();
7257 const auto calciteQueryParsingOption =
7258 calcite_mgr->getCalciteQueryParsingOption(
true,
false,
true,
false);
7259 const auto calciteOptimizationOption = calcite_mgr->getCalciteOptimizationOption(
7264 const auto query_json = calcite_mgr
7265 ->process(query_state->createQueryStateProxy(),
7267 calciteQueryParsingOption,
7268 calciteOptimizationOption)
7274 CHECK(!query_json.empty());
7275 VLOG(2) <<
"Parsing JSON DDL from Calcite: " << query_json;
7276 rapidjson::Document ddl_query;
7277 ddl_query.Parse(query_json);
7278 CHECK(ddl_query.IsObject());
7279 CHECK(ddl_query.HasMember(
"payload"));
7280 CHECK(ddl_query[
"payload"].IsObject());
7281 const auto& payload = ddl_query[
"payload"].GetObject();
7282 CHECK(payload.HasMember(
"command"));
7283 CHECK(payload[
"command"].IsString());
7285 const auto& ddl_command = std::string_view(payload[
"command"].GetString());
7288 if (ddl_command ==
"CREATE_TABLE") {
7290 }
else if (ddl_command ==
"DROP_TABLE") {
7292 }
else if (ddl_command ==
"RENAME_TABLE") {
7294 }
else if (ddl_command ==
"ALTER_TABLE") {
7296 }
else if (ddl_command ==
"TRUNCATE_TABLE") {
7298 }
else if (ddl_command ==
"DUMP_TABLE") {
7300 }
else if (ddl_command ==
"RESTORE_TABLE") {
7302 }
else if (ddl_command ==
"OPTIMIZE_TABLE") {
7304 }
else if (ddl_command ==
"COPY_TABLE") {
7306 }
else if (ddl_command ==
"EXPORT_QUERY") {
7308 }
else if (ddl_command ==
"CREATE_VIEW") {
7310 }
else if (ddl_command ==
"DROP_VIEW") {
7312 }
else if (ddl_command ==
"CREATE_DB") {
7314 }
else if (ddl_command ==
"DROP_DB") {
7316 }
else if (ddl_command ==
"RENAME_DB") {
7318 }
else if (ddl_command ==
"CREATE_USER") {
7320 }
else if (ddl_command ==
"DROP_USER") {
7322 }
else if (ddl_command ==
"ALTER_USER") {
7324 }
else if (ddl_command ==
"RENAME_USER") {
7326 }
else if (ddl_command ==
"CREATE_ROLE") {
7328 }
else if (ddl_command ==
"DROP_ROLE") {
7330 }
else if (ddl_command ==
"GRANT_ROLE") {
7332 }
else if (ddl_command ==
"REVOKE_ROLE") {
7334 }
else if (ddl_command ==
"GRANT_PRIVILEGE") {
7336 }
else if (ddl_command ==
"REVOKE_PRIVILEGE") {
7338 }
else if (ddl_command ==
"CREATE_DATAFRAME") {
7340 }
else if (ddl_command ==
"CREATE_MODEL") {
7342 }
else if (ddl_command ==
"DROP_MODEL") {
7344 }
else if (ddl_command ==
"VALIDATE_SYSTEM") {
7348 throw std::runtime_error(
"Unsupported DDL command");
7350 return std::unique_ptr<Parser::Stmt>(stmt);
7354 const std::string& query_json,
7355 std::shared_ptr<Catalog_Namespace::SessionInfo const> session_ptr,
7356 bool read_only_mode) {
7359 if (ddl !=
nullptr) {
7360 (*ddl).
execute(*session_ptr, read_only_mode);
7365 int64_t fragment_size_value{-1};
7366 bool validation_failed{
false};
7368 fragment_size_value = std::stoll(fragment_size_str);
7369 }
catch (std::out_of_range& e) {
7370 validation_failed =
true;
7372 constexpr int64_t max_fragment_size = std::numeric_limits<int32_t>::max();
7373 if (!validation_failed &&
7374 (fragment_size_value <= 0 || fragment_size_value > max_fragment_size)) {
7375 validation_failed =
true;
7377 if (validation_failed) {
7378 throw std::runtime_error(
7379 "Invalid value \"" + fragment_size_str +
7380 "\" provided for FRAGMENT_SIZE option, expected a positive integer between "
7384 return fragment_size_value;
DEVICE auto upper_bound(ARGS &&...args)
bool repair_type(std::list< std::unique_ptr< NameValueAssign >> &options)
std::optional< std::string > passwd
SQLTypes to_sql_type(const std::string &type_name)
const ColumnConstraintDef * get_column_constraint() const
decltype(auto) get_max_rows_def(TableDescriptor &td, const NameValueAssign *p, const std::list< ColumnDescriptor > &columns)
void execute(const Catalog_Namespace::SessionInfo &session, bool read_only_mode) override
int32_t maxRollbackEpochs
std::string s3_secret_key
void validate_non_foreign_table_write(const TableDescriptor *table_descriptor)
static const AccessPrivileges VIEW_SQL_EDITOR
decltype(auto) get_max_chunk_size_def(TableDescriptor &td, const NameValueAssign *p, const std::list< ColumnDescriptor > &columns)
bool geo_promoted_type_match(const SQLTypes a, const SQLTypes b)
static const std::map< const std::string, const TableDefFuncPtr > tableDefFuncMap
HOST DEVICE SQLTypes get_subtype() const
void set_compression(EncodingType c)
ValidateStmt(std::string *type, std::list< NameValueAssign * > *with_opts)
bool hasData(SubstituteMap &sMap, std::string tableName)
std::unique_ptr< std::string > username_
std::vector< std::string > privileges_
std::string s3_secret_key
size_t shard_column_index(const std::string &name, const std::list< ColumnDescriptor > &columns)
const Literal * get_value() const
CreateDBStmt(const rapidjson::Value &payload)
const std::string & get_column() const
bool was_deferred_copy_from_
std::vector< std::unique_ptr< lockmgr::AbstractLockContainer< const TableDescriptor * >>> LockedTableDescriptors
double g_running_query_interrupt_freq
std::string get_ml_model_type_str(const MLModelType model_type)
int32_t raster_scanlines_per_thread
RevokePrivilegesStmt(std::list< std::string * > *p, std::string *t, std::string *o, std::list< std::string * > *g)
static const AccessPrivileges VIEW_DASHBOARD
bool check_session_interrupted(const QuerySessionId &query_session, Executor *executor)
GrantPrivilegesStmt(std::list< std::string * > *p, std::string *t, std::string *o, std::list< std::string * > *g)
static const int32_t DROP_VIEW
ExportQueryStmt(std::string *q, std::string *p, std::list< NameValueAssign * > *o)
std::unique_ptr< QueryConnector > leafs_connector_
boost::function< void(TableDescriptor &, const Parser::NameValueAssign *, const std::list< ColumnDescriptor > &columns)> TableDefFuncPtr
HOST DEVICE int get_size() const
std::unique_ptr< std::string > new_database_name_
std::unique_ptr< std::string > view_name_
std::shared_ptr< ResultSet > getResultSet(QueryStateProxy query_state_proxy, const std::string select_stmt, std::vector< TargetMetaInfo > &targets, bool validate_only=false, std::vector< size_t > outer_fragment_indices={}, bool allow_interrupt=false)
SQLType * get_column_type() const
double data_split_eval_fraction_
std::list< std::unique_ptr< NameValueAssign > > storage_options_
QueryStateProxy createQueryStateProxy()
static const AccessPrivileges DROP_SERVER
void setColumnDescriptor(ColumnDescriptor &cd, const ColumnDef *coldef)
static const int32_t SELECT_FROM_VIEW
static constexpr int32_t kMaxNumericPrecision
std::unique_ptr< std::string > db_name_
std::optional< std::string > default_db
class for a per-database catalog. also includes metadata for the current database and the current use...
std::unique_ptr< std::string > target_
std::list< std::unique_ptr< NameValueAssign > > model_options_
std::unique_ptr< std::string > user_name_
static void checkStringLiteral(const std::string &option_name, const std::unique_ptr< NameValueAssign > &p)
static const int32_t UPDATE_IN_VIEW
const std::vector< std::vector< std::shared_ptr< TargetEntry > > > & get_values_lists() const
void executeDryRun(const Catalog_Namespace::SessionInfo &session, TableDescriptor &td, std::list< ColumnDescriptor > &columns, std::vector< SharedDictionaryDef > &shared_dict_defs)
const std::vector< TargetMetaInfo > targets_meta
void add_rte(RangeTableEntry *rte)
bool is_timestamp() const
static const AccessPrivileges ALL_DATABASE
static TimeT::rep execution(F func, Args &&...args)
void set_column_descriptor(ColumnDescriptor &cd, const ColumnDef *coldef)
void parseOptions(import_export::CopyParams ©_params, import_export::QueryExporter::FileType &file_type, std::string &layer_name, import_export::QueryExporter::FileCompression &file_compression, import_export::QueryExporter::ArrayNullHandling &array_null_handling)
decltype(auto) get_vacuum_def(TableDescriptor &td, const NameValueAssign *p, const std::list< ColumnDescriptor > &columns)
static const AccessPrivileges ALTER_TABLE
std::unique_ptr< std::string > copy_from_source_pattern_
CreateTableStmt(std::string *tab, const std::string *storage, std::list< TableElement * > *table_elems, bool is_temporary, bool if_not_exists, std::list< NameValueAssign * > *s)
RenameUserStmt(const rapidjson::Value &payload)
void execute(const Catalog_Namespace::SessionInfo &session, bool read_only_mode) override
static const int32_t CREATE_VIEW
bool raster_point_compute_angle
std::list< std::unique_ptr< TableElement > > table_element_list_
std::list< std::unique_ptr< NameValueAssign > > options_
auto getExecuteReadLock()
DropViewStmt(std::string *v, bool i)
size_t getOuterFragmentCount(QueryStateProxy, std::string &sql_query_string) override
const std::string & get_model_name() const
bool g_enable_legacy_delimited_import
bool user_can_access_table(const Catalog_Namespace::SessionInfo &session_info, const TableDescriptor *td, const AccessPrivileges access_priv)
std::unique_ptr< std::string > table_
void expand_star_in_targetlist(const Catalog_Namespace::Catalog &catalog, std::vector< std::shared_ptr< TargetEntry >> &tlist, int rte_idx)
bool geo_explode_collections
static const AccessPrivileges TRUNCATE_TABLE
const std::string & get_role() const
unsigned g_pending_query_interrupt_freq
std::unique_ptr< std::string > table_
std::unique_ptr< std::string > return_message
RenameDBStmt(const rapidjson::Value &payload)
static WriteLock getWriteLockForTable(const Catalog_Namespace::Catalog &cat, const std::string &table_name)
const bool json_bool(const rapidjson::Value &obj) noexcept
decltype(auto) get_skip_rows_def(DataframeTableDescriptor &df_td, const NameValueAssign *p, const std::list< ColumnDescriptor > &columns)
HOST DEVICE int get_scale() const
std::vector< std::string > grantees_
void populateData(QueryStateProxy, const TableDescriptor *td, bool validate_table, bool for_CTAS=false)
static const AccessPrivileges INSERT_INTO_TABLE
const std::string json_str(const rapidjson::Value &obj) noexcept
std::vector< std::unique_ptr< TypedImportBuffer > > fill_missing_columns(const Catalog_Namespace::Catalog *cat, Fragmenter_Namespace::InsertData &insert_data)
std::shared_ptr< Analyzer::Expr > deep_copy() const override
static const AccessPrivileges CREATE_DASHBOARD
static const AccessPrivileges SERVER_USAGE
static std::shared_ptr< QueryState > create(ARGS &&...args)
#define DEFAULT_MAX_CHUNK_SIZE
std::list< std::unique_ptr< NameValueAssign > > options_
HOST DEVICE void set_subtype(SQLTypes st)
DEVICE void sort(ARGS &&...args)
std::unique_ptr< std::string > new_username_
std::unique_ptr< std::string > file_path_
std::string write_model_params_to_json(const std::string &predicted, const std::vector< std::string > &features, const std::string &training_query, const double data_split_train_fraction, const double data_split_eval_fraction, const std::vector< int64_t > &feature_permutations)
std::string tarCompressionStr(CompressionType compression, const bool is_restore)
Driver for running cleanup processes on a table. TableOptimizer provides functions for various cleanu...
SQLTypeInfo get_logical_type_info(const SQLTypeInfo &type_info)
TypeR::rep timer_stop(Type clock_begin)
size_t max_import_batch_row_count
std::string deferred_copy_from_partitions_
void analyze(const Catalog_Namespace::Catalog &catalog, Analyzer::Query &query) const override=0
void set_order_by(std::list< OrderEntry > *o)
std::string extractObjectNameFromHierName(const std::string &objectHierName, const std::string &objectType, const Catalog_Namespace::Catalog &cat)
OptimizeTableStmt(std::string *table, std::list< NameValueAssign * > *o)
const Literal * get_defaultval() const
std::unique_ptr< std::string > column_
static const int32_t ALTER_TABLE
void set_result_col_list(const std::list< int > &col_list)
std::string connection_string
const std::string kDefaultExportDirName
std::string toString(const QueryDescriptionType &type)
std::unique_ptr< std::string > user_name_
std::unique_ptr< std::string > table_
std::string model_predicted_var_
void setPrivileges(const AccessPrivileges &privs)
bool g_enable_non_kernel_time_query_interrupt
HOST DEVICE SQLTypes get_type() const
void set_offset(int64_t o)
const std::vector< std::string > & get_roles() const
SQLTypeInfo common_string_type(const SQLTypeInfo &lhs_type_info, const SQLTypeInfo &rhs_type_info, const Executor *executor)
std::vector< std::string > splitObjectHierName(const std::string &hierName)
std::vector< std::string > model_feature_vars_
std::string raster_import_dimensions
#define TRANSIENT_DICT_ID
static const AccessPrivileges SELECT_FROM_TABLE
static std::unique_ptr< QueryExporter > create(const FileType file_type)
std::vector< int64_t > feature_permutations_
std::optional< bool > is_super
AggregatedResult query(QueryStateProxy, std::string &sql_query_string, std::vector< size_t > outer_frag_indices, bool validate_only, bool allow_interrupt)
bool bool_from_string_literal(const Parser::StringLiteral *str_literal)
void get_table_definitions_for_ctas(TableDescriptor &td, const std::unique_ptr< NameValueAssign > &p, const std::list< ColumnDescriptor > &columns)
void train_model(const Catalog_Namespace::SessionInfo &session)
void insertData(const Catalog_Namespace::SessionInfo &session_info, InsertData &insert_data)
std::unique_ptr< AbstractImporter > create_importer(Catalog_Namespace::Catalog &catalog, const TableDescriptor *td, const std::string ©_from_source, const import_export::CopyParams ©_params)
int32_t get_table_id() const
ChunkKey get_table_key(const ChunkKey &key)
void execute(const Catalog_Namespace::SessionInfo &session, bool read_only_mode) override
std::unique_ptr< std::string > table_
int get_rte_idx(const std::string &range_var_name) const
TableArchiverS3Options s3_options_
std::unique_ptr< std::string > table_
const std::string & get_object_type() const
CompressionType defaultCompression(bool is_restore)
static const AccessPrivileges ALL_VIEW
const std::string & get_object() const
void validate_non_duplicate_column(const std::string &column_name, std::unordered_set< std::string > &upper_column_names)
void execute(const Catalog_Namespace::SessionInfo &session, bool read_only_mode)
bool g_enable_string_functions
std::unique_ptr< std::string > database_name_
int tableId
identifies the database into which the data is being inserted
DBObjectType DBObjectTypeFromString(const std::string &type)
void execute(const Catalog_Namespace::SessionInfo &session, bool read_only_mode) override
std::shared_lock< T > shared_lock
static void set_geo_physical_import_buffer(const Catalog_Namespace::Catalog &catalog, const ColumnDescriptor *cd, std::vector< std::unique_ptr< TypedImportBuffer >> &import_buffers, size_t &col_idx, std::vector< double > &coords, std::vector< double > &bounds, std::vector< int > &ring_sizes, std::vector< int > &poly_rings, const bool force_null=false)
void set_column_descriptor(const std::string &column_name, ColumnDescriptor &cd, SqlType *column_type, const bool not_null, const Encoding *encoding, const std::string *default_value)
static std::shared_ptr< Executor > getExecutor(const ExecutorId id, const std::string &debug_dir="", const std::string &debug_file="", const SystemParameters &system_parameters=SystemParameters())
void execute(const Catalog_Namespace::SessionInfo &session, bool read_only_mode) override
static const AccessPrivileges ALTER_SERVER
ArrayLiteral * parse_insert_array_literal(const rapidjson::Value &array)
std::list< std::unique_ptr< std::string > > columns_
std::string add_metadata_columns
size_t numRows
a vector of column ids for the row(s) being inserted
This file contains the class specification and related data structures for Catalog.
std::vector< std::string > roles_
ImportHeaderRow has_header
const std::string & get_role() const
DumpTableStmt(const rapidjson::Value &payload)
std::ostringstream options_oss_
std::string generateUniqueTableName(std::string name)
bool geos_validation_available()
static SQLTypeInfo common_string_type(const SQLTypeInfo &type1, const SQLTypeInfo &type2)
double data_split_train_fraction_
std::unique_ptr< std::string > table_
std::vector< uint8_t > compress_coords(const std::vector< double > &coords, const SQLTypeInfo &ti)
void parse_model_options()
std::optional< std::string > regex_path_filter
int get_physical_cols() const
Supported runtime functions management and retrieval.
void execute(const Catalog_Namespace::SessionInfo &session, bool read_only_mode) override
future< Result > async(Fn &&fn, Args &&...args)
static SysCatalog & instance()
CreateRoleStmt(std::string *r)
void execute(const Catalog_Namespace::SessionInfo &session, bool read_only_mode) override
void execute(const Catalog_Namespace::SessionInfo &session, bool read_only_mode) override
std::list< std::unique_ptr< NameValueAssign > > options_
int32_t validate_and_get_fragment_size(const std::string &fragment_size_str)
const std::string * get_stringval() const
std::unique_ptr< std::string > select_stmt_
std::unique_ptr< QueryConnector > leafs_connector_
void recordRename(SubstituteMap &sMap, std::string oldName, std::string newName)
CONSTEXPR DEVICE bool is_null(const T &value)
RasterPointType raster_point_type
Classes representing a parse tree.
bool check_model_exists()
std::string build_model_query(const std::shared_ptr< Catalog_Namespace::SessionInfo > session_ptr)
RangeTableEntry * get_rte(int rte_idx) const
void get_dataframe_definitions(DataframeTableDescriptor &df_td, const std::unique_ptr< NameValueAssign > &p, const std::list< ColumnDescriptor > &columns)
std::vector< std::string > roles_
const DBMetadata & getCurrentDB() const
const std::string & get_role() const
std::vector< std::string > grantees_
boost::function< void(DataframeTableDescriptor &, const Parser::NameValueAssign *, const std::list< ColumnDescriptor > &columns)> DataframeDefFuncPtr
std::list< std::unique_ptr< NameValueAssign > > storage_options_
void execute(const Catalog_Namespace::SessionInfo &session, bool read_only_mode) override
const std::vector< std::string > & get_grantees() const
static const int32_t DROP_DATABASE
std::list< std::unique_ptr< ColumnDef > > coldefs_
bool geo_validate_geometry
std::unique_ptr< std::string > type_
std::unique_ptr< Parser::Stmt > create_stmt_for_json(const std::string &query_json)
std::list< TableNamePair > tablesToRename_
static const AccessPrivileges DROP_TABLE
decltype(auto) get_shard_count_def(TableDescriptor &td, const NameValueAssign *p, const std::list< ColumnDescriptor > &columns)
void execute(const Catalog_Namespace::SessionInfo &session, bool read_only_mode) override
const int64_t json_i64(const rapidjson::Value &obj) noexcept
std::unique_ptr< std::string > role_
RestoreTableStmt(const rapidjson::Value &payload)
WhichRow get_which_row() const
std::list< ColumnDef > get_columns_from_json_payload(const std::string &payload_key, const rapidjson::Value &payload)
std::unique_ptr< std::string > type_
void execute(const Catalog_Namespace::SessionInfo &session, bool read_only_mode) override
int64_t get_intval() const
static const int32_t DELETE_FROM_TABLE
CompressionType compression_
const double json_double(const rapidjson::Value &obj) noexcept
std::string select_query_
bool get_is_distinct() const
int32_t s3_max_concurrent_downloads
std::string deferred_copy_from_file_name_
const ColumnDescriptor * getMetadataForColumn(int tableId, const std::string &colName) const
bool should_translate_strings(const std::shared_ptr< Analyzer::Expr > &lhs_expr, const std::shared_ptr< Analyzer::Expr > &rhs_expr)
void execute(const Catalog_Namespace::SessionInfo &session, bool read_only_mode) override
static SQLTypeInfo common_numeric_type(const SQLTypeInfo &type1, const SQLTypeInfo &type2)
std::string select_query_
RevokeRoleStmt(std::list< std::string * > *r, std::list< std::string * > *g)
static const int32_t TRUNCATE_TABLE
Checked json field retrieval.
static bool getGeoColumns(const std::string &wkt_or_wkb_hex, SQLTypeInfo &ti, std::vector< double > &coords, std::vector< double > &bounds, std::vector< int > &ring_sizes, std::vector< int > &poly_rings, const bool validate_with_geos_if_available)
int getDatabaseId() const
const std::string * get_column_name() const
static const AccessPrivileges ALL_SERVER
static const AccessPrivileges CREATE_SERVER
DropRoleStmt(std::string *r, bool e)
void execute(const Catalog_Namespace::SessionInfo &session, bool read_only_mode) override
void vacuumDeletedRows() const
Compacts fragments to remove deleted rows. When a row is deleted, a boolean deleted system column is ...
static const AccessPrivileges DELETE_FROM_TABLE
Datum StringToDatum(const std::string_view s, SQLTypeInfo &ti)
import_export::SourceType source_type
std::unique_ptr< NameValueAssign > param_
std::string unescape(std::string s)
RenameTableStmt(const rapidjson::Value &payload)
specifies the content in-memory of a row in the column metadata table
OUTPUT transform(INPUT const &input, FUNC const &func)
#define DEFAULT_MAX_ROLLBACK_EPOCHS
specifies the content in-memory of a row in the table metadata table
std::unique_ptr< std::string > table_
std::list< std::unique_ptr< NameValueAssign > > options_
void parse_elements(const rapidjson::Value &payload, std::string element_name, std::string &table_name, std::list< std::unique_ptr< TableElement >> &table_element_list)
bool modelExists(const std::string &model_name) const
bool expr_is_null(const Analyzer::Expr *expr)
const std::vector< std::string > & get_roles() const
static const std::map< const std::string, const DataframeDefFuncPtr > dataframeDefFuncMap
std::unique_ptr< Fragmenter_Namespace::InsertDataLoader::InsertConnector > leafs_connector_
std::unique_ptr< std::string > table_
bool check_session_interrupted(const QuerySessionId &query_session, Executor *executor)
bool g_enable_smem_group_by true
std::unique_ptr< std::string > new_column_name_
void execute(const Catalog_Namespace::SessionInfo &session, bool read_only_mode) override
static const int32_t EDIT_DASHBOARD
static const int32_t DELETE_DASHBOARD
static const AccessPrivileges CREATE_TABLE
std::vector< std::string > grantees_
std::unique_ptr< std::string > path_
static const int32_t INSERT_INTO_TABLE
lockmgr::LockedTableDescriptors acquire_query_table_locks(const std::string &insert_table_db_name, const std::string &query_str, const QueryStateProxy &query_state_proxy, const std::optional< std::string > &insert_table_name={})
void set_group_by(std::list< std::shared_ptr< Analyzer::Expr >> &g)
void set_default_table_attributes(const std::string &table_name, TableDescriptor &td, const int32_t column_count)
const SQLTypeInfo & get_type_info() const
std::shared_ptr< Fragmenter_Namespace::AbstractFragmenter > fragmenter
SQLTypeInfo get_array_type() const
bool g_optimize_cuda_block_and_grid_sizes
std::unique_ptr< std::string > table_
void set_next_query(Query *q)
std::string DBObjectTypeToString(DBObjectType type)
void validate_allowed_file_path(const std::string &file_path, const DataTransferType data_transfer_type, const bool allow_wildcards)
void parse_options(const rapidjson::Value &payload, std::list< std::unique_ptr< NameValueAssign >> &nameValueList, bool stringToNull=false, bool stringToInteger=false)
int get_result_table_id() const
std::unique_ptr< std::string > user_name_
void check_executable(const Catalog_Namespace::SessionInfo &session, const TableDescriptor *td)
DropUserStmt(const rapidjson::Value &payload)
#define DEFAULT_PAGE_SIZE
void execute(const Catalog_Namespace::SessionInfo &session, bool read_only_mode) override
std::unique_ptr< std::string > role_
void parse_copy_params(const std::list< std::unique_ptr< NameValueAssign >> &options_, import_export::CopyParams ©_params, std::vector< std::string > &warnings, std::string &deferred_copy_from_partitions_)
TruncateTableStmt(std::string *tab)
void set_having_predicate(std::shared_ptr< Analyzer::Expr > p)
Literal * parse_insert_literal(const rapidjson::Value &literal)
GrantRoleStmt(std::list< std::string * > *r, std::list< std::string * > *g)
void set_comp_param(int p)
std::string get_session_id() const
void analyze(const Catalog_Namespace::Catalog &catalog, Analyzer::Query &query) const override
void set_result_table_id(int id)
const std::string * get_name() const
std::string geo_layer_name
const AccessPrivileges & getPrivileges() const
void validate_shard_column_type(const ColumnDescriptor &cd)
const std::string kRootUsername
void execute(const Catalog_Namespace::SessionInfo &session, bool read_only_mode) override
bool g_test_drop_column_rollback
const std::string sUNGZIP
void check_alter_table_privilege(const Catalog_Namespace::SessionInfo &session, const TableDescriptor *td)
const shared::ColumnKey & getColumnKey() const
DEVICE auto lower_bound(ARGS &&...args)
void set_is_distinct(bool d)
HOST DEVICE EncodingType get_compression() const
bool is_date_in_days() const
static const AccessPrivileges SELECT_FROM_VIEW
bool table_is_temporary(const TableDescriptor *const td)
const CompressDef * get_compression() const
std::vector< std::shared_ptr< TargetEntry > > & get_targetlist_nonconst()
bool g_enable_fsi_regex_import
Catalog & getCatalog() const
static ReadLock getReadLockForTable(Catalog_Namespace::Catalog &cat, const std::string &table_name)
void set_dimension(int d)
#define DEFAULT_FRAGMENT_ROWS
void setStringDictKey(const shared::StringDictKey &dict_key)
std::list< std::unique_ptr< NameValueAssign > > options_
Datum get_constval() const
void execute_stmt_for_json(const std::string &query_json, std::shared_ptr< Catalog_Namespace::SessionInfo const > session_ptr, bool read_only_mode)
import_export::CopyParams deferred_copy_from_copy_params_
void execute(const Catalog_Namespace::SessionInfo &session, bool read_only_mode) override
DropTableStmt(std::string *tab, bool i)
std::string line_start_regex
std::vector< std::string > grantees_
void execute(const Catalog_Namespace::SessionInfo &session, bool read_only_mode) override
Fragmenter_Namespace::FragmenterType fragType
std::list< const ColumnDescriptor * > getAllColumnMetadataForTable(const int tableId, const bool fetchSystemColumns, const bool fetchVirtualColumns, const bool fetchPhysicalColumns) const
Returns a list of pointers to constant ColumnDescriptor structs for all the columns from a particular...
Data_Namespace::MemoryLevel persistenceLevel
void set_is_unionall(bool u)
bool is_none_encoded_string() const
std::string s3_session_token
static const int32_t CREATE_DATABASE
HOST DEVICE int get_dimension() const
InsertIntoTableAsSelectStmt(const rapidjson::Value &payload)
std::vector< int > getTableChunkKey(const TableDescriptor *td, Catalog_Namespace::Catalog &catalog)
void disable_foreign_tables(const TableDescriptor *td)
int32_t geo_coords_comp_param
void execute(const Catalog_Namespace::SessionInfo &session, bool read_only_mode) override
std::string select_query_
std::list< std::unique_ptr< std::string > > column_list_
std::string s3_session_token
decltype(auto) get_sort_column_def(TableDescriptor &td, const NameValueAssign *p, const std::list< ColumnDescriptor > &columns)
static const AccessPrivileges ALL_DASHBOARD
std::string get_type_name() const
std::list< std::unique_ptr< NameValueAssign > > storage_options_
static const AccessPrivileges ACCESS
torch::Tensor f(torch::Tensor x, torch::Tensor W_target, torch::Tensor b_target)
CreateModelStmt(const rapidjson::Value &payload)
static const int32_t VIEW_DASHBOARD
static std::pair< AccessPrivileges, DBObjectType > parseStringPrivs(const std::string &privs, const DBObjectType &objectType, const std::string &object_name)
virtual std::shared_ptr< Analyzer::Expr > add_cast(const SQLTypeInfo &new_type_info)
void deleteModel(const std::string &model_name)
static const AccessPrivileges ALL_TABLE
decltype(auto) get_frag_size_def(TableDescriptor &td, const NameValueAssign *p, const std::list< ColumnDescriptor > &columns)
bool g_enable_ml_functions
void execute(const Catalog_Namespace::SessionInfo &session, bool read_only_mode) override
CreateViewStmt(const std::string &view_name, const std::string &select_query, const bool if_not_exists)
decltype(auto) get_header_def(DataframeTableDescriptor &df_td, const NameValueAssign *p, const std::list< ColumnDescriptor > &columns)
void set_where_predicate(std::shared_ptr< Analyzer::Expr > p)
HOST DEVICE int get_comp_param() const
void set_stmt_type(SQLStmtType t)
const ColumnDescriptor * get_column_desc(const Catalog_Namespace::Catalog &catalog, const std::string &name)
static const StringDictKey kTransientDictKey
std::unique_ptr< std::string > type_
static void verifyObject(Catalog_Namespace::Catalog &sessionCatalog, const std::string &objectName, DBObjectType objectType, const std::string &command)
static CompilationOptions defaults(const ExecutorDeviceType device_type=ExecutorDeviceType::GPU)
DumpRestoreTableStmtBase(const rapidjson::Value &payload, const bool is_restore)
std::optional< bool > can_login
void set_dict_intersection()
static const int32_t DROP_TABLE
std::vector< std::unique_ptr< std::string > > column_list_
bool shouldVacuumDeletedRows() const
#define NULL_ARRAY_DOUBLE
void checkNameSubstition(SubstituteMap &sMap)
void validate_table_type(const TableDescriptor *td, const TableType expected_table_type, const std::string &command)
std::unique_ptr< std::string > db_name_
static const int32_t INSERT_INTO_VIEW
void execute(const Catalog_Namespace::SessionInfo &session, bool read_only_mode) override
std::string raster_import_bands
virtual std::shared_ptr< Analyzer::Expr > analyze(const Catalog_Namespace::Catalog &catalog, Analyzer::Query &query, TlistRefType allow_tlist_ref=TLIST_NONE) const =0
std::string QuerySessionId
static const AccessPrivileges DROP_VIEW
bool g_enable_watchdog false
std::unique_ptr< std::string > target_
void execute(const Catalog_Namespace::SessionInfo &session, bool read_only_mode) override
static bool readBooleanLiteral(const std::string &option_name, const std::unique_ptr< NameValueAssign > &p)
void execute(const Catalog_Namespace::SessionInfo &session, bool read_only_mode) override
static const int32_t DELETE_FROM_VIEW
static const AccessPrivileges CREATE_VIEW
static const int32_t CREATE_TABLE
void validate_shared_dictionary(const Parser::CreateTableBaseStmt *stmt, const Parser::SharedDictionaryDef *shared_dict_def, const std::list< ColumnDescriptor > &columns, const std::vector< Parser::SharedDictionaryDef > &shared_dict_defs_so_far, const Catalog_Namespace::Catalog &catalog)
CreateDataframeStmt(std::string *tab, std::list< TableElement * > *table_elems, std::string *filename, std::list< NameValueAssign * > *s)
void get_table_definitions(TableDescriptor &td, const std::unique_ptr< NameValueAssign > &p, const std::list< ColumnDescriptor > &columns)
decltype(auto) get_partions_def(TableDescriptor &td, const NameValueAssign *p, const std::list< ColumnDescriptor > &columns)
const std::vector< std::string > & get_privs() const
std::vector< std::string > privileges_
CopyTableStmt(std::string *t, std::string *f, std::list< NameValueAssign * > *o)
std::unique_ptr< ColumnDef > column_from_json(const rapidjson::Value &element)
std::list< std::unique_ptr< NameValueAssign > > options_
static std::string encode_base64(const std::string &val)
static void clearExternalCaches(bool for_update, const TableDescriptor *td, const int current_db_id)
static const int32_t CREATE_DASHBOARD
decltype(auto) get_page_size_def(TableDescriptor &td, const NameValueAssign *p, const std::list< ColumnDescriptor > &columns)
const std::string & get_object_type() const
const std::vector< std::string > & get_grantees() const
decltype(auto) get_property_value(const NameValueAssign *p, ASSIGNMENT op, VALIDATE validate=VALIDATE())
const std::list< std::shared_ptr< Analyzer::Expr > > & get_group_by() const
void execute(const Catalog_Namespace::SessionInfo &session, bool read_only_mode) override
std::vector< std::unique_ptr< ValuesList > > values_lists_
The data to be inserted using the fragment manager.
auto getExecuteWriteLock()
void execute(const Catalog_Namespace::SessionInfo &session, bool read_only_mode) override
const std::vector< std::string > & get_privs() const
bool is_regression_model(const MLModelType model_type)
static DBObject createObject(const std::string &objectName, DBObjectType objectType)
MLModelType get_ml_model_type_from_str(const std::string &model_type_str)
void analyze(const Catalog_Namespace::Catalog &catalog, Analyzer::Query &query) const override
decltype(auto) get_max_chunk_size_dataframe_def(DataframeTableDescriptor &df_td, const NameValueAssign *p, const std::list< ColumnDescriptor > &columns)
std::list< ColumnDescriptor > getColumnDescriptors(AggregatedResult &result, bool for_create)
void execute(const Catalog_Namespace::SessionInfo &session, bool read_only_mode) override
static const AccessPrivileges DELETE_DASHBOARD
void execute(const Catalog_Namespace::SessionInfo &session, bool read_only_mode) override
bool is_dict_encoded_string() const
static const int32_t SELECT_FROM_TABLE
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 s3_access_key
static constexpr ExecutorId UNITARY_EXECUTOR_ID
const std::string & get_object() const
decltype(auto) get_frag_size_dataframe_def(DataframeTableDescriptor &df_td, const NameValueAssign *p, const std::list< ColumnDescriptor > &columns)
bool checkDBAccessPrivileges(const DBObjectType &permissionType, const AccessPrivileges &privs, const std::string &objectName="") const
std::unique_ptr< std::string > table_
void execute(const Catalog_Namespace::SessionInfo &session, bool read_only_mode) override
bool isAggregator() const
AlterUserStmt(const rapidjson::Value &payload)
void set_limit(int64_t l)
decltype(auto) get_max_rollback_epochs_def(TableDescriptor &td, const NameValueAssign *p, const std::list< ColumnDescriptor > &columns)
virtual void execute(const Catalog_Namespace::SessionInfo &session, bool read_only_mode)=0
static constexpr char const * FOREIGN_TABLE
void execute(const Catalog_Namespace::SessionInfo &session, bool read_only_mode) override
void restoreTable(const Catalog_Namespace::SessionInfo &session, const std::string &table_name, const std::string &archive_path, const std::string &compression, const TableArchiverS3Options &s3_options)
const std::list< int > & get_result_col_list() const
static const AccessPrivileges EDIT_DASHBOARD
static const AccessPrivileges UPDATE_IN_TABLE
std::map< std::string, std::string > SubstituteMap
static const int32_t UPDATE_IN_TABLE
std::list< std::unique_ptr< TableElement > > table_element_list_
std::string s3_access_key
SQLTypeInfo get_elem_type() const
static constexpr char const * EMPTY_NAME
std::shared_ptr< Catalog_Namespace::SessionInfo const > getConstSessionInfo() const
const std::vector< std::shared_ptr< TargetEntry > > & get_targetlist() const
CreateTableAsSelectStmt(const rapidjson::Value &payload)
CompressionType validateCompression(const std::string &compression, const bool is_restore)
RasterPointTransform raster_point_transform
bool g_enable_add_metadata_columns
bool hasPermission(int permission) const
DropModelStmt(const rapidjson::Value &payload)
void execute(const Catalog_Namespace::SessionInfo &session, bool read_only_mode) override
bool is_distinct(const size_t input_idx, const RelAlgNode *node)
DropDBStmt(const rapidjson::Value &payload)
std::unique_ptr< std::string > table_
std::string loadTable(Catalog_Namespace::Catalog &catalog, SubstituteMap &sMap, std::string tableName)
void dumpTable(const TableDescriptor *td, const std::string &archive_path, const std::string &compression)
const UserMetadata & get_currentUser() const
size_t sort_column_index(const std::string &name, const std::list< ColumnDescriptor > &columns)
std::optional< std::string > file_sort_order_by
std::string pg_shim(const std::string &query)
std::unique_ptr< Parser::Stmt > create_stmt_for_query(const std::string &queryStr, const Catalog_Namespace::SessionInfo &session_info)
const std::vector< RangeTableEntry * > & get_rangetable() const
#define TRANSIENT_DICT(ID)
CreateUserStmt(const rapidjson::Value &payload)
double get_doubleval() const
decltype(auto) get_storage_type(TableDescriptor &td, const NameValueAssign *p, const std::list< ColumnDescriptor > &columns)
const std::string & get_object_type() const
std::string credential_string
std::unique_ptr< std::string > filename_
static SQLTypeInfo analyze_type_info(SQLOps op, const SQLTypeInfo &left_type, const SQLTypeInfo &right_type, SQLTypeInfo *new_left_type, SQLTypeInfo *new_right_type)
const std::string getQuerySubmittedTime() const
decltype(auto) get_delimiter_def(DataframeTableDescriptor &df_td, const NameValueAssign *p, const std::list< ColumnDescriptor > &columns)
SQLTypeInfo const & get_str_dict_cast_type(const SQLTypeInfo &lhs_type_info, const SQLTypeInfo &rhs_type_info, const Executor *executor)
void execute(const Catalog_Namespace::SessionInfo &session, bool read_only_mode) override
std::string serialize_key_metainfo(const ShardKeyDef *shard_key_def, const std::vector< SharedDictionaryDef > &shared_dict_defs)
void recomputeMetadata() const
Recomputes per-chunk metadata for each fragment in the table. Updates and deletes can cause chunk met...
void execute(const Catalog_Namespace::SessionInfo &session, bool read_only_mode) override
void set_precision(int d)
std::unique_ptr< TargetValueConverter > create(ConverterCreateParameter param)
void set_string_field(rapidjson::Value &obj, const std::string &field_name, const std::string &field_value, rapidjson::Document &document)
void analyze(const Catalog_Namespace::Catalog &catalog, Analyzer::Query &query) const override
std::unique_ptr< std::string > table_
const std::string & get_object() const
virtual bool get_is_array() const
std::optional< std::string > file_sort_regex
std::unique_ptr< ColumnDef > coldef_
const shared::StringDictKey & getStringDictKey() const
std::optional< std::string > get_string_option(const NameValueAssign *option, const std::string &option_name)
EncodingType geo_coords_encoding
void execute(const Catalog_Namespace::SessionInfo &session, bool read_only_mode) override
void execute(const Catalog_Namespace::SessionInfo &session, bool read_only_mode) override
specifies the content in-memory of a row in the table metadata table