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.");
479 std::string timeinterval_op_error{
480 "Operator type not supported for time interval arithmetic: "};
485 throw std::runtime_error(timeinterval_op_error + type2.
get_type_name());
491 throw std::runtime_error(timeinterval_op_error + type1.
get_type_name());
716 return shared_from_this();
730 return shared_from_this();
737 return shared_from_this();
745 if (has_non_literal_operands && new_type_info.
is_string() &&
749 throw std::runtime_error(
750 "Implict casts of TEXT ENCODING NONE to TEXT ENCODED DICT are not allowed "
751 "for non-literal arguments. Consider adding an explicit conversion to a "
752 "dictionary-encoded text type with ENCODE_TEXT(<none-encoded text arg>).");
754 throw std::runtime_error(
755 "Internal error: Cannot apply transient dictionary encoding "
756 "to non-literal expression.");
764 template <
typename T>
766 static_assert(std::is_floating_point_v<T>);
776 template <
typename FLOAT_TYPE,
typename INT_TYPE>
778 static_assert(std::is_integral_v<INT_TYPE> && std::is_floating_point_v<FLOAT_TYPE>);
780 std::numeric_limits<INT_TYPE>::digits - std::numeric_limits<FLOAT_TYPE>::digits;
781 if constexpr (0 < dd) {
782 return static_cast<FLOAT_TYPE
>(std::numeric_limits<INT_TYPE>::max() - (1ll << dd));
784 return static_cast<FLOAT_TYPE
>(std::numeric_limits<INT_TYPE>::max());
788 template <
typename TO,
typename FROM>
790 static_assert(std::is_integral_v<TO> && std::is_integral_v<FROM>);
791 static_assert(
sizeof(TO) <
sizeof(FROM));
792 if (from < static_cast<FROM>(std::numeric_limits<TO>::min()) ||
793 static_cast<FROM>(std::numeric_limits<TO>::max()) < from) {
794 throw std::runtime_error(
"Overflow or underflow");
796 return static_cast<TO
>(from);
799 template <
typename T>
801 static_assert(std::is_integral_v<T>);
802 constexpr
size_t max_scale = std::numeric_limits<uint64_t>::digits10;
803 constexpr
auto pow10 = shared::powersOf<uint64_t, max_scale + 1>(10);
805 if constexpr (
sizeof(
T) <
sizeof(int64_t)) {
806 return safeNarrow<T>(
n);
810 }
else if (max_scale < scale) {
813 uint64_t
const u = std::abs(n);
814 uint64_t
const pow = pow10[scale];
815 uint64_t div = u / pow;
816 uint64_t rem = u % pow;
817 div += pow / 2 <= rem;
818 if constexpr (
sizeof(
T) <
sizeof(int64_t)) {
819 return safeNarrow<T>(
static_cast<int64_t
>(n < 0 ? -div : div));
821 return n < 0 ? -div : div;
825 template <
typename TO,
typename FROM>
827 static_assert(std::is_integral_v<TO> && std::is_floating_point_v<FROM>);
828 constexpr FROM max_float = maxRound<FROM, TO>();
829 FROM
const n = std::round(from);
830 if (n < static_cast<FROM>(std::numeric_limits<TO>::min()) || max_float < n) {
831 throw std::runtime_error(
"Overflow or underflow");
833 return static_cast<TO
>(
n);
837 template <
typename T>
839 static_assert(std::is_arithmetic_v<T>);
840 constexpr
size_t max_scale = std::numeric_limits<int64_t>::digits10;
841 constexpr
auto pow10 = shared::powersOf<int64_t, max_scale + 1>(10);
842 if constexpr (std::is_integral_v<T>) {
844 if (scale < pow10.size()) {
846 if (!__builtin_mul_overflow(from, pow10[scale], &retval)) {
851 return from * pow10[scale];
854 }
else if constexpr (std::is_floating_point_v<T>) {
855 if (scale < pow10.size()) {
856 return safeRound<int64_t>(from * pow10[scale]);
862 throw std::runtime_error(
"Overflow or underflow");
1010 switch (new_type_info.
get_type()) {
1039 switch (new_type_info.
get_type()) {
1075 switch (new_type_info.
get_type()) {
1096 for (
int i = 0; i < new_type_info.
get_scale(); i++) {
1105 switch (new_type_info.
get_type()) {
1128 for (
int i = 0; i < new_type_info.
get_scale(); i++) {
1145 static_cast<size_t>(new_type_info.
get_dimension()) < s->length()) {
1214 return constval.
arrayval ==
nullptr;
1281 throw std::runtime_error(
"Invalid array cast.");
1283 c->do_cast(new_sub_ti);
1363 return shared_from_this();
1375 const auto is_integral_type =
1382 return shared_from_this();
1413 std::list<std::pair<std::shared_ptr<Analyzer::Expr>, std::shared_ptr<Analyzer::Expr>>>
1416 new_expr_pair_list.emplace_back(
1417 std::make_pair(p.first, p.second->deep_copy()->add_cast(ti)));
1424 expr_pair_list = new_expr_pair_list;
1427 return shared_from_this();
1439 if (rte->get_rangevar() ==
name) {
1452 const std::list<std::shared_ptr<Analyzer::Expr>>& groupby)
const {
1453 if (!groupby.empty()) {
1454 for (
auto e : groupby) {
1455 auto c = std::dynamic_pointer_cast<
ColumnVar>(e);
1461 throw std::runtime_error(
1462 "expressions in the SELECT or HAVING clause must be an aggregate function or an "
1464 "over GROUP BY columns.");
1468 const std::list<std::shared_ptr<Analyzer::Expr>>& groupby)
const {
1470 throw std::runtime_error(
"Internal error: invalid VAR in GROUP BY or HAVING.");
1475 const std::list<std::shared_ptr<Analyzer::Expr>>& groupby)
const {
1476 operand->check_group_by(groupby);
1480 const std::list<std::shared_ptr<Analyzer::Expr>>& groupby)
const {
1488 bool expr_is(
const std::shared_ptr<Analyzer::Expr>& expr) {
1489 return std::dynamic_pointer_cast<
T>(expr) !=
nullptr;
1495 const std::shared_ptr<Analyzer::Expr> cast_operand,
1496 const std::shared_ptr<Analyzer::Expr> const_operand) {
1497 if (expr_is<UOper>(cast_operand) && expr_is<Constant>(const_operand)) {
1498 auto u_expr = std::dynamic_pointer_cast<
UOper>(cast_operand);
1499 if (u_expr->get_optype() !=
kCAST) {
1502 if (!(expr_is<Analyzer::ColumnVar>(u_expr->get_own_operand()) &&
1503 !expr_is<Analyzer::Var>(u_expr->get_own_operand()))) {
1507 if (ti.is_time() && u_expr->get_operand()->get_type_info().is_time()) {
1510 }
else if (ti.is_integer() && u_expr->get_operand()->get_type_info().is_integer()) {
1526 auto cv = std::dynamic_pointer_cast<
ColumnVar>(uo->get_own_operand());
1533 auto cv = std::dynamic_pointer_cast<
ColumnVar>(uo->get_own_operand());
1562 std::list<const Expr*>& join_predicates,
1563 std::list<const Expr*>& const_predicates)
const {
1565 scan_predicates.push_back(
this);
1570 std::list<const Expr*>& join_predicates,
1571 std::list<const Expr*>& const_predicates)
const {
1572 std::set<int> rte_idx_set;
1573 operand->collect_rte_idx(rte_idx_set);
1574 if (rte_idx_set.size() > 1) {
1575 join_predicates.push_back(
this);
1576 }
else if (rte_idx_set.size() == 1) {
1577 scan_predicates.push_back(
this);
1579 const_predicates.push_back(
this);
1584 std::list<const Expr*>& join_predicates,
1585 std::list<const Expr*>& const_predicates)
const {
1587 left_operand->group_predicates(scan_predicates, join_predicates, const_predicates);
1588 right_operand->group_predicates(scan_predicates, join_predicates, const_predicates);
1591 std::set<int> rte_idx_set;
1594 if (rte_idx_set.size() > 1) {
1595 join_predicates.push_back(
this);
1596 }
else if (rte_idx_set.size() == 1) {
1597 scan_predicates.push_back(
this);
1599 const_predicates.push_back(
this);
1615 const std::list<std::shared_ptr<Analyzer::Expr>>& l) {
1619 for (
const auto& v : l) {
1630 const std::list<std::shared_ptr<Analyzer::Expr>>& l)
1634 std::list<const Expr*>& join_predicates,
1635 std::list<const Expr*>& const_predicates)
const {
1636 std::set<int> rte_idx_set;
1637 arg->collect_rte_idx(rte_idx_set);
1638 if (rte_idx_set.size() > 1) {
1639 join_predicates.push_back(
this);
1640 }
else if (rte_idx_set.size() == 1) {
1641 scan_predicates.push_back(
this);
1643 const_predicates.push_back(
this);
1648 const std::vector<int64_t>& l,
1649 const bool not_null)
1653 std::list<const Expr*>& join_predicates,
1654 std::list<const Expr*>& const_predicates)
const {
1655 std::set<int> rte_idx_set;
1656 arg->collect_rte_idx(rte_idx_set);
1657 if (rte_idx_set.size() > 1) {
1658 join_predicates.push_back(
this);
1659 }
else if (rte_idx_set.size() == 1) {
1660 scan_predicates.push_back(
this);
1662 const_predicates.push_back(
this);
1667 std::list<const Expr*>& join_predicates,
1668 std::list<const Expr*>& const_predicates)
const {
1669 std::set<int> rte_idx_set;
1670 arg->collect_rte_idx(rte_idx_set);
1671 if (rte_idx_set.size() > 1) {
1672 join_predicates.push_back(
this);
1673 }
else if (rte_idx_set.size() == 1) {
1674 scan_predicates.push_back(
this);
1676 const_predicates.push_back(
this);
1681 std::list<const Expr*>& join_predicates,
1682 std::list<const Expr*>& const_predicates)
const {
1683 std::set<int> rte_idx_set;
1684 arg->collect_rte_idx(rte_idx_set);
1685 if (rte_idx_set.size() > 1) {
1686 join_predicates.push_back(
this);
1687 }
else if (rte_idx_set.size() == 1) {
1688 scan_predicates.push_back(
this);
1690 const_predicates.push_back(
this);
1695 std::list<const Expr*>& join_predicates,
1696 std::list<const Expr*>& const_predicates)
const {
1697 std::set<int> rte_idx_set;
1698 for (
const auto& arg :
args_) {
1699 arg->collect_rte_idx(rte_idx_set);
1701 if (rte_idx_set.size() > 1) {
1702 join_predicates.push_back(
this);
1703 }
else if (rte_idx_set.size() == 1) {
1704 scan_predicates.push_back(
this);
1706 const_predicates.push_back(
this);
1711 std::list<const Expr*>& join_predicates,
1712 std::list<const Expr*>& const_predicates)
const {
1713 std::set<int> rte_idx_set;
1714 arg->collect_rte_idx(rte_idx_set);
1715 if (rte_idx_set.size() > 1) {
1716 join_predicates.push_back(
this);
1717 }
else if (rte_idx_set.size() == 1) {
1718 scan_predicates.push_back(
this);
1720 const_predicates.push_back(
this);
1725 std::list<const Expr*>& join_predicates,
1726 std::list<const Expr*>& const_predicates)
const {
1727 std::set<int> rte_idx_set;
1728 arg->collect_rte_idx(rte_idx_set);
1729 if (rte_idx_set.size() > 1) {
1730 join_predicates.push_back(
this);
1731 }
else if (rte_idx_set.size() == 1) {
1732 scan_predicates.push_back(
this);
1734 const_predicates.push_back(
this);
1739 std::list<const Expr*>& join_predicates,
1740 std::list<const Expr*>& const_predicates)
const {
1741 std::set<int> rte_idx_set;
1742 arg->collect_rte_idx(rte_idx_set);
1743 if (rte_idx_set.size() > 1) {
1744 join_predicates.push_back(
this);
1745 }
else if (rte_idx_set.size() == 1) {
1746 scan_predicates.push_back(
this);
1748 const_predicates.push_back(
this);
1753 std::list<const Expr*>& join_predicates,
1754 std::list<const Expr*>& const_predicates)
const {
1755 std::set<int> rte_idx_set;
1757 if (rte_idx_set.size() > 1) {
1758 join_predicates.push_back(
this);
1759 }
else if (rte_idx_set.size() == 1) {
1760 scan_predicates.push_back(
this);
1762 const_predicates.push_back(
this);
1767 std::list<const Expr*>& join_predicates,
1768 std::list<const Expr*>& const_predicates)
const {
1769 std::set<int> rte_idx_set;
1770 arg->collect_rte_idx(rte_idx_set);
1771 if (rte_idx_set.size() > 1) {
1772 join_predicates.push_back(
this);
1773 }
else if (rte_idx_set.size() == 1) {
1774 scan_predicates.push_back(
this);
1776 const_predicates.push_back(
this);
1781 std::list<const Expr*>& join_predicates,
1782 std::list<const Expr*>& const_predicates)
const {
1783 std::set<int> rte_idx_set;
1784 arg->collect_rte_idx(rte_idx_set);
1785 if (rte_idx_set.size() > 1) {
1786 join_predicates.push_back(
this);
1787 }
else if (rte_idx_set.size() == 1) {
1788 scan_predicates.push_back(
this);
1790 const_predicates.push_back(
this);
1795 std::list<const Expr*>& join_predicates,
1796 std::list<const Expr*>& const_predicates)
const {
1797 std::set<int> rte_idx_set;
1799 p.first->collect_rte_idx(rte_idx_set);
1800 p.second->collect_rte_idx(rte_idx_set);
1803 else_expr->collect_rte_idx(rte_idx_set);
1805 if (rte_idx_set.size() > 1) {
1806 join_predicates.push_back(
this);
1807 }
else if (rte_idx_set.size() == 1) {
1808 scan_predicates.push_back(
this);
1810 const_predicates.push_back(
this);
1815 std::list<const Expr*>& join_predicates,
1816 std::list<const Expr*>& const_predicates)
const {
1817 std::set<int> rte_idx_set;
1819 if (rte_idx_set.size() > 1) {
1820 join_predicates.push_back(
this);
1821 }
else if (rte_idx_set.size() == 1) {
1822 scan_predicates.push_back(
this);
1824 const_predicates.push_back(
this);
1829 std::list<const Expr*>& join_predicates,
1830 std::list<const Expr*>& const_predicates)
const {
1831 std::set<int> rte_idx_set;
1832 number_->collect_rte_idx(rte_idx_set);
1833 datetime_->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;
1847 start_->collect_rte_idx(rte_idx_set);
1848 end_->collect_rte_idx(rte_idx_set);
1849 if (rte_idx_set.size() > 1) {
1850 join_predicates.push_back(
this);
1851 }
else if (rte_idx_set.size() == 1) {
1852 scan_predicates.push_back(
this);
1854 const_predicates.push_back(
this);
1859 std::list<const Expr*>& join_predicates,
1860 std::list<const Expr*>& const_predicates)
const {
1861 std::set<int> rte_idx_set;
1863 if (rte_idx_set.size() > 1) {
1864 join_predicates.push_back(
this);
1865 }
else if (rte_idx_set.size() == 1) {
1866 scan_predicates.push_back(
this);
1868 const_predicates.push_back(
this);
1873 const std::vector<std::shared_ptr<TargetEntry>>& tlist)
const {
1874 for (
auto tle : tlist) {
1875 const Expr* e = tle->get_expr();
1877 if (colvar !=
nullptr) {
1883 throw std::runtime_error(
"Internal error: cannot find ColumnVar in targetlist.");
1887 const std::vector<std::shared_ptr<TargetEntry>>& tlist)
const {
1889 for (
auto tle : tlist) {
1890 const Expr* e = tle->get_expr();
1892 if (colvar ==
nullptr) {
1893 throw std::runtime_error(
1894 "Internal Error: targetlist in rewrite_with_child_targetlist is not all "
1907 throw std::runtime_error(
"Internal error: cannot find ColumnVar in child targetlist.");
1911 const std::vector<std::shared_ptr<TargetEntry>>& tlist)
const {
1913 for (
auto tle : tlist) {
1914 const Expr* e = tle->get_expr();
1915 if (
typeid(*e) !=
typeid(
AggExpr)) {
1917 if (colvar ==
nullptr) {
1918 throw std::runtime_error(
1919 "Internal Error: targetlist in rewrite_agg_to_var is not all columns and "
1933 throw std::runtime_error(
1934 "Internal error: cannot find ColumnVar from having clause in targetlist.");
1938 const std::vector<std::shared_ptr<TargetEntry>>& tlist)
const {
1940 for (
auto tle : tlist) {
1941 const Expr* e = tle->get_expr();
1947 throw std::runtime_error(
1948 "Internal error: cannot find Var from having clause in targetlist.");
1952 const std::vector<std::shared_ptr<TargetEntry>>& tlist)
const {
1953 std::vector<std::shared_ptr<Analyzer::Expr>> rewritten_args;
1954 for (
const auto& arg :
args_) {
1955 rewritten_args.emplace_back(arg->rewrite_with_targetlist(tlist));
1957 return makeExpr<StringOper>(
kind_, rewritten_args);
1961 const std::vector<std::shared_ptr<TargetEntry>>& tlist)
const {
1962 std::vector<std::shared_ptr<Analyzer::Expr>> rewritten_args;
1963 for (
const auto& arg :
args_) {
1964 rewritten_args.emplace_back(arg->rewrite_with_child_targetlist(tlist));
1966 return makeExpr<StringOper>(
kind_, rewritten_args);
1970 const std::vector<std::shared_ptr<TargetEntry>>& tlist)
const {
1971 std::vector<std::shared_ptr<Analyzer::Expr>> rewritten_args;
1972 for (
const auto& arg :
args_) {
1973 rewritten_args.emplace_back(arg->rewrite_agg_to_var(tlist));
1975 return makeExpr<StringOper>(
kind_, rewritten_args);
1979 const std::vector<std::shared_ptr<TargetEntry>>& tlist)
const {
1980 std::list<std::shared_ptr<Analyzer::Expr>> new_value_list;
1982 new_value_list.push_back(v->deep_copy());
1984 return makeExpr<InValues>(
arg->rewrite_with_targetlist(tlist), new_value_list);
1988 const std::vector<std::shared_ptr<TargetEntry>>& tlist)
const {
1989 std::list<std::shared_ptr<Analyzer::Expr>> new_value_list;
1991 new_value_list.push_back(v->deep_copy());
1993 return makeExpr<InValues>(
arg->rewrite_with_child_targetlist(tlist), new_value_list);
1997 const std::vector<std::shared_ptr<TargetEntry>>& tlist)
const {
1998 std::list<std::shared_ptr<Analyzer::Expr>> new_value_list;
2000 new_value_list.push_back(v->rewrite_agg_to_var(tlist));
2002 return makeExpr<InValues>(
arg->rewrite_agg_to_var(tlist), new_value_list);
2006 const std::vector<std::shared_ptr<TargetEntry>>& tlist)
const {
2007 for (
auto tle : tlist) {
2008 const Expr* e = tle->get_expr();
2009 if (
typeid(*e) ==
typeid(
AggExpr)) {
2011 if (*
this == *agg) {
2016 throw std::runtime_error(
"Internal error: cannot find AggExpr in targetlist.");
2020 const std::vector<std::shared_ptr<TargetEntry>>& tlist)
const {
2023 arg ?
arg->rewrite_with_child_targetlist(tlist) :
nullptr,
2029 const std::vector<std::shared_ptr<TargetEntry>>& tlist)
const {
2031 for (
auto tle : tlist) {
2032 const Expr* e = tle->get_expr();
2033 if (
typeid(*e) ==
typeid(
AggExpr)) {
2035 if (*
this == *agg_expr) {
2041 throw std::runtime_error(
2042 "Internal error: cannot find AggExpr from having clause in targetlist.");
2046 const std::vector<std::shared_ptr<TargetEntry>>& tlist)
const {
2047 std::list<std::pair<std::shared_ptr<Analyzer::Expr>, std::shared_ptr<Analyzer::Expr>>>
2050 epair_list.emplace_back(p.first->rewrite_with_targetlist(tlist),
2051 p.second->rewrite_with_targetlist(tlist));
2053 return makeExpr<CaseExpr>(
2061 const std::vector<std::shared_ptr<TargetEntry>>& tlist)
const {
2062 return makeExpr<ExtractExpr>(
2067 const std::vector<std::shared_ptr<TargetEntry>>& tlist)
const {
2070 number_->rewrite_with_targetlist(tlist),
2071 datetime_->rewrite_with_targetlist(tlist));
2075 const std::vector<std::shared_ptr<TargetEntry>>& tlist)
const {
2076 return makeExpr<DatediffExpr>(
type_info,
2078 start_->rewrite_with_targetlist(tlist),
2079 end_->rewrite_with_targetlist(tlist));
2083 const std::vector<std::shared_ptr<TargetEntry>>& tlist)
const {
2084 return makeExpr<DatetruncExpr>(
2089 const std::vector<std::shared_ptr<TargetEntry>>& tlist)
const {
2090 std::list<std::pair<std::shared_ptr<Analyzer::Expr>, std::shared_ptr<Analyzer::Expr>>>
2093 epair_list.emplace_back(p.first->rewrite_with_child_targetlist(tlist),
2094 p.second->rewrite_with_child_targetlist(tlist));
2096 return makeExpr<CaseExpr>(
2104 const std::vector<std::shared_ptr<TargetEntry>>& tlist)
const {
2105 return makeExpr<ExtractExpr>(
2110 const std::vector<std::shared_ptr<TargetEntry>>& tlist)
const {
2113 number_->rewrite_with_child_targetlist(tlist),
2114 datetime_->rewrite_with_child_targetlist(tlist));
2118 const std::vector<std::shared_ptr<TargetEntry>>& tlist)
const {
2119 return makeExpr<DatediffExpr>(
type_info,
2121 start_->rewrite_with_child_targetlist(tlist),
2122 end_->rewrite_with_child_targetlist(tlist));
2126 const std::vector<std::shared_ptr<TargetEntry>>& tlist)
const {
2127 return makeExpr<DatetruncExpr>(
2132 const std::vector<std::shared_ptr<TargetEntry>>& tlist)
const {
2133 std::list<std::pair<std::shared_ptr<Analyzer::Expr>, std::shared_ptr<Analyzer::Expr>>>
2136 epair_list.emplace_back(p.first->rewrite_agg_to_var(tlist),
2137 p.second->rewrite_agg_to_var(tlist));
2146 const std::vector<std::shared_ptr<TargetEntry>>& tlist)
const {
2147 return makeExpr<ExtractExpr>(
2152 const std::vector<std::shared_ptr<TargetEntry>>& tlist)
const {
2155 number_->rewrite_agg_to_var(tlist),
2160 const std::vector<std::shared_ptr<TargetEntry>>& tlist)
const {
2161 return makeExpr<DatediffExpr>(
type_info,
2163 start_->rewrite_agg_to_var(tlist),
2164 end_->rewrite_agg_to_var(tlist));
2168 const std::vector<std::shared_ptr<TargetEntry>>& tlist)
const {
2169 return makeExpr<DatetruncExpr>(
2174 if (
typeid(rhs) !=
typeid(
ColumnVar) &&
typeid(rhs) !=
typeid(
Var)) {
2182 const Var* v =
dynamic_cast<const Var*
>(
this);
2186 const Var* rv =
dynamic_cast<const Var*
>(&rhs);
2187 if (rv ==
nullptr) {
2199 const auto& rhs_tuple_cols = rhs_tuple->
getTuple();
2239 throw std::runtime_error(
"Unrecognized type for Constant Datum equality: " +
2247 if (
typeid(rhs) !=
typeid(
Constant)) {
2264 if (
typeid(rhs) !=
typeid(
UOper)) {
2267 const UOper& rhs_uo =
dynamic_cast<const UOper&
>(rhs);
2272 if (
typeid(rhs) !=
typeid(
BinOper)) {
2337 if (
typeid(rhs) !=
typeid(
LikeExpr)) {
2408 if (
typeid(rhs) !=
typeid(
InValues)) {
2429 if (
typeid(rhs) !=
typeid(
AggExpr)) {
2439 if (
arg ==
nullptr || rhs_ae.
get_arg() ==
nullptr) {
2446 if (
typeid(rhs) !=
typeid(
CaseExpr)) {
2459 if (!(*p.first == *it->first) || !(*p.second == *it->second)) {
2520 const auto rhs_window =
dynamic_cast<const WindowFunction*
>(&rhs);
2524 if (
kind_ != rhs_window->kind_ ||
args_.size() != rhs_window->args_.size() ||
2526 order_keys_.size() != rhs_window->order_keys_.size() ||
2545 if (!(lhs_expr == rhs_expr)) {
2558 const auto rhs_geo =
dynamic_cast<const GeoUOper*
>(&rhs);
2562 if (
op_ != rhs_geo->getOp() ||
ti0_ != rhs_geo->getTypeInfo0() ||
2563 args0_.size() != rhs_geo->getArgs0().size()) {
2570 const auto rhs_geo =
dynamic_cast<const GeoBinOper*
>(&rhs);
2574 if (
op_ != rhs_geo->getOp() ||
ti0_ != rhs_geo->getTypeInfo0() ||
2575 args0_.size() != rhs_geo->getArgs0().size()) {
2578 if (
ti1_ != rhs_geo->getTypeInfo1() ||
args1_.size() != rhs_geo->getArgs1().size()) {
2592 std::string str{
"< "};
2593 for (
const auto& column :
tuple_) {
2594 str += column->toString();
2608 std::string str{
"(Const "};
2649 return "(" + op +
operand->toString() +
") ";
2703 std::string str{
"("};
2719 return "(RangeOper " + lhs +
" " +
left_operand_->toString() +
" , " +
2724 return "(Subquery ) ";
2728 std::string str{
"(IN "};
2729 str +=
arg->toString();
2732 bool shorted_value_list_str =
false;
2734 str += e->toString();
2737 shorted_value_list_str =
true;
2741 if (shorted_value_list_str) {
2743 str +=
"Total # values: ";
2755 if (!dynamic_cast<const InIntegerSet*>(&rhs)) {
2758 const auto& rhs_in_integer_set =
static_cast<const InIntegerSet&
>(rhs);
2759 return *
arg == *rhs_in_integer_set.arg &&
value_list == rhs_in_integer_set.value_list;
2763 std::string str{
"(IN_INTEGER_SET "};
2764 str +=
arg->toString();
2767 bool shorted_value_list_str =
false;
2772 shorted_value_list_str =
true;
2776 if (shorted_value_list_str) {
2778 str +=
"Total # values: ";
2788 str +=
"CHAR_LENGTH(";
2792 str +=
arg->toString();
2798 std::string str{
"KEY_FOR_STRING("};
2799 str +=
arg->toString();
2805 std::string str{
"SAMPLE_RATIO("};
2806 str +=
arg->toString();
2812 std::string str{
"CARDINALITY("};
2813 str +=
arg->toString();
2819 std::string str{
"(LIKE "};
2820 str +=
arg->toString();
2830 std::string str{
"(REGEXP "};
2831 str +=
arg->toString();
2841 std::string str{
"(WIDTH_BUCKET "};
2850 std::string str{
"(LIKELIHOOD "};
2851 str +=
arg->toString();
2874 agg =
"APPROX_COUNT_DISTINCT";
2877 agg =
"APPROX_PERCENTILE";
2880 agg =
"SINGLE_VALUE";
2886 std::string str{
"(" + agg};
2891 str +=
arg->toString();
2899 std::string str{
"CASE "};
2902 str += p.first->toString();
2904 str += p.second->toString();
2921 " DATETIME " +
datetime_->toString() +
") ";
2926 end_->toString() +
") ";
2934 return "(OffsetInFragment) ";
2944 for (
const auto& arg :
args_) {
2945 result +=
" " + arg->toString();
2948 result +=
" Frame{";
2960 <<
"Two bound types are supported for window framing: ROW and RANGE.";
2968 result +=
" (RANGE BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW)";
2970 result +=
" (RANGE BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING)";
2974 return result +
") ";
2978 std::string str{
"ARRAY["};
2982 str += (*iter)->toString();
3005 fn =
"ST_IsConcaveHull";
3008 fn =
"ST_IsConvexHull";
3014 std::string
result = fn +
"(";
3015 for (
const auto& arg :
args0_) {
3016 result +=
" " + arg->toString();
3018 return result +
" ) ";
3025 fn =
"ST_Intersection";
3028 fn =
"ST_Difference";
3040 std::string
result = fn +
"(";
3042 for (
const auto& arg :
args0_) {
3043 result +=
" " + arg->toString();
3045 for (
const auto& arg :
args1_) {
3046 result +=
" " + arg->toString();
3048 return result +
" ) ";
3052 std::string str{
"(" +
resname +
" "};
3053 str +=
expr->toString();
3067 str +=
" nulls first";
3075 for (
auto e : expr_list) {
3080 expr_list.push_back(
this);
3101 std::list<const Expr*>& expr_list)
const {
3106 arg->find_expr(
f, expr_list);
3108 e->find_expr(
f, expr_list);
3113 std::list<const Expr*>& expr_list)
const {
3118 arg->find_expr(
f, expr_list);
3122 std::list<const Expr*>& expr_list)
const {
3127 arg->find_expr(
f, expr_list);
3131 std::list<const Expr*>& expr_list)
const {
3136 arg->find_expr(
f, expr_list);
3140 std::list<const Expr*>& expr_list)
const {
3145 for (
const auto& arg :
args_) {
3146 arg->find_expr(
f, expr_list);
3151 std::list<const Expr*>& expr_list)
const {
3156 arg->find_expr(
f, expr_list);
3160 std::list<const Expr*>& expr_list)
const {
3165 arg->find_expr(
f, expr_list);
3173 std::list<const Expr*>& expr_list)
const {
3178 arg->find_expr(
f, expr_list);
3186 std::list<const Expr*>& expr_list)
const {
3198 std::list<const Expr*>& expr_list)
const {
3203 arg->find_expr(
f, expr_list);
3211 if (
arg !=
nullptr) {
3212 arg->find_expr(
f, expr_list);
3217 std::list<const Expr*>& expr_list)
const {
3223 p.first->find_expr(
f, expr_list);
3224 p.second->find_expr(
f, expr_list);
3232 std::list<const Expr*>& expr_list)
const {
3241 std::list<const Expr*>& expr_list)
const {
3251 std::list<const Expr*>& expr_list)
const {
3256 start_->find_expr(
f, expr_list);
3257 end_->find_expr(
f, expr_list);
3261 std::list<const Expr*>& expr_list)
const {
3271 p.first->collect_rte_idx(rte_idx_set);
3272 p.second->collect_rte_idx(rte_idx_set);
3275 else_expr->collect_rte_idx(rte_idx_set);
3284 number_->collect_rte_idx(rte_idx_set);
3285 datetime_->collect_rte_idx(rte_idx_set);
3289 start_->collect_rte_idx(rte_idx_set);
3290 end_->collect_rte_idx(rte_idx_set);
3300 expr->collect_rte_idx(rte_idx_set);
3305 for (
const auto& arg :
args_) {
3306 arg->collect_rte_idx(rte_idx_set);
3311 for (
unsigned i = 0; i <
getArity(); i++) {
3312 const auto expr =
getArg(i);
3313 expr->collect_rte_idx(rte_idx_set);
3319 bool include_agg)
const {
3321 p.first->collect_column_var(colvar_set, include_agg);
3322 p.second->collect_column_var(colvar_set, include_agg);
3325 else_expr->collect_column_var(colvar_set, include_agg);
3331 bool include_agg)
const {
3332 from_expr_->collect_column_var(colvar_set, include_agg);
3337 bool include_agg)
const {
3338 number_->collect_column_var(colvar_set, include_agg);
3339 datetime_->collect_column_var(colvar_set, include_agg);
3344 bool include_agg)
const {
3345 start_->collect_column_var(colvar_set, include_agg);
3346 end_->collect_column_var(colvar_set, include_agg);
3351 bool include_agg)
const {
3352 from_expr_->collect_column_var(colvar_set, include_agg);
3357 bool include_agg)
const {
3360 expr->collect_column_var(colvar_set, include_agg);
3366 bool include_agg)
const {
3367 for (
const auto& arg :
args_) {
3368 arg->collect_column_var(colvar_set, include_agg);
3374 bool include_agg)
const {
3375 for (
unsigned i = 0; i <
getArity(); i++) {
3376 const auto expr =
getArg(i);
3377 expr->collect_column_var(colvar_set, include_agg);
3382 const std::list<std::shared_ptr<Analyzer::Expr>>& groupby)
const {
3384 p.first->check_group_by(groupby);
3385 p.second->check_group_by(groupby);
3393 const std::list<std::shared_ptr<Analyzer::Expr>>& groupby)
const {
3398 const std::list<std::shared_ptr<Analyzer::Expr>>& groupby)
const {
3399 number_->check_group_by(groupby);
3404 const std::list<std::shared_ptr<Analyzer::Expr>>& groupby)
const {
3405 start_->check_group_by(groupby);
3406 end_->check_group_by(groupby);
3410 const std::list<std::shared_ptr<Analyzer::Expr>>& groupby)
const {
3416 const auto c = std::dynamic_pointer_cast<
const Constant>(p.second);
3420 const auto v = std::dynamic_pointer_cast<
const ColumnVar>(p.second);
3424 const auto cast = std::dynamic_pointer_cast<
const UOper>(p.second);
3425 if (cast !=
nullptr && cast->get_optype() ==
kCAST) {
3431 const auto v = std::dynamic_pointer_cast<
const ColumnVar>(p.second);
3438 p.second->get_domain(domain_set);
3439 if (domain_set.empty()) {
3454 const auto cast = std::dynamic_pointer_cast<
const UOper>(
else_expr);
3455 if (cast !=
nullptr && cast->get_optype() ==
kCAST) {
3474 std::vector<std::shared_ptr<Analyzer::Expr>> args_copy;
3475 for (
const auto& arg :
args_) {
3476 args_copy.emplace_back(arg->deep_copy());
3478 std::vector<std::shared_ptr<Analyzer::Expr>> chained_string_op_exprs_copy;
3480 chained_string_op_exprs_copy.emplace_back(chained_string_op_expr->deep_copy());
3482 return makeExpr<Analyzer::StringOper>(
3483 kind_, std::move(args_copy), std::move(chained_string_op_exprs_copy));
3487 return makeExpr<Analyzer::LowerStringOper>(
3492 return makeExpr<Analyzer::UpperStringOper>(
3497 return makeExpr<Analyzer::InitCapStringOper>(
3502 return makeExpr<Analyzer::ReverseStringOper>(
3507 return makeExpr<Analyzer::RepeatStringOper>(
3512 return makeExpr<Analyzer::PadStringOper>(
3517 return makeExpr<Analyzer::TrimStringOper>(
3522 return makeExpr<Analyzer::SubstringStringOper>(
3527 return makeExpr<Analyzer::ReplaceStringOper>(
3532 return makeExpr<Analyzer::OverlayStringOper>(
3537 return makeExpr<Analyzer::ConcatStringOper>(
3542 return makeExpr<Analyzer::SplitPartStringOper>(
3547 return makeExpr<Analyzer::RegexpReplaceStringOper>(
3552 return makeExpr<Analyzer::RegexpSubstrStringOper>(
3557 return makeExpr<Analyzer::JsonValueStringOper>(
3562 return makeExpr<Analyzer::Base64EncodeStringOper>(
3567 return makeExpr<Analyzer::Base64DecodeStringOper>(
3572 std::vector<std::shared_ptr<Analyzer::Expr>> args_copy;
3573 for (
size_t i = 0; i <
getArity(); ++i) {
3580 const auto rhs_string_oper =
dynamic_cast<const StringOper*
>(&rhs);
3582 if (!rhs_string_oper) {
3586 if (
get_kind() != rhs_string_oper->get_kind()) {
3589 if (
getArity() != rhs_string_oper->getArity()) {
3593 for (
size_t i = 0; i <
getArity(); ++i) {
3594 if (!(*
getArg(i) == *(rhs_string_oper->getArg(i)))) {
3599 rhs_string_oper->chained_string_op_exprs_.size()) {
3604 *(rhs_string_oper->chained_string_op_exprs_[i]))) {
3615 const auto rhs_func_oper =
dynamic_cast<const FunctionOper*
>(&rhs);
3616 if (!rhs_func_oper) {
3619 if (
getName() != rhs_func_oper->getName()) {
3622 if (
getArity() != rhs_func_oper->getArity()) {
3625 for (
size_t i = 0; i <
getArity(); ++i) {
3626 if (!(*
getArg(i) == *(rhs_func_oper->getArg(i)))) {
3635 for (
const auto& arg :
args_) {
3636 str += arg->toString();
3643 std::string str{
"(" +
name_ +
" "};
3644 for (
const auto& arg :
args_) {
3645 str += arg->toString();
3652 std::vector<std::shared_ptr<Analyzer::Expr>> args_copy;
3653 for (
size_t i = 0; i <
getArity(); ++i) {
3656 return makeExpr<Analyzer::FunctionOperWithCustomTypeHandling>(
3664 const auto rhs_func_oper =
3666 if (!rhs_func_oper) {
3669 if (
getName() != rhs_func_oper->getName()) {
3672 if (
getArity() != rhs_func_oper->getArity()) {
3675 for (
size_t i = 0; i <
getArity(); ++i) {
3676 if (!(*
getArg(i) == *(rhs_func_oper->getArg(i)))) {
3685 auto copied_expr = bound_expr->
deep_copy();
3688 auto casted_constant = std::dynamic_pointer_cast<
const Analyzer::Constant>(casted_expr);
3689 CHECK(casted_constant);
3690 return casted_constant->get_constval().doubleval;
3694 auto const_partition_count_expr =
3696 if (!const_partition_count_expr) {
3700 switch (const_partition_count_expr->get_type_info().get_type()) {
3702 return d.tinyintval;
3704 return d.smallintval;
3708 auto bi = d.bigintval;
3709 if (bi < 1 || bi > INT32_MAX) {
3753 :
GeoExpr(ti), geo_(std::move(geo)) {
3756 throw std::runtime_error(
"Conflicting types for geo data " +
geo_->getWktString() +
3767 std::string str{
"(GeoConstant "};
3769 str +=
geo_->getWktString();
3776 return geo_->getWktString();
3802 const size_t index)
const {
3806 CHECK_LE(index,
size_t(num_phys_coords));
3809 std::vector<double> coords;
3810 std::vector<double> bounds;
3811 std::vector<int> ring_sizes;
3812 std::vector<int> poly_rings;
3815 geo_->getWktString(), ti, coords, bounds, ring_sizes, poly_rings);
3843 throw std::runtime_error(
"Failed to transform constant geometry: " +
toString());
3849 return makeExpr<GeoConstant>(std::move(
geo_), cast_type_info);
3853 const std::string&
name,
3854 const std::vector<std::shared_ptr<Analyzer::Expr>>&
args,
3855 const std::optional<int>& output_srid_override)
3859 , output_srid_override_(output_srid_override) {}
3862 std::vector<std::shared_ptr<Analyzer::Expr>>
args;
3863 for (
size_t i = 0; i <
args_.size(); i++) {
3870 for (
size_t i = 0; i <
size(); i++) {
3872 expr->collect_rte_idx(rte_idx_set);
3878 bool include_agg)
const {
3879 for (
size_t i = 0; i <
size(); i++) {
3881 expr->collect_column_var(colvar_set, include_agg);
3886 std::string str{
"(" +
name_ +
" "};
3887 for (
const auto& arg :
args_) {
3888 str += arg->toString();
3905 for (
size_t i = 0; i <
size(); i++) {
3914 return args_.size();
3919 return args_[index].get();
3924 std::vector<std::shared_ptr<Analyzer::Expr>>
args;
3925 for (
size_t i = 0; i <
args_.size(); i++) {
3932 return makeExpr<UOper>(new_type_info,
false,
kCAST, new_expr);
3937 std::vector<std::shared_ptr<Analyzer::Expr>>
args;
3938 for (
size_t i = 0; i <
args_.size(); i++) {
3941 return makeExpr<GeoTransformOperator>(
3946 std::string str{
"(" +
name_ +
" "};
3947 for (
const auto& arg :
args_) {
3948 str += arg->toString();
3967 for (
size_t i = 0; i <
size(); i++) {
3984 bool (*)(
const Analyzer::ColumnVar*,
const Analyzer::ColumnVar*)>
3985 colvar_set(comparator);
3987 if (colvar_set.size() != 1UL) {
3990 auto col_expr_ptr = *colvar_set.begin();
3991 CHECK(col_expr_ptr);
3992 return col_expr_ptr->get_type_info().is_dict_encoded_string();
3996 std::vector<size_t> literal_arg_indexes;
3997 const auto num_args =
args_.size();
3998 for (
size_t idx = 0; idx < num_args; ++idx) {
3999 if (dynamic_cast<const Constant*>(
args_[idx].
get())) {
4000 literal_arg_indexes.emplace_back(idx);
4003 return literal_arg_indexes;
4011 for (
size_t idx = 0; idx < num_args; ++idx) {
4013 if (constant_arg_expr) {
4014 literal_arg_map.emplace(
4016 std::make_pair(constant_arg_expr->get_type_info().get_type(),
4017 constant_arg_expr->get_constval())));
4020 return literal_arg_map;
4024 const std::vector<std::shared_ptr<Analyzer::Expr>>
args) {
4029 if (dynamic_cast<const Analyzer::Constant*>(
args[0].
get())) {
4030 return args[0]->get_type_info();
4046 const size_t min_args,
4047 const std::vector<OperandTypeFamily>& expected_type_families,
4048 const std::vector<std::string>& arg_names,
4049 const bool dict_encoded_cols_only,
4050 const bool cols_first_arg_only)
const {
4051 std::ostringstream oss;
4054 throw std::runtime_error(oss.str());
4056 const size_t num_args =
args_.size();
4057 CHECK_EQ(expected_type_families.size(), arg_names.size());
4058 if (num_args < min_args || num_args > expected_type_families.size()) {
4060 oss <<
"Expected " << expected_type_families.size() <<
" arguments, but received "
4063 for (
size_t arg_idx = 0; arg_idx < num_args; ++arg_idx) {
4064 const auto& expected_type_family = expected_type_families[arg_idx];
4068 auto arg_ti =
args_[arg_idx]->get_type_info();
4070 const bool is_arg_constant =
4072 const bool is_arg_column_var =
4074 const bool is_arg_string_oper =
4076 if (!(is_arg_constant || is_arg_column_var || is_arg_string_oper)) {
4078 <<
"Currently only constant, column, or other string operator arguments "
4079 <<
"are allowed as inputs.";
4080 throw std::runtime_error(oss.str());
4082 auto decasted_arg_ti = decasted_arg->get_type_info();
4087 if (arg_ti != decasted_arg_ti &&
4088 ((arg_ti.is_string() && !decasted_arg_ti.is_string()) ||
4089 (arg_ti.is_integer() && decasted_arg_ti.is_string()))) {
4090 arg_ti = decasted_arg_ti;
4093 if (cols_first_arg_only && !is_arg_constant && arg_idx >= 1UL) {
4095 <<
"Currently only column inputs allowed for the primary argument, "
4096 <<
"but a column input was received for argument " << arg_idx + 1 <<
".";
4097 throw std::runtime_error(oss.str());
4099 switch (expected_type_family) {
4101 if (!arg_ti.is_string()) {
4103 <<
"Expected text type for argument " << arg_idx + 1 <<
" ("
4104 << arg_names[arg_idx] <<
").";
4105 throw std::runtime_error(oss.str());
4108 if (dict_encoded_cols_only &&
4109 (!is_arg_constant && !arg_ti.is_dict_encoded_string())) {
4111 <<
"Currently only text-encoded dictionary-encoded column inputs are "
4112 <<
"allowed, but a none-encoded text column argument was received.";
4113 throw std::runtime_error(oss.str());
4121 <<
"Expected integer type for argument " << arg_idx + 1 <<
" ("
4122 << arg_names[arg_idx] <<
").";
4123 throw std::runtime_error(oss.str());
4126 if (!is_arg_constant) {
4128 <<
"Currently only text-encoded dictionary column inputs are "
4129 <<
"allowed, but an integer-type column was provided.";
4130 throw std::runtime_error(oss.str());
4140 const std::vector<std::shared_ptr<Analyzer::Expr>>& operands) {
4141 if (operands.size() != 2UL) {
4142 std::ostringstream oss;
4143 oss <<
"Concat operator expects two arguments, but was provided " << operands.size()
4145 throw std::runtime_error(oss.str());
4147 if (operands[1].
get()->get_type_info().is_dict_encoded_string() &&
4148 !(operands[0].get()->get_type_info().is_dict_encoded_string())) {
4155 const std::vector<std::shared_ptr<Analyzer::Expr>>& operands) {
4158 return {operands[1], operands[0]};
4167 throw std::runtime_error(
"Invalid pad type supplied to PAD operator");
4174 const std::vector<std::shared_ptr<Analyzer::Expr>>&
args) {
4175 auto get_trim_type_if_exists = [&
args]() {
4180 if (!trim_type_arg) {
4183 const auto trim_type_str =
to_upper(*trim_type_arg->get_constval().stringval);
4184 if (trim_type_str ==
"BOTH") {
4187 if (trim_type_str ==
"LEADING") {
4190 if (trim_type_str ==
"TRAILING") {
4197 ? get_trim_type_if_exists()
4198 : trim_op_kind_maybe;
4200 return trim_op_kind;
4204 const std::vector<std::shared_ptr<Analyzer::Expr>>& operands,
4206 if (operands.size() < 2UL) {
4207 throw std::runtime_error(
"Trim operator expects 2 arguments.");
4219 if (dynamic_cast<const Analyzer::Constant*>(operands[0].
get()) &&
4221 return {operands[1], operands[0]};
4226 return {operands[2], operands[1]};
4232 const std::vector<std::shared_ptr<Analyzer::Expr>>& rhs) {
4233 if (lhs.size() != rhs.size()) {
4236 for (
size_t i = 0; i < lhs.size(); ++i) {
4237 if (!(*lhs[i] == *rhs[i])) {
4244 std::shared_ptr<Analyzer::Expr>
remove_cast(
const std::shared_ptr<Analyzer::Expr>& expr) {
4246 if (!uoper || uoper->get_optype() !=
kCAST) {
4254 if (!uoper || uoper->get_optype() !=
kCAST) {
4257 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
void find_expr(bool(*f)(const Expr *), std::list< const Expr * > &expr_list) 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
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)
void find_expr(bool(*f)(const Expr *), std::list< const Expr * > &expr_list) const override
bool operator==(const Expr &rhs) const override
const Expr * get_escape_expr() const
std::shared_ptr< Analyzer::Expr > arg
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)
void find_expr(bool(*f)(const Expr *), std::list< const Expr * > &expr_list) const override
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 is_any(Types...types) const
bool operator==(const Expr &rhs) const override
std::shared_ptr< Analyzer::Expr > deep_copy() 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
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
std::map< size_t, std::pair< SQLTypes, Datum >> LiteralArgMap
std::shared_ptr< Analyzer::Expr > deep_copy() const override
SqlWindowFrameBoundType bound_type_
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
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
std::string toString(const QueryDescriptionType &type)
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_
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_
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
void find_expr(bool(*f)(const Expr *), std::list< const Expr * > &expr_list) const override
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
static SQLTypeInfo get_return_type(const std::vector< std::shared_ptr< Analyzer::Expr >> args)
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
void find_expr(bool(*f)(const Expr *), std::list< const Expr * > &expr_list) 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_
const Geospatial::GeoBase::GeoOp op_
std::string toString() const override
SQLOps get_optype() const
std::shared_ptr< Analyzer::Expr > left_operand
This file contains the class specification and related data structures for Catalog.
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=true, const bool cols_first_arg_only=true) const
bool operator==(const Expr &rhs) const override
void set_input_srid(int d)
const std::vector< std::shared_ptr< Analyzer::Expr > > args1_
std::shared_ptr< Analyzer::Constant > arg1
std::string toString() const
const std::shared_ptr< Analyzer::Expr > frame_start_bound_
std::shared_ptr< Analyzer::Expr > deep_copy() const override
std::shared_ptr< Analyzer::Expr > normalize_simple_predicate(int &rte_idx) const override
const std::list< std::shared_ptr< Analyzer::Expr > > value_list
std::shared_ptr< Analyzer::Expr > deep_copy() const override
std::shared_ptr< Analyzer::Expr > deep_copy() const override
static SQLTypeInfo common_string_type(const SQLTypeInfo &type1, const SQLTypeInfo &type2)
std::shared_ptr< Analyzer::Expr > deep_copy() const override
std::shared_ptr< Analyzer::Expr > right_operand_
void group_predicates(std::list< const Expr * > &scan_predicates, std::list< const Expr * > &join_predicates, std::list< const Expr * > &const_predicates) const override
std::shared_ptr< Analyzer::Expr > deep_copy() const override
static SqlStringOpKind validate_trim_op_kind(const SqlStringOpKind trim_op_kind)
bool hasSingleDictEncodedColInput() const
returns whether we have one and only one column involved in this StringOper and all its descendents...
std::shared_ptr< Analyzer::Expr > deep_copy() const final
LiteralArgMap getLiteralArgs() const
std::string toString() const override
std::shared_ptr< Analyzer::Expr > rewrite_agg_to_var(const std::vector< std::shared_ptr< TargetEntry >> &tlist) const override
const DatetruncField field_
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
const std::vector< std::shared_ptr< Analyzer::Expr > > & getTuple() const
void collect_rte_idx(std::set< int > &rte_idx_set) const override
std::shared_ptr< Analyzer::Expr > rewrite_agg_to_var(const std::vector< std::shared_ptr< TargetEntry >> &tlist) const override
bool is_castable(const SQLTypeInfo &new_type_info) const
void collect_rte_idx(std::set< int > &rte_idx_set) const override
void find_expr(bool(*f)(const Expr *), std::list< const Expr * > &expr_list) const override
std::shared_ptr< Analyzer::Expr > lower_bound_
std::string toString() const override
const DateaddField field_
std::shared_ptr< Analyzer::Expr > deep_copy() const override