60 bool (*)(
const Analyzer::ColumnVar*,
const Analyzer::ColumnVar*)>
63 return colvar_set.size();
71 for (
const auto& column :
tuple_) {
72 column->collect_rte_idx(rte_idx_set);
77 std::vector<std::shared_ptr<Expr>> tuple_deep_copy;
78 for (
const auto& column :
tuple_) {
79 const auto column_deep_copy =
81 CHECK(column_deep_copy);
82 tuple_deep_copy.push_back(column_deep_copy);
84 return makeExpr<ExpressionTuple>(tuple_deep_copy);
129 std::list<std::shared_ptr<Analyzer::Expr>> new_value_list;
131 new_value_list.push_back(p->deep_copy());
133 return makeExpr<InValues>(
arg->deep_copy(), new_value_list);
137 std::vector<std::shared_ptr<Analyzer::Expr>> regressors_copy;
139 regressors_copy.emplace_back(r->deep_copy());
141 return makeExpr<MLPredictExpr>(
model_value_->deep_copy(), regressors_copy);
145 std::vector<std::shared_ptr<Analyzer::Expr>> features_copy;
147 features_copy.emplace_back(feature_value->deep_copy());
149 return makeExpr<PCAProjectExpr>(
158 return makeExpr<KeyForStringExpr>(
arg->deep_copy());
162 return makeExpr<SampleRatioExpr>(
arg->deep_copy());
166 return makeExpr<CardinalityExpr>(
arg->deep_copy());
170 return makeExpr<LikeExpr>(
arg->deep_copy(),
178 return makeExpr<RegexpExpr>(
arg->deep_copy(),
191 return makeExpr<LikelihoodExpr>(
arg->deep_copy(),
likelihood);
195 return makeExpr<AggExpr>(
200 std::list<std::pair<std::shared_ptr<Analyzer::Expr>, std::shared_ptr<Analyzer::Expr>>>
203 new_list.emplace_back(p.first->deep_copy(), p.second->deep_copy());
208 else_expr ==
nullptr ?
nullptr : else_expr->deep_copy());
216 return makeExpr<DateaddExpr>(
221 return makeExpr<DatediffExpr>(
226 return makeExpr<DatetruncExpr>(
231 return makeExpr<OffsetInFragment>();
240 return makeExpr<WindowFunction>(
type_info,
252 return makeExpr<Analyzer::ArrayExpr>(
274 *new_left_type = left_type;
275 *new_right_type = right_type;
278 throw std::runtime_error(
279 "non-boolean operands cannot be used in logic operations.");
283 if (left_type != right_type) {
286 *new_left_type = common_type;
288 *new_right_type = common_type;
295 throw std::runtime_error(
"Cannont compare between TIMESTAMP and TIME.");
302 *new_right_type = *new_left_type;
324 throw std::runtime_error(
"Cannont compare between TIME and TIMESTAMP.");
327 throw std::runtime_error(
"Cannont compare between TIME and DATE.");
352 *new_right_type = *new_left_type;
360 *new_right_type = *new_left_type;
364 throw std::runtime_error(
"Cannont compare between DATE and TIME.");
374 *new_left_type = right_type;
376 *new_right_type = right_type;
378 *new_left_type = left_type;
379 *new_right_type = left_type;
382 *new_left_type = left_type;
383 *new_right_type = right_type;
387 *new_left_type = common_type;
388 *new_right_type = common_type;
390 throw std::runtime_error(
"Cannot compare between " + left_type.
get_type_name() +
395 }
else if (op ==
kMINUS &&
398 *new_left_type = left_type;
399 *new_right_type = right_type;
400 result_type = left_type;
404 throw std::runtime_error(
"non-numeric operands in arithmetic operations.");
407 throw std::runtime_error(
"non-integer operands in modulo operation.");
426 *new_left_type = common_type;
428 *new_right_type = common_type;
434 result_type = common_type;
436 throw std::runtime_error(
"invalid binary operator type.");
446 return (type1_dict_key == type2_dict_key ||
447 (type1_dict_key.db_id == type2_dict_key.db_id &&
448 type1_dict_key.dict_id ==
TRANSIENT_DICT(type2_dict_key.dict_id)));
514 std::string timeinterval_op_error{
515 "Operator type not supported for time interval arithmetic: "};
520 throw std::runtime_error(timeinterval_op_error + type2.
get_type_name());
526 throw std::runtime_error(timeinterval_op_error + type1.
get_type_name());
751 return shared_from_this();
770 return sql_type_info_copy;
776 return shared_from_this();
782 return shared_from_this();
788 ". Consider using TRY_CAST instead.");
795 if (has_non_literal_operands && new_type_info.
is_string() &&
799 throw std::runtime_error(
800 "Implicit casts of TEXT ENCODING NONE to TEXT ENCODED DICT are not allowed "
801 "for non-literal arguments. Consider adding an explicit conversion to a "
802 "dictionary-encoded text type with ENCODE_TEXT(<none-encoded text arg>).");
804 throw std::runtime_error(
805 "Internal error: Cannot apply transient dictionary encoding "
806 "to non-literal expression.");
810 return makeExpr<UOper>(
819 template <
typename T>
821 static_assert(std::is_floating_point_v<T>);
831 template <
typename FLOAT_TYPE,
typename INT_TYPE>
833 static_assert(std::is_integral_v<INT_TYPE> && std::is_floating_point_v<FLOAT_TYPE>);
835 std::numeric_limits<INT_TYPE>::digits - std::numeric_limits<FLOAT_TYPE>::digits;
836 if constexpr (0 < dd) {
837 return static_cast<FLOAT_TYPE
>(std::numeric_limits<INT_TYPE>::max() - (1ll << dd));
839 return static_cast<FLOAT_TYPE
>(std::numeric_limits<INT_TYPE>::max());
843 template <
typename TO,
typename FROM>
845 static_assert(std::is_integral_v<TO> && std::is_integral_v<FROM>);
846 static_assert(
sizeof(TO) <
sizeof(FROM));
847 if (from < static_cast<FROM>(std::numeric_limits<TO>::min()) ||
848 static_cast<FROM>(std::numeric_limits<TO>::max()) < from) {
849 throw std::runtime_error(
"Overflow or underflow");
851 return static_cast<TO
>(from);
854 template <
typename T>
856 static_assert(std::is_integral_v<T>);
857 constexpr
size_t max_scale = std::numeric_limits<uint64_t>::digits10;
858 constexpr
auto pow10 = shared::powersOf<uint64_t, max_scale + 1>(10);
860 if constexpr (
sizeof(
T) <
sizeof(int64_t)) {
861 return safeNarrow<T>(
n);
865 }
else if (max_scale < scale) {
868 uint64_t
const u = std::abs(n);
869 uint64_t
const pow = pow10[scale];
870 uint64_t div = u / pow;
871 uint64_t rem = u % pow;
872 div += pow / 2 <= rem;
873 if constexpr (
sizeof(
T) <
sizeof(int64_t)) {
874 return safeNarrow<T>(
static_cast<int64_t
>(n < 0 ? -div : div));
876 return n < 0 ? -div : div;
880 template <
typename TO,
typename FROM>
882 static_assert(std::is_integral_v<TO> && std::is_floating_point_v<FROM>);
883 constexpr FROM max_float = maxRound<FROM, TO>();
884 FROM
const n = std::round(from);
885 if (n < static_cast<FROM>(std::numeric_limits<TO>::min()) || max_float < n) {
886 throw std::runtime_error(
"Overflow or underflow");
888 return static_cast<TO
>(
n);
892 template <
typename T>
894 static_assert(std::is_arithmetic_v<T>);
895 constexpr
size_t max_scale = std::numeric_limits<int64_t>::digits10;
896 constexpr
auto pow10 = shared::powersOf<int64_t, max_scale + 1>(10);
897 if constexpr (std::is_integral_v<T>) {
899 if (scale < pow10.size()) {
901 if (!__builtin_mul_overflow(from, pow10[scale], &retval)) {
906 return from * pow10[scale];
909 }
else if constexpr (std::is_floating_point_v<T>) {
910 if (scale < pow10.size()) {
911 return safeRound<int64_t>(from * pow10[scale]);
917 throw std::runtime_error(
"Overflow or underflow");
1009 switch (new_type_info.
get_type()) {
1037 switch (new_type_info.
get_type()) {
1065 switch (new_type_info.
get_type()) {
1094 switch (new_type_info.
get_type()) {
1130 switch (new_type_info.
get_type()) {
1151 for (
int i = 0; i < new_type_info.
get_scale(); i++) {
1160 switch (new_type_info.
get_type()) {
1183 for (
int i = 0; i < new_type_info.
get_scale(); i++) {
1200 static_cast<size_t>(new_type_info.
get_dimension()) < s->length()) {
1271 return constval.
arrayval ==
nullptr;
1338 throw std::runtime_error(
"Invalid array cast.");
1340 c->do_cast(new_sub_ti);
1420 return shared_from_this();
1432 const auto is_integral_type =
1439 return shared_from_this();
1472 std::list<std::pair<std::shared_ptr<Analyzer::Expr>, std::shared_ptr<Analyzer::Expr>>>
1475 new_expr_pair_list.emplace_back(
1476 std::make_pair(p.first, p.second->deep_copy()->add_cast(ti)));
1483 expr_pair_list = new_expr_pair_list;
1486 return shared_from_this();
1498 if (rte->get_rangevar() ==
name) {
1511 const std::list<std::shared_ptr<Analyzer::Expr>>& groupby)
const {
1512 if (!groupby.empty()) {
1513 for (
auto e : groupby) {
1514 auto c = std::dynamic_pointer_cast<
ColumnVar>(e);
1520 throw std::runtime_error(
1521 "expressions in the SELECT or HAVING clause must be an aggregate function or an "
1523 "over GROUP BY columns.");
1527 const std::list<std::shared_ptr<Analyzer::Expr>>& groupby)
const {
1529 throw std::runtime_error(
"Internal error: invalid VAR in GROUP BY or HAVING.");
1534 const std::list<std::shared_ptr<Analyzer::Expr>>& groupby)
const {
1535 operand->check_group_by(groupby);
1539 const std::list<std::shared_ptr<Analyzer::Expr>>& groupby)
const {
1547 bool expr_is(
const std::shared_ptr<Analyzer::Expr>& expr) {
1548 return std::dynamic_pointer_cast<
T>(expr) !=
nullptr;
1554 const std::shared_ptr<Analyzer::Expr> cast_operand,
1555 const std::shared_ptr<Analyzer::Expr> const_operand) {
1556 if (expr_is<UOper>(cast_operand) && expr_is<Constant>(const_operand)) {
1557 auto u_expr = std::dynamic_pointer_cast<
UOper>(cast_operand);
1558 if (u_expr->get_optype() !=
kCAST) {
1561 if (!(expr_is<Analyzer::ColumnVar>(u_expr->get_own_operand()) &&
1562 !expr_is<Analyzer::Var>(u_expr->get_own_operand()))) {
1566 if (ti.is_time() && u_expr->get_operand()->get_type_info().is_time()) {
1569 }
else if (ti.is_integer() && u_expr->get_operand()->get_type_info().is_integer()) {
1585 auto cv = std::dynamic_pointer_cast<
ColumnVar>(uo->get_own_operand());
1592 auto cv = std::dynamic_pointer_cast<
ColumnVar>(uo->get_own_operand());
1621 std::list<const Expr*>& join_predicates,
1622 std::list<const Expr*>& const_predicates)
const {
1624 scan_predicates.push_back(
this);
1629 std::list<const Expr*>& join_predicates,
1630 std::list<const Expr*>& const_predicates)
const {
1631 std::set<int> rte_idx_set;
1632 operand->collect_rte_idx(rte_idx_set);
1633 if (rte_idx_set.size() > 1) {
1634 join_predicates.push_back(
this);
1635 }
else if (rte_idx_set.size() == 1) {
1636 scan_predicates.push_back(
this);
1638 const_predicates.push_back(
this);
1643 std::list<const Expr*>& join_predicates,
1644 std::list<const Expr*>& const_predicates)
const {
1646 left_operand->group_predicates(scan_predicates, join_predicates, const_predicates);
1647 right_operand->group_predicates(scan_predicates, join_predicates, const_predicates);
1650 std::set<int> rte_idx_set;
1653 if (rte_idx_set.size() > 1) {
1654 join_predicates.push_back(
this);
1655 }
else if (rte_idx_set.size() == 1) {
1656 scan_predicates.push_back(
this);
1658 const_predicates.push_back(
this);
1674 const std::list<std::shared_ptr<Analyzer::Expr>>& l) {
1678 for (
const auto& v : l) {
1689 const std::list<std::shared_ptr<Analyzer::Expr>>& l)
1693 std::list<const Expr*>& join_predicates,
1694 std::list<const Expr*>& const_predicates)
const {
1695 std::set<int> rte_idx_set;
1696 arg->collect_rte_idx(rte_idx_set);
1697 if (rte_idx_set.size() > 1) {
1698 join_predicates.push_back(
this);
1699 }
else if (rte_idx_set.size() == 1) {
1700 scan_predicates.push_back(
this);
1702 const_predicates.push_back(
this);
1707 const std::vector<int64_t>& l,
1708 const bool not_null)
1712 std::list<const Expr*>& join_predicates,
1713 std::list<const Expr*>& const_predicates)
const {
1714 std::set<int> rte_idx_set;
1715 arg->collect_rte_idx(rte_idx_set);
1716 if (rte_idx_set.size() > 1) {
1717 join_predicates.push_back(
this);
1718 }
else if (rte_idx_set.size() == 1) {
1719 scan_predicates.push_back(
this);
1721 const_predicates.push_back(
this);
1726 std::list<const Expr*>& join_predicates,
1727 std::list<const Expr*>& const_predicates)
const {
1728 std::set<int> rte_idx_set;
1729 arg->collect_rte_idx(rte_idx_set);
1730 if (rte_idx_set.size() > 1) {
1731 join_predicates.push_back(
this);
1732 }
else if (rte_idx_set.size() == 1) {
1733 scan_predicates.push_back(
this);
1735 const_predicates.push_back(
this);
1740 std::list<const Expr*>& join_predicates,
1741 std::list<const Expr*>& const_predicates)
const {
1742 std::set<int> rte_idx_set;
1744 regressor_value->collect_rte_idx(rte_idx_set);
1746 if (rte_idx_set.size() > 1) {
1747 join_predicates.push_back(
this);
1748 }
else if (rte_idx_set.size() == 1) {
1749 scan_predicates.push_back(
this);
1751 const_predicates.push_back(
this);
1756 std::list<const Expr*>& join_predicates,
1757 std::list<const Expr*>& const_predicates)
const {
1758 std::set<int> rte_idx_set;
1760 feature_value->collect_rte_idx(rte_idx_set);
1762 if (rte_idx_set.size() > 1) {
1763 join_predicates.push_back(
this);
1764 }
else if (rte_idx_set.size() == 1) {
1765 scan_predicates.push_back(
this);
1767 const_predicates.push_back(
this);
1772 std::list<const Expr*>& join_predicates,
1773 std::list<const Expr*>& const_predicates)
const {
1774 std::set<int> rte_idx_set;
1775 arg->collect_rte_idx(rte_idx_set);
1776 if (rte_idx_set.size() > 1) {
1777 join_predicates.push_back(
this);
1778 }
else if (rte_idx_set.size() == 1) {
1779 scan_predicates.push_back(
this);
1781 const_predicates.push_back(
this);
1786 std::list<const Expr*>& join_predicates,
1787 std::list<const Expr*>& const_predicates)
const {
1788 std::set<int> rte_idx_set;
1789 for (
const auto& arg :
args_) {
1790 arg->collect_rte_idx(rte_idx_set);
1792 if (rte_idx_set.size() > 1) {
1793 join_predicates.push_back(
this);
1794 }
else if (rte_idx_set.size() == 1) {
1795 scan_predicates.push_back(
this);
1797 const_predicates.push_back(
this);
1802 std::list<const Expr*>& join_predicates,
1803 std::list<const Expr*>& const_predicates)
const {
1804 std::set<int> rte_idx_set;
1805 arg->collect_rte_idx(rte_idx_set);
1806 if (rte_idx_set.size() > 1) {
1807 join_predicates.push_back(
this);
1808 }
else if (rte_idx_set.size() == 1) {
1809 scan_predicates.push_back(
this);
1811 const_predicates.push_back(
this);
1816 std::list<const Expr*>& join_predicates,
1817 std::list<const Expr*>& const_predicates)
const {
1818 std::set<int> rte_idx_set;
1819 arg->collect_rte_idx(rte_idx_set);
1820 if (rte_idx_set.size() > 1) {
1821 join_predicates.push_back(
this);
1822 }
else if (rte_idx_set.size() == 1) {
1823 scan_predicates.push_back(
this);
1825 const_predicates.push_back(
this);
1830 std::list<const Expr*>& join_predicates,
1831 std::list<const Expr*>& const_predicates)
const {
1832 std::set<int> rte_idx_set;
1833 arg->collect_rte_idx(rte_idx_set);
1834 if (rte_idx_set.size() > 1) {
1835 join_predicates.push_back(
this);
1836 }
else if (rte_idx_set.size() == 1) {
1837 scan_predicates.push_back(
this);
1839 const_predicates.push_back(
this);
1844 std::list<const Expr*>& join_predicates,
1845 std::list<const Expr*>& const_predicates)
const {
1846 std::set<int> rte_idx_set;
1848 if (rte_idx_set.size() > 1) {
1849 join_predicates.push_back(
this);
1850 }
else if (rte_idx_set.size() == 1) {
1851 scan_predicates.push_back(
this);
1853 const_predicates.push_back(
this);
1858 std::list<const Expr*>& join_predicates,
1859 std::list<const Expr*>& const_predicates)
const {
1860 std::set<int> rte_idx_set;
1861 arg->collect_rte_idx(rte_idx_set);
1862 if (rte_idx_set.size() > 1) {
1863 join_predicates.push_back(
this);
1864 }
else if (rte_idx_set.size() == 1) {
1865 scan_predicates.push_back(
this);
1867 const_predicates.push_back(
this);
1872 std::list<const Expr*>& join_predicates,
1873 std::list<const Expr*>& const_predicates)
const {
1874 std::set<int> rte_idx_set;
1875 arg->collect_rte_idx(rte_idx_set);
1876 if (rte_idx_set.size() > 1) {
1877 join_predicates.push_back(
this);
1878 }
else if (rte_idx_set.size() == 1) {
1879 scan_predicates.push_back(
this);
1881 const_predicates.push_back(
this);
1886 std::list<const Expr*>& join_predicates,
1887 std::list<const Expr*>& const_predicates)
const {
1888 std::set<int> rte_idx_set;
1890 p.first->collect_rte_idx(rte_idx_set);
1891 p.second->collect_rte_idx(rte_idx_set);
1894 else_expr->collect_rte_idx(rte_idx_set);
1896 if (rte_idx_set.size() > 1) {
1897 join_predicates.push_back(
this);
1898 }
else if (rte_idx_set.size() == 1) {
1899 scan_predicates.push_back(
this);
1901 const_predicates.push_back(
this);
1906 std::list<const Expr*>& join_predicates,
1907 std::list<const Expr*>& const_predicates)
const {
1908 std::set<int> rte_idx_set;
1910 if (rte_idx_set.size() > 1) {
1911 join_predicates.push_back(
this);
1912 }
else if (rte_idx_set.size() == 1) {
1913 scan_predicates.push_back(
this);
1915 const_predicates.push_back(
this);
1920 std::list<const Expr*>& join_predicates,
1921 std::list<const Expr*>& const_predicates)
const {
1922 std::set<int> rte_idx_set;
1923 number_->collect_rte_idx(rte_idx_set);
1924 datetime_->collect_rte_idx(rte_idx_set);
1925 if (rte_idx_set.size() > 1) {
1926 join_predicates.push_back(
this);
1927 }
else if (rte_idx_set.size() == 1) {
1928 scan_predicates.push_back(
this);
1930 const_predicates.push_back(
this);
1935 std::list<const Expr*>& join_predicates,
1936 std::list<const Expr*>& const_predicates)
const {
1937 std::set<int> rte_idx_set;
1938 start_->collect_rte_idx(rte_idx_set);
1939 end_->collect_rte_idx(rte_idx_set);
1940 if (rte_idx_set.size() > 1) {
1941 join_predicates.push_back(
this);
1942 }
else if (rte_idx_set.size() == 1) {
1943 scan_predicates.push_back(
this);
1945 const_predicates.push_back(
this);
1950 std::list<const Expr*>& join_predicates,
1951 std::list<const Expr*>& const_predicates)
const {
1952 std::set<int> rte_idx_set;
1954 if (rte_idx_set.size() > 1) {
1955 join_predicates.push_back(
this);
1956 }
else if (rte_idx_set.size() == 1) {
1957 scan_predicates.push_back(
this);
1959 const_predicates.push_back(
this);
1964 const std::vector<std::shared_ptr<TargetEntry>>& tlist)
const {
1965 for (
auto tle : tlist) {
1966 const Expr* e = tle->get_expr();
1968 if (colvar !=
nullptr) {
1974 throw std::runtime_error(
"Internal error: cannot find ColumnVar in targetlist.");
1978 const std::vector<std::shared_ptr<TargetEntry>>& tlist)
const {
1980 for (
auto tle : tlist) {
1981 const Expr* e = tle->get_expr();
1983 if (colvar ==
nullptr) {
1984 throw std::runtime_error(
1985 "Internal Error: targetlist in rewrite_with_child_targetlist is not all "
1997 throw std::runtime_error(
"Internal error: cannot find ColumnVar in child targetlist.");
2001 const std::vector<std::shared_ptr<TargetEntry>>& tlist)
const {
2003 for (
auto tle : tlist) {
2004 const Expr* e = tle->get_expr();
2005 if (
typeid(*e) !=
typeid(
AggExpr)) {
2007 if (colvar ==
nullptr) {
2008 throw std::runtime_error(
2009 "Internal Error: targetlist in rewrite_agg_to_var is not all columns and "
2022 throw std::runtime_error(
2023 "Internal error: cannot find ColumnVar from having clause in targetlist.");
2027 const std::vector<std::shared_ptr<TargetEntry>>& tlist)
const {
2029 for (
auto tle : tlist) {
2030 const Expr* e = tle->get_expr();
2036 throw std::runtime_error(
2037 "Internal error: cannot find Var from having clause in targetlist.");
2041 const std::vector<std::shared_ptr<TargetEntry>>& tlist)
const {
2042 std::vector<std::shared_ptr<Analyzer::Expr>> rewritten_args;
2043 for (
const auto& arg :
args_) {
2044 rewritten_args.emplace_back(arg->rewrite_with_targetlist(tlist));
2046 return makeExpr<StringOper>(
kind_, rewritten_args);
2050 const std::vector<std::shared_ptr<TargetEntry>>& tlist)
const {
2051 std::vector<std::shared_ptr<Analyzer::Expr>> rewritten_args;
2052 for (
const auto& arg :
args_) {
2053 rewritten_args.emplace_back(arg->rewrite_with_child_targetlist(tlist));
2055 return makeExpr<StringOper>(
kind_, rewritten_args);
2059 const std::vector<std::shared_ptr<TargetEntry>>& tlist)
const {
2060 std::vector<std::shared_ptr<Analyzer::Expr>> rewritten_args;
2061 for (
const auto& arg :
args_) {
2062 rewritten_args.emplace_back(arg->rewrite_agg_to_var(tlist));
2064 return makeExpr<StringOper>(
kind_, rewritten_args);
2068 const std::vector<std::shared_ptr<TargetEntry>>& tlist)
const {
2069 std::list<std::shared_ptr<Analyzer::Expr>> new_value_list;
2071 new_value_list.push_back(v->deep_copy());
2073 return makeExpr<InValues>(
arg->rewrite_with_targetlist(tlist), new_value_list);
2077 const std::vector<std::shared_ptr<TargetEntry>>& tlist)
const {
2078 std::list<std::shared_ptr<Analyzer::Expr>> new_value_list;
2080 new_value_list.push_back(v->deep_copy());
2082 return makeExpr<InValues>(
arg->rewrite_with_child_targetlist(tlist), new_value_list);
2086 const std::vector<std::shared_ptr<TargetEntry>>& tlist)
const {
2087 std::list<std::shared_ptr<Analyzer::Expr>> new_value_list;
2089 new_value_list.push_back(v->rewrite_agg_to_var(tlist));
2091 return makeExpr<InValues>(
arg->rewrite_agg_to_var(tlist), new_value_list);
2095 const std::vector<std::shared_ptr<TargetEntry>>& tlist)
const {
2096 for (
auto tle : tlist) {
2097 const Expr* e = tle->get_expr();
2098 if (
typeid(*e) ==
typeid(
AggExpr)) {
2100 if (*
this == *agg) {
2105 throw std::runtime_error(
"Internal error: cannot find AggExpr in targetlist.");
2109 const std::vector<std::shared_ptr<TargetEntry>>& tlist)
const {
2112 arg ?
arg->rewrite_with_child_targetlist(tlist) :
nullptr,
2118 const std::vector<std::shared_ptr<TargetEntry>>& tlist)
const {
2120 for (
auto tle : tlist) {
2121 const Expr* e = tle->get_expr();
2122 if (
typeid(*e) ==
typeid(
AggExpr)) {
2124 if (*
this == *agg_expr) {
2130 throw std::runtime_error(
2131 "Internal error: cannot find AggExpr from having clause in targetlist.");
2135 const std::vector<std::shared_ptr<TargetEntry>>& tlist)
const {
2136 std::list<std::pair<std::shared_ptr<Analyzer::Expr>, std::shared_ptr<Analyzer::Expr>>>
2139 epair_list.emplace_back(p.first->rewrite_with_targetlist(tlist),
2140 p.second->rewrite_with_targetlist(tlist));
2142 return makeExpr<CaseExpr>(
2150 const std::vector<std::shared_ptr<TargetEntry>>& tlist)
const {
2151 return makeExpr<ExtractExpr>(
2156 const std::vector<std::shared_ptr<TargetEntry>>& tlist)
const {
2159 number_->rewrite_with_targetlist(tlist),
2160 datetime_->rewrite_with_targetlist(tlist));
2164 const std::vector<std::shared_ptr<TargetEntry>>& tlist)
const {
2165 return makeExpr<DatediffExpr>(
type_info,
2167 start_->rewrite_with_targetlist(tlist),
2168 end_->rewrite_with_targetlist(tlist));
2172 const std::vector<std::shared_ptr<TargetEntry>>& tlist)
const {
2173 return makeExpr<DatetruncExpr>(
2178 const std::vector<std::shared_ptr<TargetEntry>>& tlist)
const {
2179 std::list<std::pair<std::shared_ptr<Analyzer::Expr>, std::shared_ptr<Analyzer::Expr>>>
2182 epair_list.emplace_back(p.first->rewrite_with_child_targetlist(tlist),
2183 p.second->rewrite_with_child_targetlist(tlist));
2185 return makeExpr<CaseExpr>(
2193 const std::vector<std::shared_ptr<TargetEntry>>& tlist)
const {
2194 return makeExpr<ExtractExpr>(
2199 const std::vector<std::shared_ptr<TargetEntry>>& tlist)
const {
2202 number_->rewrite_with_child_targetlist(tlist),
2203 datetime_->rewrite_with_child_targetlist(tlist));
2207 const std::vector<std::shared_ptr<TargetEntry>>& tlist)
const {
2208 return makeExpr<DatediffExpr>(
type_info,
2210 start_->rewrite_with_child_targetlist(tlist),
2211 end_->rewrite_with_child_targetlist(tlist));
2215 const std::vector<std::shared_ptr<TargetEntry>>& tlist)
const {
2216 return makeExpr<DatetruncExpr>(
2221 const std::vector<std::shared_ptr<TargetEntry>>& tlist)
const {
2222 std::list<std::pair<std::shared_ptr<Analyzer::Expr>, std::shared_ptr<Analyzer::Expr>>>
2225 epair_list.emplace_back(p.first->rewrite_agg_to_var(tlist),
2226 p.second->rewrite_agg_to_var(tlist));
2235 const std::vector<std::shared_ptr<TargetEntry>>& tlist)
const {
2236 return makeExpr<ExtractExpr>(
2241 const std::vector<std::shared_ptr<TargetEntry>>& tlist)
const {
2244 number_->rewrite_agg_to_var(tlist),
2249 const std::vector<std::shared_ptr<TargetEntry>>& tlist)
const {
2250 return makeExpr<DatediffExpr>(
type_info,
2252 start_->rewrite_agg_to_var(tlist),
2253 end_->rewrite_agg_to_var(tlist));
2257 const std::vector<std::shared_ptr<TargetEntry>>& tlist)
const {
2258 return makeExpr<DatetruncExpr>(
2263 if (
typeid(rhs) !=
typeid(
ColumnVar) &&
typeid(rhs) !=
typeid(
Var)) {
2270 const Var* v =
dynamic_cast<const Var*
>(
this);
2274 const Var* rv =
dynamic_cast<const Var*
>(&rhs);
2275 if (rv ==
nullptr) {
2287 const auto& rhs_tuple_cols = rhs_tuple->
getTuple();
2327 throw std::runtime_error(
"Unrecognized type for Constant Datum equality: " +
2335 if (
typeid(rhs) !=
typeid(
Constant)) {
2352 if (
typeid(rhs) !=
typeid(
UOper)) {
2355 const UOper& rhs_uo =
dynamic_cast<const UOper&
>(rhs);
2360 if (
typeid(rhs) !=
typeid(
BinOper)) {
2427 if (!(*
regressor_values_[regressor_idx] == *rhs_regressor_values[regressor_idx])) {
2449 for (
size_t feature_idx = 0; feature_idx <
feature_values_.size(); ++feature_idx) {
2450 if (!(*
feature_values_[feature_idx] == *rhs_feature_values[feature_idx])) {
2469 if (
typeid(rhs) !=
typeid(
LikeExpr)) {
2540 if (
typeid(rhs) !=
typeid(
InValues)) {
2561 if (
typeid(rhs) !=
typeid(
AggExpr)) {
2571 if (
arg ==
nullptr || rhs_ae.
get_arg() ==
nullptr) {
2578 if (
typeid(rhs) !=
typeid(
CaseExpr)) {
2591 if (!(*p.first == *it->first) || !(*p.second == *it->second)) {
2652 const auto rhs_window =
dynamic_cast<const WindowFunction*
>(&rhs);
2656 if (
kind_ != rhs_window->kind_ ||
args_.size() != rhs_window->args_.size() ||
2658 order_keys_.size() != rhs_window->order_keys_.size() ||
2677 if (!(lhs_expr == rhs_expr)) {
2690 const auto rhs_geo =
dynamic_cast<const GeoUOper*
>(&rhs);
2694 if (
op_ != rhs_geo->getOp() ||
ti0_ != rhs_geo->getTypeInfo0() ||
2695 args0_.size() != rhs_geo->getArgs0().size()) {
2702 const auto rhs_geo =
dynamic_cast<const GeoBinOper*
>(&rhs);
2706 if (
op_ != rhs_geo->getOp() ||
ti0_ != rhs_geo->getTypeInfo0() ||
2707 args0_.size() != rhs_geo->getArgs0().size()) {
2710 if (
ti1_ != rhs_geo->getTypeInfo1() ||
args1_.size() != rhs_geo->getArgs1().size()) {
2718 std::stringstream ss;
2725 std::string str{
"< "};
2726 for (
const auto& column :
tuple_) {
2727 str += column->toString();
2734 std::stringstream ss;
2742 std::string str{
"(Const "};
2783 return "(" + op +
operand->toString() +
") ";
2832 op =
"BBOX_INTERSECT ";
2837 std::string str{
"("};
2853 return "(RangeOper " + lhs +
" " +
left_operand_->toString() +
" , " +
2858 std::stringstream ss;
2859 ss <<
"ML_PREDICT(Model: ";
2861 ss <<
" Regressors: ";
2863 ss << regressor_value->toString() <<
" ";
2870 std::stringstream ss;
2871 ss <<
"PCA_PROJECT(Model: ";
2873 ss <<
" Features: ";
2875 ss << feature_value->toString() <<
" ";
2877 ss <<
" PC Dimension: ";
2884 return "(Subquery ) ";
2888 std::string str{
"(IN "};
2889 str +=
arg->toString();
2892 bool shorted_value_list_str =
false;
2894 str += e->toString();
2897 shorted_value_list_str =
true;
2901 if (shorted_value_list_str) {
2903 str +=
"Total # values: ";
2915 if (!dynamic_cast<const InIntegerSet*>(&rhs)) {
2918 const auto& rhs_in_integer_set =
static_cast<const InIntegerSet&
>(rhs);
2919 return *
arg == *rhs_in_integer_set.arg &&
value_list == rhs_in_integer_set.value_list;
2923 std::string str{
"(IN_INTEGER_SET "};
2924 str +=
arg->toString();
2927 bool shorted_value_list_str =
false;
2932 shorted_value_list_str =
true;
2936 if (shorted_value_list_str) {
2938 str +=
"Total # values: ";
2948 str +=
"CHAR_LENGTH(";
2952 str +=
arg->toString();
2958 std::string str{
"KEY_FOR_STRING("};
2959 str +=
arg->toString();
2965 std::string str{
"SAMPLE_RATIO("};
2966 str +=
arg->toString();
2972 std::string str{
"CARDINALITY("};
2973 str +=
arg->toString();
2979 std::string str{
"(LIKE "};
2980 str +=
arg->toString();
2990 std::string str{
"(REGEXP "};
2991 str +=
arg->toString();
3001 std::string str{
"(WIDTH_BUCKET "};
3010 std::string str{
"(LIKELIHOOD "};
3011 str +=
arg->toString();
3034 agg =
"APPROX_COUNT_DISTINCT";
3037 agg =
"APPROX_PERCENTILE";
3040 agg =
"SINGLE_VALUE";
3058 std::string str{
"(" + agg};
3063 str +=
arg->toString();
3071 std::string str{
"CASE "};
3074 str += p.first->toString();
3076 str += p.second->toString();
3093 " DATETIME " +
datetime_->toString() +
") ";
3098 end_->toString() +
") ";
3106 return "(OffsetInFragment) ";
3110 std::ostringstream oss;
3117 std::ostringstream oss;
3118 oss <<
"WindowFunction(" <<
kind_;
3119 for (
const auto& arg :
args_) {
3120 oss <<
" " << arg->toString();
3135 <<
"Two bound types are supported for window framing: ROW and RANGE.";
3143 oss <<
" (RANGE BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW)";
3145 oss <<
" (RANGE BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING)";
3153 std::string str{
"ARRAY["};
3157 str += (*iter)->toString();
3180 fn =
"ST_IsConcaveHull";
3183 fn =
"ST_IsConvexHull";
3189 std::string
result = fn +
"(";
3190 for (
const auto& arg :
args0_) {
3191 result +=
" " + arg->toString();
3193 return result +
" ) ";
3200 fn =
"ST_Intersection";
3203 fn =
"ST_Difference";
3215 std::string
result = fn +
"(";
3217 for (
const auto& arg :
args0_) {
3218 result +=
" " + arg->toString();
3220 for (
const auto& arg :
args1_) {
3221 result +=
" " + arg->toString();
3223 return result +
" ) ";
3227 std::string str{
"(" +
resname +
" "};
3228 str +=
expr->toString();
3242 str +=
" nulls first";
3250 for (
auto e : expr_list) {
3255 expr_list.push_back(
this);
3259 std::list<const Expr*>& expr_list)
const {
3269 std::list<const Expr*>& expr_list)
const {
3278 std::list<const Expr*>& expr_list)
const {
3283 arg->find_expr(
f, expr_list);
3285 e->find_expr(
f, expr_list);
3290 std::list<const Expr*>& expr_list)
const {
3296 r->find_expr(
f, expr_list);
3301 std::list<const Expr*>& expr_list)
const {
3307 feature_value->find_expr(
f, expr_list);
3312 std::list<const Expr*>& expr_list)
const {
3317 arg->find_expr(
f, expr_list);
3321 std::list<const Expr*>& expr_list)
const {
3326 arg->find_expr(
f, expr_list);
3330 std::list<const Expr*>& expr_list)
const {
3335 arg->find_expr(
f, expr_list);
3339 std::list<const Expr*>& expr_list)
const {
3344 for (
const auto& arg :
args_) {
3345 arg->find_expr(
f, expr_list);
3350 std::list<const Expr*>& expr_list)
const {
3355 arg->find_expr(
f, expr_list);
3359 std::list<const Expr*>& expr_list)
const {
3364 arg->find_expr(
f, expr_list);
3372 std::list<const Expr*>& expr_list)
const {
3377 arg->find_expr(
f, expr_list);
3385 std::list<const Expr*>& expr_list)
const {
3397 std::list<const Expr*>& expr_list)
const {
3402 arg->find_expr(
f, expr_list);
3406 std::list<const Expr*>& expr_list)
const {
3411 if (
arg !=
nullptr) {
3412 arg->find_expr(
f, expr_list);
3417 std::list<const Expr*>& expr_list)
const {
3423 p.first->find_expr(
f, expr_list);
3424 p.second->find_expr(
f, expr_list);
3432 std::list<const Expr*>& expr_list)
const {
3441 std::list<const Expr*>& expr_list)
const {
3451 std::list<const Expr*>& expr_list)
const {
3456 start_->find_expr(
f, expr_list);
3457 end_->find_expr(
f, expr_list);
3461 std::list<const Expr*>& expr_list)
const {
3470 std::list<const Expr*>& expr_list)
const {
3475 for (
const auto& arg :
args_) {
3476 arg->find_expr(
f, expr_list);
3482 p.first->collect_rte_idx(rte_idx_set);
3483 p.second->collect_rte_idx(rte_idx_set);
3486 else_expr->collect_rte_idx(rte_idx_set);
3495 number_->collect_rte_idx(rte_idx_set);
3496 datetime_->collect_rte_idx(rte_idx_set);
3500 start_->collect_rte_idx(rte_idx_set);
3501 end_->collect_rte_idx(rte_idx_set);
3511 expr->collect_rte_idx(rte_idx_set);
3516 for (
const auto& arg :
args_) {
3517 arg->collect_rte_idx(rte_idx_set);
3522 for (
unsigned i = 0; i <
getArity(); i++) {
3523 const auto expr =
getArg(i);
3524 expr->collect_rte_idx(rte_idx_set);
3530 bool include_agg)
const {
3532 p.first->collect_column_var(colvar_set, include_agg);
3533 p.second->collect_column_var(colvar_set, include_agg);
3536 else_expr->collect_column_var(colvar_set, include_agg);
3542 bool include_agg)
const {
3543 from_expr_->collect_column_var(colvar_set, include_agg);
3548 bool include_agg)
const {
3549 number_->collect_column_var(colvar_set, include_agg);
3550 datetime_->collect_column_var(colvar_set, include_agg);
3555 bool include_agg)
const {
3556 start_->collect_column_var(colvar_set, include_agg);
3557 end_->collect_column_var(colvar_set, include_agg);
3562 bool include_agg)
const {
3563 from_expr_->collect_column_var(colvar_set, include_agg);
3568 bool include_agg)
const {
3571 expr->collect_column_var(colvar_set, include_agg);
3577 bool include_agg)
const {
3578 for (
const auto& arg :
args_) {
3579 arg->collect_column_var(colvar_set, include_agg);
3585 bool include_agg)
const {
3586 for (
unsigned i = 0; i <
getArity(); i++) {
3587 const auto expr =
getArg(i);
3588 expr->collect_column_var(colvar_set, include_agg);
3593 const std::list<std::shared_ptr<Analyzer::Expr>>& groupby)
const {
3595 p.first->check_group_by(groupby);
3596 p.second->check_group_by(groupby);
3604 const std::list<std::shared_ptr<Analyzer::Expr>>& groupby)
const {
3609 const std::list<std::shared_ptr<Analyzer::Expr>>& groupby)
const {
3610 number_->check_group_by(groupby);
3615 const std::list<std::shared_ptr<Analyzer::Expr>>& groupby)
const {
3616 start_->check_group_by(groupby);
3617 end_->check_group_by(groupby);
3621 const std::list<std::shared_ptr<Analyzer::Expr>>& groupby)
const {
3627 const auto c = std::dynamic_pointer_cast<
const Constant>(p.second);
3631 const auto v = std::dynamic_pointer_cast<
const ColumnVar>(p.second);
3635 const auto cast = std::dynamic_pointer_cast<
const UOper>(p.second);
3636 if (cast !=
nullptr && cast->get_optype() ==
kCAST) {
3642 const auto v = std::dynamic_pointer_cast<
const ColumnVar>(p.second);
3649 p.second->get_domain(domain_set);
3650 if (domain_set.empty()) {
3665 const auto cast = std::dynamic_pointer_cast<
const UOper>(
else_expr);
3666 if (cast !=
nullptr && cast->get_optype() ==
kCAST) {
3685 std::vector<std::shared_ptr<Analyzer::Expr>> args_copy;
3686 for (
const auto& arg :
args_) {
3687 args_copy.emplace_back(arg->deep_copy());
3689 std::vector<std::shared_ptr<Analyzer::Expr>> chained_string_op_exprs_copy;
3691 chained_string_op_exprs_copy.emplace_back(chained_string_op_expr->deep_copy());
3693 return makeExpr<Analyzer::StringOper>(
kind_,
3695 std::move(args_copy),
3696 std::move(chained_string_op_exprs_copy));
3700 return makeExpr<Analyzer::LowerStringOper>(
3705 return makeExpr<Analyzer::UpperStringOper>(
3710 return makeExpr<Analyzer::InitCapStringOper>(
3715 return makeExpr<Analyzer::ReverseStringOper>(
3720 return makeExpr<Analyzer::RepeatStringOper>(
3725 return makeExpr<Analyzer::PadStringOper>(
3730 return makeExpr<Analyzer::TrimStringOper>(
3735 return makeExpr<Analyzer::SubstringStringOper>(
3740 return makeExpr<Analyzer::ReplaceStringOper>(
3745 return makeExpr<Analyzer::OverlayStringOper>(
3750 return makeExpr<Analyzer::ConcatStringOper>(
3755 return makeExpr<Analyzer::SplitPartStringOper>(
3760 return makeExpr<Analyzer::RegexpReplaceStringOper>(
3765 return makeExpr<Analyzer::RegexpSubstrStringOper>(
3770 return makeExpr<Analyzer::RegexpCountStringOper>(
3775 return makeExpr<Analyzer::JsonValueStringOper>(
3780 return makeExpr<Analyzer::Base64EncodeStringOper>(
3785 return makeExpr<Analyzer::Base64DecodeStringOper>(
3790 return makeExpr<Analyzer::UrlEncodeStringOper>(
3795 return makeExpr<Analyzer::UrlDecodeStringOper>(
3800 return makeExpr<Analyzer::TryStringCastOper>(
3805 return makeExpr<Analyzer::PositionStringOper>(
3810 return makeExpr<Analyzer::JarowinklerSimilarityStringOper>(
3815 return makeExpr<Analyzer::LevenshteinDistanceStringOper>(
3820 return makeExpr<Analyzer::HashStringOper>(
3825 std::vector<std::shared_ptr<Analyzer::Expr>> args_copy;
3826 for (
size_t i = 0; i <
getArity(); ++i) {
3833 const auto rhs_string_oper =
dynamic_cast<const StringOper*
>(&rhs);
3835 if (!rhs_string_oper) {
3839 if (
get_kind() != rhs_string_oper->get_kind()) {
3842 if (
getArity() != rhs_string_oper->getArity()) {
3846 for (
size_t i = 0; i <
getArity(); ++i) {
3847 if (!(*
getArg(i) == *(rhs_string_oper->getArg(i)))) {
3852 rhs_string_oper->chained_string_op_exprs_.size()) {
3857 *(rhs_string_oper->chained_string_op_exprs_[i]))) {
3868 const auto rhs_func_oper =
dynamic_cast<const FunctionOper*
>(&rhs);
3869 if (!rhs_func_oper) {
3872 if (
getName() != rhs_func_oper->getName()) {
3875 if (
getArity() != rhs_func_oper->getArity()) {
3878 for (
size_t i = 0; i <
getArity(); ++i) {
3879 if (!(*
getArg(i) == *(rhs_func_oper->getArg(i)))) {
3888 for (
const auto& arg :
args_) {
3889 str += arg->toString();
3896 std::string str{
"(" +
name_ +
" "};
3897 for (
const auto& arg :
args_) {
3898 str += arg->toString();
3905 std::vector<std::shared_ptr<Analyzer::Expr>> args_copy;
3906 for (
size_t i = 0; i <
getArity(); ++i) {
3909 return makeExpr<Analyzer::FunctionOperWithCustomTypeHandling>(
3917 const auto rhs_func_oper =
3919 if (!rhs_func_oper) {
3922 if (
getName() != rhs_func_oper->getName()) {
3925 if (
getArity() != rhs_func_oper->getArity()) {
3928 for (
size_t i = 0; i <
getArity(); ++i) {
3929 if (!(*
getArg(i) == *(rhs_func_oper->getArg(i)))) {
3938 auto copied_expr = bound_expr->
deep_copy();
3941 auto casted_constant = std::dynamic_pointer_cast<
const Analyzer::Constant>(casted_expr);
3942 CHECK(casted_constant);
3943 return casted_constant->get_constval().doubleval;
3947 auto const_partition_count_expr =
3949 if (!const_partition_count_expr) {
3953 switch (const_partition_count_expr->get_type_info().get_type()) {
3955 return d.tinyintval;
3957 return d.smallintval;
3961 auto bi = d.bigintval;
3962 if (bi < 1 || bi > INT32_MAX) {
3976 int32_t
const partition_count,
3977 double const value) {
3978 if (value < lower_bound) {
3980 }
else if (upper_bound <= value) {
3981 return partition_count + 1;
3984 return static_cast<int32_t
>(partition_count * (value -
lower_bound) / width) + 1;
3998 if (lower_bound <= upper_bound) {
3999 return ordered_bucket(lower_bound, upper_bound, partition_count, target_const);
4001 return ordered_bucket(-lower_bound, -upper_bound, partition_count, -target_const);
4039 :
GeoExpr(ti), geo_(std::move(geo)) {
4042 throw std::runtime_error(
"Conflicting types for geo data " +
geo_->getWktString() +
4053 std::string str{
"(GeoConstant "};
4055 str +=
geo_->getWktString();
4062 return geo_->getWktString();
4088 const size_t index)
const {
4092 CHECK_LE(index,
size_t(num_phys_coords));
4095 std::vector<double> coords;
4096 std::vector<double> bounds;
4097 std::vector<int> ring_sizes;
4098 std::vector<int> poly_rings;
4100 const bool validate_with_geos_if_available =
false;
4108 validate_with_geos_if_available);
4110 std::ostringstream oss;
4111 oss <<
"Failed to create geometry from WKT string: " <<
geo_->getWktString();
4112 throw std::runtime_error(oss.str());
4141 throw std::runtime_error(
"Failed to transform constant geometry: " +
toString());
4147 return makeExpr<GeoConstant>(std::move(
geo_), cast_type_info);
4151 const std::string&
name,
4152 const std::vector<std::shared_ptr<Analyzer::Expr>>&
args,
4153 const std::optional<int>& output_srid_override)
4157 , output_srid_override_(output_srid_override) {}
4160 std::vector<std::shared_ptr<Analyzer::Expr>>
args;
4161 for (
size_t i = 0; i <
args_.size(); i++) {
4168 for (
size_t i = 0; i <
size(); i++) {
4170 expr->collect_rte_idx(rte_idx_set);
4176 bool include_agg)
const {
4177 for (
size_t i = 0; i <
size(); i++) {
4179 expr->collect_column_var(colvar_set, include_agg);
4184 std::string str{
"(" +
name_ +
" "};
4185 for (
const auto& arg :
args_) {
4186 str += arg->toString();
4203 for (
size_t i = 0; i <
size(); i++) {
4212 return args_.size();
4217 return args_[index].get();
4221 constexpr
bool geo_contains_agg =
false;
4223 std::vector<std::shared_ptr<Analyzer::Expr>>
args;
4224 for (
size_t i = 0; i <
args_.size(); i++) {
4232 return makeExpr<UOper>(trans_dict_type, geo_contains_agg,
kCAST,
deep_copy());
4234 return makeExpr<UOper>(new_type_info, geo_contains_agg,
kCAST,
deep_copy());
4239 std::vector<std::shared_ptr<Analyzer::Expr>>
args;
4240 for (
size_t i = 0; i <
args_.size(); i++) {
4243 return makeExpr<GeoTransformOperator>(
4248 std::string str{
"(" +
name_ +
" "};
4249 for (
const auto& arg :
args_) {
4250 str += arg->toString();
4269 for (
size_t i = 0; i <
size(); i++) {
4286 bool (*)(
const Analyzer::ColumnVar*,
const Analyzer::ColumnVar*)>
4287 colvar_set(comparator);
4289 if (colvar_set.size() != 1UL) {
4292 auto col_expr_ptr = *colvar_set.begin();
4293 CHECK(col_expr_ptr);
4294 return col_expr_ptr->get_type_info().is_dict_encoded_string();
4298 std::vector<size_t> literal_arg_indexes;
4299 const auto num_args =
args_.size();
4300 for (
size_t idx = 0; idx < num_args; ++idx) {
4301 if (dynamic_cast<const Constant*>(
args_[idx].
get())) {
4302 literal_arg_indexes.emplace_back(idx);
4305 return literal_arg_indexes;
4313 for (
size_t idx = 0; idx < num_args; ++idx) {
4315 if (constant_arg_expr) {
4316 literal_arg_map.emplace(
4318 std::make_pair(constant_arg_expr->get_type_info().get_type(),
4319 constant_arg_expr->get_constval())));
4322 return literal_arg_map;
4327 const std::vector<std::shared_ptr<Analyzer::Expr>>&
args) {
4329 <<
"get_return_type for TRY_STRING_CAST disallowed.";
4331 size_t num_var_string_inputs{0};
4332 for (
const auto& arg :
args) {
4333 const auto raw_arg = arg.get();
4334 const auto& arg_ti = arg->get_type_info();
4335 if (dynamic_cast<const Analyzer::CaseExpr*>(
remove_cast(raw_arg))) {
4344 }
else if (arg_ti.is_none_encoded_string()) {
4346 }
else if (arg_ti.is_dict_encoded_string()) {
4347 if (arg_ti.getStringDictKey().isTransientDict()) {
4350 num_var_string_inputs++;
4355 if (num_var_string_inputs > 1UL) {
4362 const size_t min_args,
4363 const std::vector<OperandTypeFamily>& expected_type_families,
4364 const std::vector<std::string>& arg_names,
4365 const bool dict_encoded_cols_only,
4366 const bool cols_first_arg_only)
const {
4367 std::ostringstream oss;
4370 throw std::runtime_error(oss.str());
4372 const size_t num_args =
args_.size();
4373 CHECK_EQ(expected_type_families.size(), arg_names.size());
4374 if (num_args < min_args || num_args > expected_type_families.size()) {
4376 oss <<
"Expected " << expected_type_families.size() <<
" arguments, but received "
4379 for (
size_t arg_idx = 0; arg_idx < num_args; ++arg_idx) {
4380 const auto& expected_type_family = expected_type_families[arg_idx];
4384 auto arg_ti =
args_[arg_idx]->get_type_info();
4386 const bool is_arg_case =
4390 <<
"Currently string operations cannot be run on output of a case "
4392 throw std::runtime_error(oss.str());
4394 const bool is_arg_constant =
4401 if (arg_ti != decasted_arg_ti &&
4402 (arg_ti.is_integer() && decasted_arg_ti.is_string())) {
4403 arg_ti = decasted_arg_ti;
4406 if (cols_first_arg_only && !is_arg_constant && arg_idx >= 1UL) {
4408 <<
"Currently only column inputs are allowed for argument '" << arg_names[0]
4409 <<
"', but a column input was received for argument '" << arg_names[arg_idx]
4411 throw std::runtime_error(oss.str());
4413 switch (expected_type_family) {
4415 if (!arg_ti.is_string()) {
4417 <<
"Expected text type for argument '" << arg_names[arg_idx] <<
"'";
4418 throw std::runtime_error(oss.str());
4421 if (dict_encoded_cols_only &&
4422 (!is_arg_constant && !arg_ti.is_dict_encoded_string())) {
4424 <<
"Currently only text-encoded dictionary-encoded column inputs are "
4425 <<
"allowed, but a none-encoded text column argument was received.";
4426 throw std::runtime_error(oss.str());
4434 <<
"Expected integer type for argument " << arg_idx + 1 <<
" ('"
4435 << arg_names[arg_idx] <<
"').";
4436 throw std::runtime_error(oss.str());
4439 if (!is_arg_constant) {
4441 <<
"Currently only text-encoded dictionary column inputs are "
4442 <<
"allowed, but an integer-type column was provided.";
4443 throw std::runtime_error(oss.str());
4453 const std::vector<std::shared_ptr<Analyzer::Expr>>& operands) {
4454 if (operands.size() != 2UL) {
4455 std::ostringstream oss;
4456 oss <<
"Concat operator expects two arguments, but was provided " << operands.size()
4458 throw std::runtime_error(oss.str());
4460 const auto operand0_is_literal =
4462 const auto operand1_is_literal =
4464 if (operand0_is_literal && !operand1_is_literal) {
4471 const std::vector<std::shared_ptr<Analyzer::Expr>>& operands) {
4474 return {operands[1], operands[0]};
4483 throw std::runtime_error(
"Invalid pad type supplied to PAD operator");
4490 const std::vector<std::shared_ptr<Analyzer::Expr>>&
args) {
4491 auto get_trim_type_if_exists = [&
args]() {
4496 if (!trim_type_arg) {
4499 const auto trim_type_str =
to_upper(*trim_type_arg->get_constval().stringval);
4500 if (trim_type_str ==
"BOTH") {
4503 if (trim_type_str ==
"LEADING") {
4506 if (trim_type_str ==
"TRAILING") {
4513 ? get_trim_type_if_exists()
4514 : trim_op_kind_maybe;
4516 return trim_op_kind;
4520 const std::vector<std::shared_ptr<Analyzer::Expr>>& operands,
4522 if (operands.size() < 2UL) {
4523 throw std::runtime_error(
"Trim operator expects 2 arguments.");
4535 if (dynamic_cast<const Analyzer::Constant*>(operands[0].
get()) &&
4537 return {operands[1], operands[0]};
4542 return {operands[2], operands[1]};
4546 const std::vector<std::shared_ptr<Analyzer::Expr>>& operands) {
4549 std::vector<std::shared_ptr<Analyzer::Expr>> normalized_operands;
4550 normalized_operands.emplace_back(operands[1]);
4551 normalized_operands.emplace_back(operands[0]);
4552 if (operands.size() == 3UL) {
4553 normalized_operands.emplace_back(operands[2]);
4555 return normalized_operands;
4558 std::vector<std::shared_ptr<Analyzer::Expr>>
4560 const std::vector<std::shared_ptr<Analyzer::Expr>>& operands) {
4561 if (operands.size() != 2UL) {
4562 std::ostringstream oss;
4563 oss <<
"JAROWINKLER_SIMILARITY operator expects two arguments, but was provided "
4564 << operands.size() <<
".";
4565 throw std::runtime_error(oss.str());
4567 const auto operand0_is_literal =
4569 const auto operand1_is_literal =
4571 if (operand0_is_literal && !operand1_is_literal) {
4572 return {operands[1], operands[0]};
4577 std::vector<std::shared_ptr<Analyzer::Expr>>
4579 const std::vector<std::shared_ptr<Analyzer::Expr>>& operands) {
4580 if (operands.size() != 2UL) {
4581 std::ostringstream oss;
4582 oss <<
"LEVENSHTEIN_DISTANCE operator expects two arguments, but was provided "
4583 << operands.size() <<
".";
4584 throw std::runtime_error(oss.str());
4586 const auto operand0_is_literal =
4588 const auto operand1_is_literal =
4590 if (operand0_is_literal && !operand1_is_literal) {
4591 return {operands[1], operands[0]};
4599 const std::vector<std::shared_ptr<Analyzer::Expr>>& rhs) {
4600 if (lhs.size() != rhs.size()) {
4603 for (
size_t i = 0; i < lhs.size(); ++i) {
4604 if (!(*lhs[i] == *rhs[i])) {
4611 std::shared_ptr<Analyzer::Expr>
remove_cast(
const std::shared_ptr<Analyzer::Expr>& expr) {
4613 if (!uoper || uoper->get_optype() !=
kCAST) {
4621 if (!uoper || uoper->get_optype() !=
kCAST) {
4624 return uoper->get_operand();
DEVICE auto upper_bound(ARGS &&...args)
std::shared_ptr< Analyzer::Expr > arg
std::shared_ptr< Analyzer::Expr > deep_copy() const override
std::shared_ptr< Analyzer::Expr > arg
Defines data structures for the semantic analysis phase of query processing.
InIntegerSet(const std::shared_ptr< const Analyzer::Expr > a, const std::vector< int64_t > &values, const bool not_null)
std::shared_ptr< Analyzer::Expr > rewrite_agg_to_var(const std::vector< std::shared_ptr< TargetEntry >> &tlist) const override
HOST DEVICE SQLTypes get_subtype() const
void set_compression(EncodingType c)
T roundDecimal(int64_t n, unsigned scale)
std::string toString() const override
double power10(unsigned const x)
float get_likelihood() const
static constexpr int32_t kMaxRepresentableNumericPrecision
std::shared_ptr< Analyzer::Expr > expr
std::string toString() const override
void find_expr(std::function< bool(const Expr *)> f, std::list< const Expr * > &expr_list) const override
void group_predicates(std::list< const Expr * > &scan_predicates, std::list< const Expr * > &join_predicates, std::list< const Expr * > &const_predicates) const override
InValues(std::shared_ptr< Analyzer::Expr > a, const std::list< std::shared_ptr< Analyzer::Expr >> &l)
static bool simple_predicate_has_simple_cast(const std::shared_ptr< Analyzer::Expr > cast_operand, const std::shared_ptr< Analyzer::Expr > const_operand)
const Expr * get_partition_count() const
std::shared_ptr< Analyzer::Expr > deep_copy() const override
bool operator==(const Expr &rhs) const override
std::string toString() const override
std::shared_ptr< Analyzer::Expr > deep_copy() const override
std::shared_ptr< Analyzer::Expr > deep_copy() const override
GeoConstant(std::unique_ptr< Geospatial::GeoBase > &&geo, const SQLTypeInfo &ti)
void get_domain(DomainSet &domain_set) const override
std::shared_ptr< Analyzer::Expr > rewrite_agg_to_var(const std::vector< std::shared_ptr< TargetEntry >> &tlist) const override
std::string toString() const final
bool operator==(const Expr &rhs) const override
const Expr * get_else_expr() const
std::shared_ptr< Analyzer::Expr > deep_copy() const override
bool operator==(const Expr &rhs) const override
std::shared_ptr< Analyzer::Expr > deep_copy() const override
static std::vector< std::shared_ptr< Analyzer::Expr > > normalize_operands(const std::vector< std::shared_ptr< Analyzer::Expr >> &operands)
std::shared_ptr< Analyzer::Expr > deep_copy() const override
bool operator==(const Expr &rhs) const override
bool Datum_equal(const SQLTypeInfo &ti, Datum val1, Datum val2)
std::string DatumToString(Datum d, const SQLTypeInfo &ti)
bool operator==(const Expr &rhs) const override
void check_operand_types(const size_t min_args, const std::vector< OperandTypeFamily > &expected_type_families, const std::vector< std::string > &arg_names, const bool dict_encoded_cols_only=false, const bool cols_first_arg_only=true) const
const Expr * get_escape_expr() const
std::shared_ptr< Analyzer::Expr > arg
void find_expr(std::function< bool(const Expr *)> f, std::list< const Expr * > &expr_list) const override
std::shared_ptr< Analyzer::Expr > rewrite_with_targetlist(const std::vector< std::shared_ptr< TargetEntry >> &tlist) const override
std::shared_ptr< Analyzer::Expr > decompress()
std::optional< int > output_srid_override_
std::shared_ptr< Analyzer::Expr > remove_cast(const std::shared_ptr< Analyzer::Expr > &expr)
bool is_null_value(const SQLTypeInfo &ti, const Datum &constval)
static bool colvar_comp(const ColumnVar *l, const ColumnVar *r)
const std::shared_ptr< Analyzer::Expr > frame_end_bound_
std::shared_ptr< Analyzer::Expr > deep_copy() const override
void add_rte(RangeTableEntry *rte)
bool is_timestamp() const
std::shared_ptr< Analyzer::Expr > operand
std::shared_ptr< Analyzer::Expr > deep_copy() const override
bool operator==(const Expr &rhs) const override
std::shared_ptr< Analyzer::Expr > arg
std::shared_ptr< Analyzer::Expr > deep_copy() const override
std::list< std::pair< std::shared_ptr< Analyzer::Expr >, std::shared_ptr< Analyzer::Expr > > > expr_pair_list
std::shared_ptr< Analyzer::Expr > rewrite_agg_to_var(const std::vector< std::shared_ptr< TargetEntry >> &tlist) const override
bool operator==(const Expr &rhs) const override
std::shared_ptr< Analyzer::Expr > deep_copy() const override
void find_expr(std::function< bool(const Expr *)> f, std::list< const Expr * > &expr_list) const override
void collect_rte_idx(std::set< int > &rte_idx_set) const final
std::shared_ptr< Analyzer::Expr > rewrite_with_child_targetlist(const std::vector< std::shared_ptr< TargetEntry >> &tlist) const override
bool operator==(const Expr &rhs) const override
void group_predicates(std::list< const Expr * > &scan_predicates, std::list< const Expr * > &join_predicates, std::list< const Expr * > &const_predicates) const override
virtual void add_unique(std::list< const Expr * > &expr_list) const
std::shared_ptr< Analyzer::Expr > right_operand
void find_expr(std::function< bool(const Expr *)> f, std::list< const Expr * > &expr_list) const override
std::shared_ptr< Analyzer::Expr > escape_expr
bool operator==(Expr const &rhs) const override
std::shared_ptr< Analyzer::Expr > rewrite_agg_to_var(const std::vector< std::shared_ptr< TargetEntry >> &tlist) const override
void group_predicates(std::list< const Expr * > &scan_predicates, std::list< const Expr * > &join_predicates, std::list< const Expr * > &const_predicates) const override
void collect_rte_idx(std::set< int > &rte_idx_set) const override
std::shared_ptr< Analyzer::Expr > deep_copy() const override
std::shared_ptr< Analyzer::Expr > deep_copy() const override
void collect_column_var(std::set< const ColumnVar *, bool(*)(const ColumnVar *, const ColumnVar *)> &colvar_set, bool include_agg) const override
const Expr * get_escape_expr() const
HOST DEVICE int get_scale() const
const Expr * get_right_operand() const
void group_predicates(std::list< const Expr * > &scan_predicates, std::list< const Expr * > &join_predicates, std::list< const Expr * > &const_predicates) const override
void collect_rte_idx(std::set< int > &rte_idx_set) const override
std::string toString() const override
shared::ColumnKey column_key_
std::map< size_t, std::pair< SQLTypes, Datum >> LiteralArgMap
std::shared_ptr< Analyzer::Expr > deep_copy() const override
SqlWindowFrameBoundType bound_type_
void find_expr(std::function< bool(const Expr *)> f, std::list< const Expr * > &expr_list) const override
std::string get_compression_name() const
DEVICE int64_t DateTruncate(DatetruncField field, const int64_t timeval)