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);
141 return makeExpr<KeyForStringExpr>(
arg->deep_copy());
145 return makeExpr<SampleRatioExpr>(
arg->deep_copy());
149 return makeExpr<CardinalityExpr>(
arg->deep_copy());
153 return makeExpr<LikeExpr>(
arg->deep_copy(),
161 return makeExpr<RegexpExpr>(
arg->deep_copy(),
174 return makeExpr<LikelihoodExpr>(
arg->deep_copy(),
likelihood);
178 return makeExpr<AggExpr>(
183 std::list<std::pair<std::shared_ptr<Analyzer::Expr>, std::shared_ptr<Analyzer::Expr>>>
186 new_list.emplace_back(p.first->deep_copy(), p.second->deep_copy());
191 else_expr ==
nullptr ?
nullptr : else_expr->deep_copy());
199 return makeExpr<DateaddExpr>(
204 return makeExpr<DatediffExpr>(
209 return makeExpr<DatetruncExpr>(
214 return makeExpr<OffsetInFragment>();
223 return makeExpr<WindowFunction>(
type_info,
235 return makeExpr<Analyzer::ArrayExpr>(
257 *new_left_type = left_type;
258 *new_right_type = right_type;
261 throw std::runtime_error(
262 "non-boolean operands cannot be used in logic operations.");
266 if (left_type != right_type) {
269 *new_left_type = common_type;
271 *new_right_type = common_type;
278 throw std::runtime_error(
"Cannont compare between TIMESTAMP and TIME.");
285 *new_right_type = *new_left_type;
307 throw std::runtime_error(
"Cannont compare between TIME and TIMESTAMP.");
310 throw std::runtime_error(
"Cannont compare between TIME and DATE.");
335 *new_right_type = *new_left_type;
343 *new_right_type = *new_left_type;
347 throw std::runtime_error(
"Cannont compare between DATE and TIME.");
357 *new_left_type = right_type;
359 *new_right_type = right_type;
361 *new_left_type = left_type;
362 *new_right_type = left_type;
365 *new_left_type = left_type;
366 *new_right_type = right_type;
370 *new_left_type = common_type;
371 *new_right_type = common_type;
373 throw std::runtime_error(
"Cannot compare between " + left_type.
get_type_name() +
378 }
else if (op ==
kMINUS &&
381 *new_left_type = left_type;
382 *new_right_type = right_type;
383 result_type = left_type;
387 throw std::runtime_error(
"non-numeric operands in arithmetic operations.");
390 throw std::runtime_error(
"non-integer operands in modulo operation.");
409 *new_left_type = common_type;
411 *new_right_type = common_type;
417 result_type = common_type;
419 throw std::runtime_error(
"invalid binary operator type.");
429 return (type1_dict_key == type2_dict_key ||
430 (type1_dict_key.db_id == type2_dict_key.db_id &&
431 type1_dict_key.dict_id ==
TRANSIENT_DICT(type2_dict_key.dict_id)));
497 std::string timeinterval_op_error{
498 "Operator type not supported for time interval arithmetic: "};
503 throw std::runtime_error(timeinterval_op_error + type2.
get_type_name());
509 throw std::runtime_error(timeinterval_op_error + type1.
get_type_name());
734 return shared_from_this();
748 return shared_from_this();
754 return shared_from_this();
760 ". Consider using TRY_CAST instead.");
767 if (has_non_literal_operands && new_type_info.
is_string() &&
771 throw std::runtime_error(
772 "Implict casts of TEXT ENCODING NONE to TEXT ENCODED DICT are not allowed "
773 "for non-literal arguments. Consider adding an explicit conversion to a "
774 "dictionary-encoded text type with ENCODE_TEXT(<none-encoded text arg>).");
776 throw std::runtime_error(
777 "Internal error: Cannot apply transient dictionary encoding "
778 "to non-literal expression.");
787 return makeExpr<UOper>(casted_new_type_info,
contains_agg,
kCAST, shared_from_this());
795 template <
typename T>
797 static_assert(std::is_floating_point_v<T>);
807 template <
typename FLOAT_TYPE,
typename INT_TYPE>
809 static_assert(std::is_integral_v<INT_TYPE> && std::is_floating_point_v<FLOAT_TYPE>);
811 std::numeric_limits<INT_TYPE>::digits - std::numeric_limits<FLOAT_TYPE>::digits;
812 if constexpr (0 < dd) {
813 return static_cast<FLOAT_TYPE
>(std::numeric_limits<INT_TYPE>::max() - (1ll << dd));
815 return static_cast<FLOAT_TYPE
>(std::numeric_limits<INT_TYPE>::max());
819 template <
typename TO,
typename FROM>
821 static_assert(std::is_integral_v<TO> && std::is_integral_v<FROM>);
822 static_assert(
sizeof(TO) <
sizeof(FROM));
823 if (from < static_cast<FROM>(std::numeric_limits<TO>::min()) ||
824 static_cast<FROM>(std::numeric_limits<TO>::max()) < from) {
825 throw std::runtime_error(
"Overflow or underflow");
827 return static_cast<TO
>(from);
830 template <
typename T>
832 static_assert(std::is_integral_v<T>);
833 constexpr
size_t max_scale = std::numeric_limits<uint64_t>::digits10;
834 constexpr
auto pow10 = shared::powersOf<uint64_t, max_scale + 1>(10);
836 if constexpr (
sizeof(
T) <
sizeof(int64_t)) {
837 return safeNarrow<T>(
n);
841 }
else if (max_scale < scale) {
844 uint64_t
const u = std::abs(n);
845 uint64_t
const pow = pow10[scale];
846 uint64_t div = u / pow;
847 uint64_t rem = u % pow;
848 div += pow / 2 <= rem;
849 if constexpr (
sizeof(
T) <
sizeof(int64_t)) {
850 return safeNarrow<T>(
static_cast<int64_t
>(n < 0 ? -div : div));
852 return n < 0 ? -div : div;
856 template <
typename TO,
typename FROM>
858 static_assert(std::is_integral_v<TO> && std::is_floating_point_v<FROM>);
859 constexpr FROM max_float = maxRound<FROM, TO>();
860 FROM
const n = std::round(from);
861 if (n < static_cast<FROM>(std::numeric_limits<TO>::min()) || max_float < n) {
862 throw std::runtime_error(
"Overflow or underflow");
864 return static_cast<TO
>(
n);
868 template <
typename T>
870 static_assert(std::is_arithmetic_v<T>);
871 constexpr
size_t max_scale = std::numeric_limits<int64_t>::digits10;
872 constexpr
auto pow10 = shared::powersOf<int64_t, max_scale + 1>(10);
873 if constexpr (std::is_integral_v<T>) {
875 if (scale < pow10.size()) {
877 if (!__builtin_mul_overflow(from, pow10[scale], &retval)) {
882 return from * pow10[scale];
885 }
else if constexpr (std::is_floating_point_v<T>) {
886 if (scale < pow10.size()) {
887 return safeRound<int64_t>(from * pow10[scale]);
893 throw std::runtime_error(
"Overflow or underflow");
1013 switch (new_type_info.
get_type()) {
1041 switch (new_type_info.
get_type()) {
1070 switch (new_type_info.
get_type()) {
1106 switch (new_type_info.
get_type()) {
1127 for (
int i = 0; i < new_type_info.
get_scale(); i++) {
1136 switch (new_type_info.
get_type()) {
1159 for (
int i = 0; i < new_type_info.
get_scale(); i++) {
1176 static_cast<size_t>(new_type_info.
get_dimension()) < s->length()) {
1247 return constval.
arrayval ==
nullptr;
1314 throw std::runtime_error(
"Invalid array cast.");
1316 c->do_cast(new_sub_ti);
1396 return shared_from_this();
1408 const auto is_integral_type =
1415 return shared_from_this();
1445 std::list<std::pair<std::shared_ptr<Analyzer::Expr>, std::shared_ptr<Analyzer::Expr>>>
1448 new_expr_pair_list.emplace_back(
1449 std::make_pair(p.first, p.second->deep_copy()->add_cast(ti)));
1456 expr_pair_list = new_expr_pair_list;
1459 return shared_from_this();
1471 if (rte->get_rangevar() ==
name) {
1484 const std::list<std::shared_ptr<Analyzer::Expr>>& groupby)
const {
1485 if (!groupby.empty()) {
1486 for (
auto e : groupby) {
1487 auto c = std::dynamic_pointer_cast<
ColumnVar>(e);
1493 throw std::runtime_error(
1494 "expressions in the SELECT or HAVING clause must be an aggregate function or an "
1496 "over GROUP BY columns.");
1500 const std::list<std::shared_ptr<Analyzer::Expr>>& groupby)
const {
1502 throw std::runtime_error(
"Internal error: invalid VAR in GROUP BY or HAVING.");
1507 const std::list<std::shared_ptr<Analyzer::Expr>>& groupby)
const {
1508 operand->check_group_by(groupby);
1512 const std::list<std::shared_ptr<Analyzer::Expr>>& groupby)
const {
1520 bool expr_is(
const std::shared_ptr<Analyzer::Expr>& expr) {
1521 return std::dynamic_pointer_cast<
T>(expr) !=
nullptr;
1527 const std::shared_ptr<Analyzer::Expr> cast_operand,
1528 const std::shared_ptr<Analyzer::Expr> const_operand) {
1529 if (expr_is<UOper>(cast_operand) && expr_is<Constant>(const_operand)) {
1530 auto u_expr = std::dynamic_pointer_cast<
UOper>(cast_operand);
1531 if (u_expr->get_optype() !=
kCAST) {
1534 if (!(expr_is<Analyzer::ColumnVar>(u_expr->get_own_operand()) &&
1535 !expr_is<Analyzer::Var>(u_expr->get_own_operand()))) {
1539 if (ti.is_time() && u_expr->get_operand()->get_type_info().is_time()) {
1542 }
else if (ti.is_integer() && u_expr->get_operand()->get_type_info().is_integer()) {
1558 auto cv = std::dynamic_pointer_cast<
ColumnVar>(uo->get_own_operand());
1565 auto cv = std::dynamic_pointer_cast<
ColumnVar>(uo->get_own_operand());
1594 std::list<const Expr*>& join_predicates,
1595 std::list<const Expr*>& const_predicates)
const {
1597 scan_predicates.push_back(
this);
1602 std::list<const Expr*>& join_predicates,
1603 std::list<const Expr*>& const_predicates)
const {
1604 std::set<int> rte_idx_set;
1605 operand->collect_rte_idx(rte_idx_set);
1606 if (rte_idx_set.size() > 1) {
1607 join_predicates.push_back(
this);
1608 }
else if (rte_idx_set.size() == 1) {
1609 scan_predicates.push_back(
this);
1611 const_predicates.push_back(
this);
1616 std::list<const Expr*>& join_predicates,
1617 std::list<const Expr*>& const_predicates)
const {
1619 left_operand->group_predicates(scan_predicates, join_predicates, const_predicates);
1620 right_operand->group_predicates(scan_predicates, join_predicates, const_predicates);
1623 std::set<int> rte_idx_set;
1626 if (rte_idx_set.size() > 1) {
1627 join_predicates.push_back(
this);
1628 }
else if (rte_idx_set.size() == 1) {
1629 scan_predicates.push_back(
this);
1631 const_predicates.push_back(
this);
1647 const std::list<std::shared_ptr<Analyzer::Expr>>& l) {
1651 for (
const auto& v : l) {
1662 const std::list<std::shared_ptr<Analyzer::Expr>>& l)
1666 std::list<const Expr*>& join_predicates,
1667 std::list<const Expr*>& const_predicates)
const {
1668 std::set<int> rte_idx_set;
1669 arg->collect_rte_idx(rte_idx_set);
1670 if (rte_idx_set.size() > 1) {
1671 join_predicates.push_back(
this);
1672 }
else if (rte_idx_set.size() == 1) {
1673 scan_predicates.push_back(
this);
1675 const_predicates.push_back(
this);
1680 const std::vector<int64_t>& l,
1681 const bool not_null)
1685 std::list<const Expr*>& join_predicates,
1686 std::list<const Expr*>& const_predicates)
const {
1687 std::set<int> rte_idx_set;
1688 arg->collect_rte_idx(rte_idx_set);
1689 if (rte_idx_set.size() > 1) {
1690 join_predicates.push_back(
this);
1691 }
else if (rte_idx_set.size() == 1) {
1692 scan_predicates.push_back(
this);
1694 const_predicates.push_back(
this);
1699 std::list<const Expr*>& join_predicates,
1700 std::list<const Expr*>& const_predicates)
const {
1701 std::set<int> rte_idx_set;
1702 arg->collect_rte_idx(rte_idx_set);
1703 if (rte_idx_set.size() > 1) {
1704 join_predicates.push_back(
this);
1705 }
else if (rte_idx_set.size() == 1) {
1706 scan_predicates.push_back(
this);
1708 const_predicates.push_back(
this);
1713 std::list<const Expr*>& join_predicates,
1714 std::list<const Expr*>& const_predicates)
const {
1715 std::set<int> rte_idx_set;
1716 arg->collect_rte_idx(rte_idx_set);
1717 if (rte_idx_set.size() > 1) {
1718 join_predicates.push_back(
this);
1719 }
else if (rte_idx_set.size() == 1) {
1720 scan_predicates.push_back(
this);
1722 const_predicates.push_back(
this);
1727 std::list<const Expr*>& join_predicates,
1728 std::list<const Expr*>& const_predicates)
const {
1729 std::set<int> rte_idx_set;
1730 for (
const auto& arg :
args_) {
1731 arg->collect_rte_idx(rte_idx_set);
1733 if (rte_idx_set.size() > 1) {
1734 join_predicates.push_back(
this);
1735 }
else if (rte_idx_set.size() == 1) {
1736 scan_predicates.push_back(
this);
1738 const_predicates.push_back(
this);
1743 std::list<const Expr*>& join_predicates,
1744 std::list<const Expr*>& const_predicates)
const {
1745 std::set<int> rte_idx_set;
1746 arg->collect_rte_idx(rte_idx_set);
1747 if (rte_idx_set.size() > 1) {
1748 join_predicates.push_back(
this);
1749 }
else if (rte_idx_set.size() == 1) {
1750 scan_predicates.push_back(
this);
1752 const_predicates.push_back(
this);
1757 std::list<const Expr*>& join_predicates,
1758 std::list<const Expr*>& const_predicates)
const {
1759 std::set<int> rte_idx_set;
1760 arg->collect_rte_idx(rte_idx_set);
1761 if (rte_idx_set.size() > 1) {
1762 join_predicates.push_back(
this);
1763 }
else if (rte_idx_set.size() == 1) {
1764 scan_predicates.push_back(
this);
1766 const_predicates.push_back(
this);
1771 std::list<const Expr*>& join_predicates,
1772 std::list<const Expr*>& const_predicates)
const {
1773 std::set<int> rte_idx_set;
1774 arg->collect_rte_idx(rte_idx_set);
1775 if (rte_idx_set.size() > 1) {
1776 join_predicates.push_back(
this);
1777 }
else if (rte_idx_set.size() == 1) {
1778 scan_predicates.push_back(
this);
1780 const_predicates.push_back(
this);
1785 std::list<const Expr*>& join_predicates,
1786 std::list<const Expr*>& const_predicates)
const {
1787 std::set<int> rte_idx_set;
1789 if (rte_idx_set.size() > 1) {
1790 join_predicates.push_back(
this);
1791 }
else if (rte_idx_set.size() == 1) {
1792 scan_predicates.push_back(
this);
1794 const_predicates.push_back(
this);
1799 std::list<const Expr*>& join_predicates,
1800 std::list<const Expr*>& const_predicates)
const {
1801 std::set<int> rte_idx_set;
1802 arg->collect_rte_idx(rte_idx_set);
1803 if (rte_idx_set.size() > 1) {
1804 join_predicates.push_back(
this);
1805 }
else if (rte_idx_set.size() == 1) {
1806 scan_predicates.push_back(
this);
1808 const_predicates.push_back(
this);
1813 std::list<const Expr*>& join_predicates,
1814 std::list<const Expr*>& const_predicates)
const {
1815 std::set<int> rte_idx_set;
1816 arg->collect_rte_idx(rte_idx_set);
1817 if (rte_idx_set.size() > 1) {
1818 join_predicates.push_back(
this);
1819 }
else if (rte_idx_set.size() == 1) {
1820 scan_predicates.push_back(
this);
1822 const_predicates.push_back(
this);
1827 std::list<const Expr*>& join_predicates,
1828 std::list<const Expr*>& const_predicates)
const {
1829 std::set<int> rte_idx_set;
1831 p.first->collect_rte_idx(rte_idx_set);
1832 p.second->collect_rte_idx(rte_idx_set);
1835 else_expr->collect_rte_idx(rte_idx_set);
1837 if (rte_idx_set.size() > 1) {
1838 join_predicates.push_back(
this);
1839 }
else if (rte_idx_set.size() == 1) {
1840 scan_predicates.push_back(
this);
1842 const_predicates.push_back(
this);
1847 std::list<const Expr*>& join_predicates,
1848 std::list<const Expr*>& const_predicates)
const {
1849 std::set<int> rte_idx_set;
1851 if (rte_idx_set.size() > 1) {
1852 join_predicates.push_back(
this);
1853 }
else if (rte_idx_set.size() == 1) {
1854 scan_predicates.push_back(
this);
1856 const_predicates.push_back(
this);
1861 std::list<const Expr*>& join_predicates,
1862 std::list<const Expr*>& const_predicates)
const {
1863 std::set<int> rte_idx_set;
1864 number_->collect_rte_idx(rte_idx_set);
1865 datetime_->collect_rte_idx(rte_idx_set);
1866 if (rte_idx_set.size() > 1) {
1867 join_predicates.push_back(
this);
1868 }
else if (rte_idx_set.size() == 1) {
1869 scan_predicates.push_back(
this);
1871 const_predicates.push_back(
this);
1876 std::list<const Expr*>& join_predicates,
1877 std::list<const Expr*>& const_predicates)
const {
1878 std::set<int> rte_idx_set;
1879 start_->collect_rte_idx(rte_idx_set);
1880 end_->collect_rte_idx(rte_idx_set);
1881 if (rte_idx_set.size() > 1) {
1882 join_predicates.push_back(
this);
1883 }
else if (rte_idx_set.size() == 1) {
1884 scan_predicates.push_back(
this);
1886 const_predicates.push_back(
this);
1891 std::list<const Expr*>& join_predicates,
1892 std::list<const Expr*>& const_predicates)
const {
1893 std::set<int> rte_idx_set;
1895 if (rte_idx_set.size() > 1) {
1896 join_predicates.push_back(
this);
1897 }
else if (rte_idx_set.size() == 1) {
1898 scan_predicates.push_back(
this);
1900 const_predicates.push_back(
this);
1905 const std::vector<std::shared_ptr<TargetEntry>>& tlist)
const {
1906 for (
auto tle : tlist) {
1907 const Expr* e = tle->get_expr();
1909 if (colvar !=
nullptr) {
1915 throw std::runtime_error(
"Internal error: cannot find ColumnVar in targetlist.");
1919 const std::vector<std::shared_ptr<TargetEntry>>& tlist)
const {
1921 for (
auto tle : tlist) {
1922 const Expr* e = tle->get_expr();
1924 if (colvar ==
nullptr) {
1925 throw std::runtime_error(
1926 "Internal Error: targetlist in rewrite_with_child_targetlist is not all "
1938 throw std::runtime_error(
"Internal error: cannot find ColumnVar in child targetlist.");
1942 const std::vector<std::shared_ptr<TargetEntry>>& tlist)
const {
1944 for (
auto tle : tlist) {
1945 const Expr* e = tle->get_expr();
1946 if (
typeid(*e) !=
typeid(
AggExpr)) {
1948 if (colvar ==
nullptr) {
1949 throw std::runtime_error(
1950 "Internal Error: targetlist in rewrite_agg_to_var is not all columns and "
1963 throw std::runtime_error(
1964 "Internal error: cannot find ColumnVar from having clause in targetlist.");
1968 const std::vector<std::shared_ptr<TargetEntry>>& tlist)
const {
1970 for (
auto tle : tlist) {
1971 const Expr* e = tle->get_expr();
1977 throw std::runtime_error(
1978 "Internal error: cannot find Var from having clause in targetlist.");
1982 const std::vector<std::shared_ptr<TargetEntry>>& tlist)
const {
1983 std::vector<std::shared_ptr<Analyzer::Expr>> rewritten_args;
1984 for (
const auto& arg :
args_) {
1985 rewritten_args.emplace_back(arg->rewrite_with_targetlist(tlist));
1987 return makeExpr<StringOper>(
kind_, rewritten_args);
1991 const std::vector<std::shared_ptr<TargetEntry>>& tlist)
const {
1992 std::vector<std::shared_ptr<Analyzer::Expr>> rewritten_args;
1993 for (
const auto& arg :
args_) {
1994 rewritten_args.emplace_back(arg->rewrite_with_child_targetlist(tlist));
1996 return makeExpr<StringOper>(
kind_, rewritten_args);
2000 const std::vector<std::shared_ptr<TargetEntry>>& tlist)
const {
2001 std::vector<std::shared_ptr<Analyzer::Expr>> rewritten_args;
2002 for (
const auto& arg :
args_) {
2003 rewritten_args.emplace_back(arg->rewrite_agg_to_var(tlist));
2005 return makeExpr<StringOper>(
kind_, rewritten_args);
2009 const std::vector<std::shared_ptr<TargetEntry>>& tlist)
const {
2010 std::list<std::shared_ptr<Analyzer::Expr>> new_value_list;
2012 new_value_list.push_back(v->deep_copy());
2014 return makeExpr<InValues>(
arg->rewrite_with_targetlist(tlist), new_value_list);
2018 const std::vector<std::shared_ptr<TargetEntry>>& tlist)
const {
2019 std::list<std::shared_ptr<Analyzer::Expr>> new_value_list;
2021 new_value_list.push_back(v->deep_copy());
2023 return makeExpr<InValues>(
arg->rewrite_with_child_targetlist(tlist), new_value_list);
2027 const std::vector<std::shared_ptr<TargetEntry>>& tlist)
const {
2028 std::list<std::shared_ptr<Analyzer::Expr>> new_value_list;
2030 new_value_list.push_back(v->rewrite_agg_to_var(tlist));
2032 return makeExpr<InValues>(
arg->rewrite_agg_to_var(tlist), new_value_list);
2036 const std::vector<std::shared_ptr<TargetEntry>>& tlist)
const {
2037 for (
auto tle : tlist) {
2038 const Expr* e = tle->get_expr();
2039 if (
typeid(*e) ==
typeid(
AggExpr)) {
2041 if (*
this == *agg) {
2046 throw std::runtime_error(
"Internal error: cannot find AggExpr in targetlist.");
2050 const std::vector<std::shared_ptr<TargetEntry>>& tlist)
const {
2053 arg ?
arg->rewrite_with_child_targetlist(tlist) :
nullptr,
2059 const std::vector<std::shared_ptr<TargetEntry>>& tlist)
const {
2061 for (
auto tle : tlist) {
2062 const Expr* e = tle->get_expr();
2063 if (
typeid(*e) ==
typeid(
AggExpr)) {
2065 if (*
this == *agg_expr) {
2071 throw std::runtime_error(
2072 "Internal error: cannot find AggExpr from having clause in targetlist.");
2076 const std::vector<std::shared_ptr<TargetEntry>>& tlist)
const {
2077 std::list<std::pair<std::shared_ptr<Analyzer::Expr>, std::shared_ptr<Analyzer::Expr>>>
2080 epair_list.emplace_back(p.first->rewrite_with_targetlist(tlist),
2081 p.second->rewrite_with_targetlist(tlist));
2083 return makeExpr<CaseExpr>(
2091 const std::vector<std::shared_ptr<TargetEntry>>& tlist)
const {
2092 return makeExpr<ExtractExpr>(
2097 const std::vector<std::shared_ptr<TargetEntry>>& tlist)
const {
2100 number_->rewrite_with_targetlist(tlist),
2101 datetime_->rewrite_with_targetlist(tlist));
2105 const std::vector<std::shared_ptr<TargetEntry>>& tlist)
const {
2106 return makeExpr<DatediffExpr>(
type_info,
2108 start_->rewrite_with_targetlist(tlist),
2109 end_->rewrite_with_targetlist(tlist));
2113 const std::vector<std::shared_ptr<TargetEntry>>& tlist)
const {
2114 return makeExpr<DatetruncExpr>(
2119 const std::vector<std::shared_ptr<TargetEntry>>& tlist)
const {
2120 std::list<std::pair<std::shared_ptr<Analyzer::Expr>, std::shared_ptr<Analyzer::Expr>>>
2123 epair_list.emplace_back(p.first->rewrite_with_child_targetlist(tlist),
2124 p.second->rewrite_with_child_targetlist(tlist));
2126 return makeExpr<CaseExpr>(
2134 const std::vector<std::shared_ptr<TargetEntry>>& tlist)
const {
2135 return makeExpr<ExtractExpr>(
2140 const std::vector<std::shared_ptr<TargetEntry>>& tlist)
const {
2143 number_->rewrite_with_child_targetlist(tlist),
2144 datetime_->rewrite_with_child_targetlist(tlist));
2148 const std::vector<std::shared_ptr<TargetEntry>>& tlist)
const {
2149 return makeExpr<DatediffExpr>(
type_info,
2151 start_->rewrite_with_child_targetlist(tlist),
2152 end_->rewrite_with_child_targetlist(tlist));
2156 const std::vector<std::shared_ptr<TargetEntry>>& tlist)
const {
2157 return makeExpr<DatetruncExpr>(
2162 const std::vector<std::shared_ptr<TargetEntry>>& tlist)
const {
2163 std::list<std::pair<std::shared_ptr<Analyzer::Expr>, std::shared_ptr<Analyzer::Expr>>>
2166 epair_list.emplace_back(p.first->rewrite_agg_to_var(tlist),
2167 p.second->rewrite_agg_to_var(tlist));
2176 const std::vector<std::shared_ptr<TargetEntry>>& tlist)
const {
2177 return makeExpr<ExtractExpr>(
2182 const std::vector<std::shared_ptr<TargetEntry>>& tlist)
const {
2185 number_->rewrite_agg_to_var(tlist),
2190 const std::vector<std::shared_ptr<TargetEntry>>& tlist)
const {
2191 return makeExpr<DatediffExpr>(
type_info,
2193 start_->rewrite_agg_to_var(tlist),
2194 end_->rewrite_agg_to_var(tlist));
2198 const std::vector<std::shared_ptr<TargetEntry>>& tlist)
const {
2199 return makeExpr<DatetruncExpr>(
2204 if (
typeid(rhs) !=
typeid(
ColumnVar) &&
typeid(rhs) !=
typeid(
Var)) {
2211 const Var* v =
dynamic_cast<const Var*
>(
this);
2215 const Var* rv =
dynamic_cast<const Var*
>(&rhs);
2216 if (rv ==
nullptr) {
2228 const auto& rhs_tuple_cols = rhs_tuple->
getTuple();
2268 throw std::runtime_error(
"Unrecognized type for Constant Datum equality: " +
2276 if (
typeid(rhs) !=
typeid(
Constant)) {
2293 if (
typeid(rhs) !=
typeid(
UOper)) {
2296 const UOper& rhs_uo =
dynamic_cast<const UOper&
>(rhs);
2301 if (
typeid(rhs) !=
typeid(
BinOper)) {
2366 if (
typeid(rhs) !=
typeid(
LikeExpr)) {
2437 if (
typeid(rhs) !=
typeid(
InValues)) {
2458 if (
typeid(rhs) !=
typeid(
AggExpr)) {
2468 if (
arg ==
nullptr || rhs_ae.
get_arg() ==
nullptr) {
2475 if (
typeid(rhs) !=
typeid(
CaseExpr)) {
2488 if (!(*p.first == *it->first) || !(*p.second == *it->second)) {
2549 const auto rhs_window =
dynamic_cast<const WindowFunction*
>(&rhs);
2553 if (
kind_ != rhs_window->kind_ ||
args_.size() != rhs_window->args_.size() ||
2555 order_keys_.size() != rhs_window->order_keys_.size() ||
2574 if (!(lhs_expr == rhs_expr)) {
2587 const auto rhs_geo =
dynamic_cast<const GeoUOper*
>(&rhs);
2591 if (
op_ != rhs_geo->getOp() ||
ti0_ != rhs_geo->getTypeInfo0() ||
2592 args0_.size() != rhs_geo->getArgs0().size()) {
2599 const auto rhs_geo =
dynamic_cast<const GeoBinOper*
>(&rhs);
2603 if (
op_ != rhs_geo->getOp() ||
ti0_ != rhs_geo->getTypeInfo0() ||
2604 args0_.size() != rhs_geo->getArgs0().size()) {
2607 if (
ti1_ != rhs_geo->getTypeInfo1() ||
args1_.size() != rhs_geo->getArgs1().size()) {
2615 std::stringstream ss;
2622 std::string str{
"< "};
2623 for (
const auto& column :
tuple_) {
2624 str += column->toString();
2631 std::stringstream ss;
2639 std::string str{
"(Const "};
2680 return "(" + op +
operand->toString() +
") ";
2734 std::string str{
"("};
2750 return "(RangeOper " + lhs +
" " +
left_operand_->toString() +
" , " +
2755 return "(Subquery ) ";
2759 std::string str{
"(IN "};
2760 str +=
arg->toString();
2763 bool shorted_value_list_str =
false;
2765 str += e->toString();
2768 shorted_value_list_str =
true;
2772 if (shorted_value_list_str) {
2774 str +=
"Total # values: ";
2786 if (!dynamic_cast<const InIntegerSet*>(&rhs)) {
2789 const auto& rhs_in_integer_set =
static_cast<const InIntegerSet&
>(rhs);
2790 return *
arg == *rhs_in_integer_set.arg &&
value_list == rhs_in_integer_set.value_list;
2794 std::string str{
"(IN_INTEGER_SET "};
2795 str +=
arg->toString();
2798 bool shorted_value_list_str =
false;
2803 shorted_value_list_str =
true;
2807 if (shorted_value_list_str) {
2809 str +=
"Total # values: ";
2819 str +=
"CHAR_LENGTH(";
2823 str +=
arg->toString();
2829 std::string str{
"KEY_FOR_STRING("};
2830 str +=
arg->toString();
2836 std::string str{
"SAMPLE_RATIO("};
2837 str +=
arg->toString();
2843 std::string str{
"CARDINALITY("};
2844 str +=
arg->toString();
2850 std::string str{
"(LIKE "};
2851 str +=
arg->toString();
2861 std::string str{
"(REGEXP "};
2862 str +=
arg->toString();
2872 std::string str{
"(WIDTH_BUCKET "};
2881 std::string str{
"(LIKELIHOOD "};
2882 str +=
arg->toString();
2905 agg =
"APPROX_COUNT_DISTINCT";
2908 agg =
"APPROX_PERCENTILE";
2911 agg =
"SINGLE_VALUE";
2929 std::string str{
"(" + agg};
2934 str +=
arg->toString();
2942 std::string str{
"CASE "};
2945 str += p.first->toString();
2947 str += p.second->toString();
2964 " DATETIME " +
datetime_->toString() +
") ";
2969 end_->toString() +
") ";
2977 return "(OffsetInFragment) ";
2987 for (
const auto& arg :
args_) {
2988 result +=
" " + arg->toString();
2991 result +=
" Frame{";
3003 <<
"Two bound types are supported for window framing: ROW and RANGE.";
3011 result +=
" (RANGE BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW)";
3013 result +=
" (RANGE BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING)";
3017 return result +
") ";
3021 std::string str{
"ARRAY["};
3025 str += (*iter)->toString();
3048 fn =
"ST_IsConcaveHull";
3051 fn =
"ST_IsConvexHull";
3057 std::string
result = fn +
"(";
3058 for (
const auto& arg :
args0_) {
3059 result +=
" " + arg->toString();
3061 return result +
" ) ";
3068 fn =
"ST_Intersection";
3071 fn =
"ST_Difference";
3083 std::string
result = fn +
"(";
3085 for (
const auto& arg :
args0_) {
3086 result +=
" " + arg->toString();
3088 for (
const auto& arg :
args1_) {
3089 result +=
" " + arg->toString();
3091 return result +
" ) ";
3095 std::string str{
"(" +
resname +
" "};
3096 str +=
expr->toString();
3110 str +=
" nulls first";
3118 for (
auto e : expr_list) {
3123 expr_list.push_back(
this);
3127 std::list<const Expr*>& expr_list)
const {
3137 std::list<const Expr*>& expr_list)
const {
3146 std::list<const Expr*>& expr_list)
const {
3151 arg->find_expr(
f, expr_list);
3153 e->find_expr(
f, expr_list);
3158 std::list<const Expr*>& expr_list)
const {
3163 arg->find_expr(
f, expr_list);
3167 std::list<const Expr*>& expr_list)
const {
3172 arg->find_expr(
f, expr_list);
3176 std::list<const Expr*>& expr_list)
const {
3181 arg->find_expr(
f, expr_list);
3185 std::list<const Expr*>& expr_list)
const {
3190 for (
const auto& arg :
args_) {
3191 arg->find_expr(
f, expr_list);
3196 std::list<const Expr*>& expr_list)
const {
3201 arg->find_expr(
f, expr_list);
3205 std::list<const Expr*>& expr_list)
const {
3210 arg->find_expr(
f, expr_list);
3218 std::list<const Expr*>& expr_list)
const {
3223 arg->find_expr(
f, expr_list);
3231 std::list<const Expr*>& expr_list)
const {
3243 std::list<const Expr*>& expr_list)
const {
3248 arg->find_expr(
f, expr_list);
3252 std::list<const Expr*>& expr_list)
const {
3257 if (
arg !=
nullptr) {
3258 arg->find_expr(
f, expr_list);
3263 std::list<const Expr*>& expr_list)
const {
3269 p.first->find_expr(
f, expr_list);
3270 p.second->find_expr(
f, expr_list);
3278 std::list<const Expr*>& expr_list)
const {
3287 std::list<const Expr*>& expr_list)
const {
3297 std::list<const Expr*>& expr_list)
const {
3302 start_->find_expr(
f, expr_list);
3303 end_->find_expr(
f, expr_list);
3307 std::list<const Expr*>& expr_list)
const {
3316 std::list<const Expr*>& expr_list)
const {
3321 for (
const auto& arg :
args_) {
3322 arg->find_expr(
f, expr_list);
3328 p.first->collect_rte_idx(rte_idx_set);
3329 p.second->collect_rte_idx(rte_idx_set);
3332 else_expr->collect_rte_idx(rte_idx_set);
3341 number_->collect_rte_idx(rte_idx_set);
3342 datetime_->collect_rte_idx(rte_idx_set);
3346 start_->collect_rte_idx(rte_idx_set);
3347 end_->collect_rte_idx(rte_idx_set);
3357 expr->collect_rte_idx(rte_idx_set);
3362 for (
const auto& arg :
args_) {
3363 arg->collect_rte_idx(rte_idx_set);
3368 for (
unsigned i = 0; i <
getArity(); i++) {
3369 const auto expr =
getArg(i);
3370 expr->collect_rte_idx(rte_idx_set);
3376 bool include_agg)
const {
3378 p.first->collect_column_var(colvar_set, include_agg);
3379 p.second->collect_column_var(colvar_set, include_agg);
3382 else_expr->collect_column_var(colvar_set, include_agg);
3388 bool include_agg)
const {
3389 from_expr_->collect_column_var(colvar_set, include_agg);
3394 bool include_agg)
const {
3395 number_->collect_column_var(colvar_set, include_agg);
3396 datetime_->collect_column_var(colvar_set, include_agg);
3401 bool include_agg)
const {
3402 start_->collect_column_var(colvar_set, include_agg);
3403 end_->collect_column_var(colvar_set, include_agg);
3408 bool include_agg)
const {
3409 from_expr_->collect_column_var(colvar_set, include_agg);
3414 bool include_agg)
const {
3417 expr->collect_column_var(colvar_set, include_agg);
3423 bool include_agg)
const {
3424 for (
const auto& arg :
args_) {
3425 arg->collect_column_var(colvar_set, include_agg);
3431 bool include_agg)
const {
3432 for (
unsigned i = 0; i <
getArity(); i++) {
3433 const auto expr =
getArg(i);
3434 expr->collect_column_var(colvar_set, include_agg);
3439 const std::list<std::shared_ptr<Analyzer::Expr>>& groupby)
const {
3441 p.first->check_group_by(groupby);
3442 p.second->check_group_by(groupby);
3450 const std::list<std::shared_ptr<Analyzer::Expr>>& groupby)
const {
3455 const std::list<std::shared_ptr<Analyzer::Expr>>& groupby)
const {
3456 number_->check_group_by(groupby);
3461 const std::list<std::shared_ptr<Analyzer::Expr>>& groupby)
const {
3462 start_->check_group_by(groupby);
3463 end_->check_group_by(groupby);
3467 const std::list<std::shared_ptr<Analyzer::Expr>>& groupby)
const {
3473 const auto c = std::dynamic_pointer_cast<
const Constant>(p.second);
3477 const auto v = std::dynamic_pointer_cast<
const ColumnVar>(p.second);
3481 const auto cast = std::dynamic_pointer_cast<
const UOper>(p.second);
3482 if (cast !=
nullptr && cast->get_optype() ==
kCAST) {
3488 const auto v = std::dynamic_pointer_cast<
const ColumnVar>(p.second);
3495 p.second->get_domain(domain_set);
3496 if (domain_set.empty()) {
3511 const auto cast = std::dynamic_pointer_cast<
const UOper>(
else_expr);
3512 if (cast !=
nullptr && cast->get_optype() ==
kCAST) {
3531 std::vector<std::shared_ptr<Analyzer::Expr>> args_copy;
3532 for (
const auto& arg :
args_) {
3533 args_copy.emplace_back(arg->deep_copy());
3535 std::vector<std::shared_ptr<Analyzer::Expr>> chained_string_op_exprs_copy;
3537 chained_string_op_exprs_copy.emplace_back(chained_string_op_expr->deep_copy());
3539 return makeExpr<Analyzer::StringOper>(
kind_,
3541 std::move(args_copy),
3542 std::move(chained_string_op_exprs_copy));
3546 return makeExpr<Analyzer::LowerStringOper>(
3551 return makeExpr<Analyzer::UpperStringOper>(
3556 return makeExpr<Analyzer::InitCapStringOper>(
3561 return makeExpr<Analyzer::ReverseStringOper>(
3566 return makeExpr<Analyzer::RepeatStringOper>(
3571 return makeExpr<Analyzer::PadStringOper>(
3576 return makeExpr<Analyzer::TrimStringOper>(
3581 return makeExpr<Analyzer::SubstringStringOper>(
3586 return makeExpr<Analyzer::ReplaceStringOper>(
3591 return makeExpr<Analyzer::OverlayStringOper>(
3596 return makeExpr<Analyzer::ConcatStringOper>(
3601 return makeExpr<Analyzer::SplitPartStringOper>(
3606 return makeExpr<Analyzer::RegexpReplaceStringOper>(
3611 return makeExpr<Analyzer::RegexpSubstrStringOper>(
3616 return makeExpr<Analyzer::JsonValueStringOper>(
3621 return makeExpr<Analyzer::Base64EncodeStringOper>(
3626 return makeExpr<Analyzer::Base64DecodeStringOper>(
3631 return makeExpr<Analyzer::TryStringCastOper>(
3636 return makeExpr<Analyzer::PositionStringOper>(
3641 std::vector<std::shared_ptr<Analyzer::Expr>> args_copy;
3642 for (
size_t i = 0; i <
getArity(); ++i) {
3649 const auto rhs_string_oper =
dynamic_cast<const StringOper*
>(&rhs);
3651 if (!rhs_string_oper) {
3655 if (
get_kind() != rhs_string_oper->get_kind()) {
3658 if (
getArity() != rhs_string_oper->getArity()) {
3662 for (
size_t i = 0; i <
getArity(); ++i) {
3663 if (!(*
getArg(i) == *(rhs_string_oper->getArg(i)))) {
3668 rhs_string_oper->chained_string_op_exprs_.size()) {
3673 *(rhs_string_oper->chained_string_op_exprs_[i]))) {
3684 const auto rhs_func_oper =
dynamic_cast<const FunctionOper*
>(&rhs);
3685 if (!rhs_func_oper) {
3688 if (
getName() != rhs_func_oper->getName()) {
3691 if (
getArity() != rhs_func_oper->getArity()) {
3694 for (
size_t i = 0; i <
getArity(); ++i) {
3695 if (!(*
getArg(i) == *(rhs_func_oper->getArg(i)))) {
3704 for (
const auto& arg :
args_) {
3705 str += arg->toString();
3712 std::string str{
"(" +
name_ +
" "};
3713 for (
const auto& arg :
args_) {
3714 str += arg->toString();
3721 std::vector<std::shared_ptr<Analyzer::Expr>> args_copy;
3722 for (
size_t i = 0; i <
getArity(); ++i) {
3725 return makeExpr<Analyzer::FunctionOperWithCustomTypeHandling>(
3733 const auto rhs_func_oper =
3735 if (!rhs_func_oper) {
3738 if (
getName() != rhs_func_oper->getName()) {
3741 if (
getArity() != rhs_func_oper->getArity()) {
3744 for (
size_t i = 0; i <
getArity(); ++i) {
3745 if (!(*
getArg(i) == *(rhs_func_oper->getArg(i)))) {
3754 auto copied_expr = bound_expr->
deep_copy();
3757 auto casted_constant = std::dynamic_pointer_cast<
const Analyzer::Constant>(casted_expr);
3758 CHECK(casted_constant);
3759 return casted_constant->get_constval().doubleval;
3763 auto const_partition_count_expr =
3765 if (!const_partition_count_expr) {
3769 switch (const_partition_count_expr->get_type_info().get_type()) {
3771 return d.tinyintval;
3773 return d.smallintval;
3777 auto bi = d.bigintval;
3778 if (bi < 1 || bi > INT32_MAX) {
3822 :
GeoExpr(ti), geo_(std::move(geo)) {
3825 throw std::runtime_error(
"Conflicting types for geo data " +
geo_->getWktString() +
3836 std::string str{
"(GeoConstant "};
3838 str +=
geo_->getWktString();
3845 return geo_->getWktString();
3871 const size_t index)
const {
3875 CHECK_LE(index,
size_t(num_phys_coords));
3878 std::vector<double> coords;
3879 std::vector<double> bounds;
3880 std::vector<int> ring_sizes;
3881 std::vector<int> poly_rings;
3884 geo_->getWktString(), ti, coords, bounds, ring_sizes, poly_rings);
3912 throw std::runtime_error(
"Failed to transform constant geometry: " +
toString());
3918 return makeExpr<GeoConstant>(std::move(
geo_), cast_type_info);
3922 const std::string&
name,
3923 const std::vector<std::shared_ptr<Analyzer::Expr>>&
args,
3924 const std::optional<int>& output_srid_override)
3928 , output_srid_override_(output_srid_override) {}
3931 std::vector<std::shared_ptr<Analyzer::Expr>>
args;
3932 for (
size_t i = 0; i <
args_.size(); i++) {
3939 for (
size_t i = 0; i <
size(); i++) {
3941 expr->collect_rte_idx(rte_idx_set);
3947 bool include_agg)
const {
3948 for (
size_t i = 0; i <
size(); i++) {
3950 expr->collect_column_var(colvar_set, include_agg);
3955 std::string str{
"(" +
name_ +
" "};
3956 for (
const auto& arg :
args_) {
3957 str += arg->toString();
3974 for (
size_t i = 0; i <
size(); i++) {
3983 return args_.size();
3988 return args_[index].get();
3993 std::vector<std::shared_ptr<Analyzer::Expr>>
args;
3994 for (
size_t i = 0; i <
args_.size(); i++) {
4001 return makeExpr<UOper>(new_type_info,
false,
kCAST, new_expr);
4006 std::vector<std::shared_ptr<Analyzer::Expr>>
args;
4007 for (
size_t i = 0; i <
args_.size(); i++) {
4010 return makeExpr<GeoTransformOperator>(
4015 std::string str{
"(" +
name_ +
" "};
4016 for (
const auto& arg :
args_) {
4017 str += arg->toString();
4036 for (
size_t i = 0; i <
size(); i++) {
4053 bool (*)(
const Analyzer::ColumnVar*,
const Analyzer::ColumnVar*)>
4054 colvar_set(comparator);
4056 if (colvar_set.size() != 1UL) {
4059 auto col_expr_ptr = *colvar_set.begin();
4060 CHECK(col_expr_ptr);
4061 return col_expr_ptr->get_type_info().is_dict_encoded_string();
4065 std::vector<size_t> literal_arg_indexes;
4066 const auto num_args =
args_.size();
4067 for (
size_t idx = 0; idx < num_args; ++idx) {
4068 if (dynamic_cast<const Constant*>(
args_[idx].
get())) {
4069 literal_arg_indexes.emplace_back(idx);
4072 return literal_arg_indexes;
4080 for (
size_t idx = 0; idx < num_args; ++idx) {
4082 if (constant_arg_expr) {
4083 literal_arg_map.emplace(
4085 std::make_pair(constant_arg_expr->get_type_info().get_type(),
4086 constant_arg_expr->get_constval())));
4089 return literal_arg_map;
4094 const std::vector<std::shared_ptr<Analyzer::Expr>>&
args) {
4096 <<
"get_return_type for TRY_STRING_CAST disallowed.";
4098 size_t num_var_string_inputs{0};
4099 for (
const auto& arg :
args) {
4100 const auto raw_arg = arg.get();
4101 const auto& arg_ti = arg->get_type_info();
4102 if (dynamic_cast<const Analyzer::CaseExpr*>(
remove_cast(raw_arg))) {
4111 }
else if (arg_ti.is_none_encoded_string()) {
4113 }
else if (arg_ti.is_dict_encoded_string()) {
4114 if (arg_ti.getStringDictKey().isTransientDict()) {
4117 num_var_string_inputs++;
4122 if (num_var_string_inputs > 1UL) {
4129 const size_t min_args,
4130 const std::vector<OperandTypeFamily>& expected_type_families,
4131 const std::vector<std::string>& arg_names,
4132 const bool dict_encoded_cols_only,
4133 const bool cols_first_arg_only)
const {
4134 std::ostringstream oss;
4137 throw std::runtime_error(oss.str());
4139 const size_t num_args =
args_.size();
4140 CHECK_EQ(expected_type_families.size(), arg_names.size());
4141 if (num_args < min_args || num_args > expected_type_families.size()) {
4143 oss <<
"Expected " << expected_type_families.size() <<
" arguments, but received "
4146 for (
size_t arg_idx = 0; arg_idx < num_args; ++arg_idx) {
4147 const auto& expected_type_family = expected_type_families[arg_idx];
4151 auto arg_ti =
args_[arg_idx]->get_type_info();
4153 const bool is_arg_case =
4157 <<
"Currently string operations cannot be run on output of a case "
4159 throw std::runtime_error(oss.str());
4161 const bool is_arg_constant =
4168 if (arg_ti != decasted_arg_ti &&
4169 (arg_ti.is_integer() && decasted_arg_ti.is_string())) {
4170 arg_ti = decasted_arg_ti;
4173 if (cols_first_arg_only && !is_arg_constant && arg_idx >= 1UL) {
4175 <<
"Currently only column inputs are allowed for argument '" << arg_names[0]
4176 <<
"', but a column input was received for argument '" << arg_names[arg_idx]
4178 throw std::runtime_error(oss.str());
4180 switch (expected_type_family) {
4182 if (!arg_ti.is_string()) {
4184 <<
"Expected text type for argument '" << arg_names[arg_idx] <<
"'";
4185 throw std::runtime_error(oss.str());
4188 if (dict_encoded_cols_only &&
4189 (!is_arg_constant && !arg_ti.is_dict_encoded_string())) {
4191 <<
"Currently only text-encoded dictionary-encoded column inputs are "
4192 <<
"allowed, but a none-encoded text column argument was received.";
4193 throw std::runtime_error(oss.str());
4201 <<
"Expected integer type for argument " << arg_idx + 1 <<
" ('"
4202 << arg_names[arg_idx] <<
"').";
4203 throw std::runtime_error(oss.str());
4206 if (!is_arg_constant) {
4208 <<
"Currently only text-encoded dictionary column inputs are "
4209 <<
"allowed, but an integer-type column was provided.";
4210 throw std::runtime_error(oss.str());
4220 const std::vector<std::shared_ptr<Analyzer::Expr>>& operands) {
4221 if (operands.size() != 2UL) {
4222 std::ostringstream oss;
4223 oss <<
"Concat operator expects two arguments, but was provided " << operands.size()
4225 throw std::runtime_error(oss.str());
4227 const auto operand0_is_literal =
4229 const auto operand1_is_literal =
4231 if (operand0_is_literal && !operand1_is_literal) {
4238 const std::vector<std::shared_ptr<Analyzer::Expr>>& operands) {
4241 return {operands[1], operands[0]};
4250 throw std::runtime_error(
"Invalid pad type supplied to PAD operator");
4257 const std::vector<std::shared_ptr<Analyzer::Expr>>&
args) {
4258 auto get_trim_type_if_exists = [&
args]() {
4263 if (!trim_type_arg) {
4266 const auto trim_type_str =
to_upper(*trim_type_arg->get_constval().stringval);
4267 if (trim_type_str ==
"BOTH") {
4270 if (trim_type_str ==
"LEADING") {
4273 if (trim_type_str ==
"TRAILING") {
4280 ? get_trim_type_if_exists()
4281 : trim_op_kind_maybe;
4283 return trim_op_kind;
4287 const std::vector<std::shared_ptr<Analyzer::Expr>>& operands,
4289 if (operands.size() < 2UL) {
4290 throw std::runtime_error(
"Trim operator expects 2 arguments.");
4302 if (dynamic_cast<const Analyzer::Constant*>(operands[0].
get()) &&
4304 return {operands[1], operands[0]};
4309 return {operands[2], operands[1]};
4313 const std::vector<std::shared_ptr<Analyzer::Expr>>& operands) {
4316 std::vector<std::shared_ptr<Analyzer::Expr>> normalized_operands;
4317 normalized_operands.emplace_back(operands[1]);
4318 normalized_operands.emplace_back(operands[0]);
4319 if (operands.size() == 3UL) {
4320 normalized_operands.emplace_back(operands[2]);
4322 return normalized_operands;
4327 const std::vector<std::shared_ptr<Analyzer::Expr>>& rhs) {
4328 if (lhs.size() != rhs.size()) {
4331 for (
size_t i = 0; i < lhs.size(); ++i) {
4332 if (!(*lhs[i] == *rhs[i])) {
4339 std::shared_ptr<Analyzer::Expr>
remove_cast(
const std::shared_ptr<Analyzer::Expr>& expr) {
4341 if (!uoper || uoper->get_optype() !=
kCAST) {
4349 if (!uoper || uoper->get_optype() !=
kCAST) {
4352 return uoper->get_operand();
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 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
bool operator==(const Expr &rhs) const override
std::string toString() 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
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)
int64_t DateTruncate(DatetruncField field, const int64_t timeval)
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
std::shared_ptr< Analyzer::Expr > arg
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
std::shared_ptr< Analyzer::Expr > arg
std::shared_ptr< Analyzer::Expr > deep_copy() const override
const std::vector< std::shared_ptr< Analyzer::Expr > > args0_
std::shared_ptr< Analyzer::Expr > like_expr
const std::vector< std::shared_ptr< Analyzer::Expr > > args0_
std::string toString() const override
void collect_column_var(std::set< const ColumnVar *, bool(*)(const ColumnVar *, const ColumnVar *)> &colvar_set, bool include_agg) const override
void find_expr(std::function< bool(const Expr *)> f, std::list< const Expr * > &expr_list) const override
void find_expr(std::function< bool(const Expr *)> f, std::list< const Expr * > &expr_list) const override
std::shared_ptr< Analyzer::Expr > deep_copy() const override
const std::shared_ptr< const Analyzer::Expr > arg
const std::shared_ptr< Analyzer::Expr > get_own_operand() const
std::shared_ptr< Analyzer::Expr > deep_copy() const override
std::shared_ptr< Analyzer::Expr > deep_copy() const override
void cast_from_string(const SQLTypeInfo &new_type_info)
std::shared_ptr< Analyzer::Expr > deep_copy() const override
void check_group_by(const std::list< std::shared_ptr< Analyzer::Expr >> &groupby) const override
std::string toString() const override
std::shared_ptr< Analyzer::Expr > add_cast(const SQLTypeInfo &new_type_info) override
std::shared_ptr< Analyzer::Expr > deep_copy() const override
std::shared_ptr< Analyzer::Expr > ExpressionPtr
const Geospatial::GeoBase::GeoOp op_
const Expr * get_arg() const
const std::vector< std::shared_ptr< Analyzer::Expr > > order_keys_
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
bool operator==(const Expr &rhs) const override
DatetruncField get_field() const
static SqlStringOpKind get_and_validate_trim_op_kind(const SqlStringOpKind trim_op_kind_maybe, const std::vector< std::shared_ptr< Analyzer::Expr >> &args)
const Expr * get_arg() const
bool is_expr_nullable(const Analyzer::Expr *expr)
std::shared_ptr< Analyzer::Expr > upper_bound_
Constants for Builtin SQL Types supported by HEAVY.AI.
std::shared_ptr< Analyzer::Expr > add_cast(const SQLTypeInfo &new_type_info) override
std::shared_ptr< Analyzer::Expr > arg
void find_expr(std::function< bool(const Expr *)> f, std::list< const Expr * > &expr_list) const override
bool operator==(const Expr &rhs) const override
std::shared_ptr< Analyzer::Expr > deep_copy() const override
std::shared_ptr< Analyzer::Expr > deep_copy() const override
const std::vector< std::shared_ptr< Analyzer::Expr > > args_
bool has_same_dict(const SQLTypeInfo &type1, const SQLTypeInfo &type2)
const std::vector< std::shared_ptr< Analyzer::Expr > > partition_keys_
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
void collect_rte_idx(std::set< int > &rte_idx_set) const override
bool operator==(const Expr &rhs) const override
HOST DEVICE SQLTypes get_type() const
std::unique_ptr< Geospatial::GeoBase > geo_
#define TRANSIENT_DICT_ID
std::shared_ptr< Analyzer::Expr > partition_count_
std::string toString() const override
constexpr int64_t get_datetime_scaled_epoch(const ScalingType direction, const int64_t epoch, const int32_t dimen)
std::string toString() const override
std::list< const Expr * > DomainSet
virtual void collect_column_var(std::set< const ColumnVar *, bool(*)(const ColumnVar *, const ColumnVar *)> &colvar_set, bool include_agg) const
const Expr * get_arg() const
TO safeRound(FROM const from)
std::string toString() const override
void check_group_by(const std::list< std::shared_ptr< Analyzer::Expr >> &groupby) const override
double get_bound_val(const Analyzer::Expr *bound_expr) const
bool operator==(const Expr &rhs) const override
int get_rte_idx(const std::string &range_var_name) const
void cast_string(const SQLTypeInfo &new_type_info)
const std::vector< std::shared_ptr< Analyzer::Expr > > args_
std::string toString() const override
std::vector< std::shared_ptr< Analyzer::Expr > > chained_string_op_exprs_
std::shared_ptr< Analyzer::Expr > deep_copy() const override
std::string toString() const override
std::shared_ptr< Analyzer::Expr > deep_copy() const override
bool operator==(const Expr &rhs) const override
bool g_enable_string_functions
std::string toString() const override
std::vector< size_t > getLiteralArgIndexes() const
std::string toString() const override
std::string toString() const override
bool get_calc_encoded_length() const
bool operator==(const Expr &rhs) const override
std::shared_ptr< Analyzer::Expr > rewrite_with_child_targetlist(const std::vector< std::shared_ptr< TargetEntry >> &tlist) const override
std::string toString() const override
std::shared_ptr< Analyzer::Expr > rewrite_with_targetlist(const std::vector< std::shared_ptr< TargetEntry >> &tlist) const override
const FrameBoundType frame_bound_type_
std::shared_ptr< Analyzer::Expr > deep_copy() const override
const Geospatial::GeoBase::GeoOp op_
std::string toString() const override
SQLOps get_optype() const
std::shared_ptr< Analyzer::Expr > left_operand