17 #ifndef QUERYENGINE_REXVISITOR_H
18 #define QUERYENGINE_REXVISITOR_H
29 const auto rex_input =
dynamic_cast<const RexInput*
>(rex_scalar);
33 const auto rex_literal =
dynamic_cast<const RexLiteral*
>(rex_scalar);
37 const auto rex_subquery =
dynamic_cast<const RexSubQuery*
>(rex_scalar);
41 const auto rex_operator =
dynamic_cast<const RexOperator*
>(rex_scalar);
45 const auto rex_case =
dynamic_cast<const RexCase*
>(rex_scalar);
49 const auto rex_ref =
dynamic_cast<const RexRef*
>(rex_scalar);
86 const size_t operand_count = rex_operator->
size();
88 for (
size_t i = 0; i < operand_count; ++i) {
89 const auto operand = rex_operator->
getOperand(i);
93 const auto rex_window_func_operator =
95 if (rex_window_func_operator) {
103 for (
size_t i = 0; i < rex_case->
branchCount(); ++i) {
104 const auto when = rex_case->
getWhen(i);
106 const auto then = rex_case->
getThen(i);
124 const T operands_visit_result)
const {
125 T result = operands_visit_result;
130 for (
const auto& key : rex_window_func_operator->
getOrderKeys()) {
140 using RetType = std::unique_ptr<const RexScalar>;
145 return literal->deepCopy();
149 return subquery->deepCopy();
155 const auto rex_window_function_operator =
157 if (rex_window_function_operator) {
161 const size_t operand_count = rex_operator->
size();
162 std::vector<RetType> new_opnds;
163 for (
size_t i = 0; i < operand_count; ++i) {
171 const size_t operand_count = rex_window_function_operator->
size();
172 std::vector<RetType> new_opnds;
173 for (
size_t i = 0; i < operand_count; ++i) {
174 new_opnds.push_back(
visit(rex_window_function_operator->
getOperand(i)));
177 const auto& partition_keys = rex_window_function_operator->
getPartitionKeys();
178 std::vector<std::unique_ptr<const RexScalar>> disambiguated_partition_keys;
179 for (
const auto& partition_key : partition_keys) {
180 disambiguated_partition_keys.emplace_back(
visit(partition_key.get()));
182 std::vector<std::unique_ptr<const RexScalar>> disambiguated_order_keys;
183 const auto& order_keys = rex_window_function_operator->
getOrderKeys();
184 for (
const auto& order_key : order_keys) {
185 disambiguated_order_keys.emplace_back(
visit(order_key.get()));
189 disambiguated_partition_keys,
190 disambiguated_order_keys,
195 std::vector<std::pair<RetType, RetType>> new_pair_list;
196 for (
size_t i = 0; i < rex_case->
branchCount(); ++i) {
201 return std::make_unique<RexCase>(new_pair_list, new_else);
208 using RowValues = std::vector<std::unique_ptr<const RexScalar>>;
210 static std::vector<RowValues>
copy(std::vector<RowValues>
const& rhs) {
212 std::vector<RowValues> retval;
213 retval.reserve(rhs.size());
214 for (
auto const& row : rhs) {
215 retval.push_back({});
216 retval.back().reserve(row.size());
217 for (
auto const& value : row) {
218 retval.back().push_back(copier.
visit(value.get()));
225 template <
bool bAllowMissing>
234 return std::make_unique<RexInput>(input->
getSourceNode(), renum_it->second);
240 return std::make_unique<RexInput>(input->
getSourceNode(), renum_it->second);
248 #endif // QUERYENGINE_REXVISITOR_H
const RexScalar * getThen(const size_t idx) const
T defaultResult() const override
std::vector< std::unique_ptr< const RexScalar >> RowValues
T visitCase(const RexCase *rex_case) const override
const RexScalar * getElse() const
std::unique_ptr< RexRef > deepCopy() const
const RexScalar * getOperand(const size_t idx) const
const std::vector< SortField > & getCollation() const
virtual T visitRef(const RexRef *) const =0
RetType visitOperator(const RexOperator *rex_operator) const override
virtual T visitLiteral(const RexLiteral *) const =0
T visitOperator(const RexOperator *rex_operator) const override
const RexScalar * getWhen(const size_t idx) const
virtual T visitCase(const RexCase *rex_case) const =0
RetType visitWindowFunctionOperator(const RexWindowFunctionOperator *rex_window_function_operator) const
RetType visitLiteral(const RexLiteral *literal) const override
virtual std::unique_ptr< const RexOperator > getDisambiguated(std::vector< std::unique_ptr< const RexScalar >> &operands) const
virtual T aggregateResult(const T &aggregate, const T &next_result) const
virtual T visit(const RexScalar *rex_scalar) const
T visitRef(const RexRef *) const override
virtual T defaultResult() const =0
RetType visitSubQuery(const RexSubQuery *subquery) const override
std::unique_ptr< const RexOperator > disambiguatedOperands(ConstRexScalarPtrVector &operands, ConstRexScalarPtrVector &partition_keys, ConstRexScalarPtrVector &order_keys, const std::vector< SortField > &collation) const
virtual T visitOperator(const RexOperator *rex_operator) const =0
virtual T visitInput(const RexInput *) const =0
virtual T visitSubQuery(const RexSubQuery *) const =0
size_t branchCount() const
RetType visitInput(const RexInput *input) const override
T visitWindowFunctionOperator(const RexWindowFunctionOperator *rex_window_func_operator, const T operands_visit_result) const
const ConstRexScalarPtrVector & getPartitionKeys() const
virtual std::string toString(RelRexToStringConfig config=RelRexToStringConfig::defaults()) const =0
T visitInput(const RexInput *) const override
static RelRexToStringConfig defaults()
T visitSubQuery(const RexSubQuery *) const override
RetType visitRef(const RexRef *ref) const override
const ConstRexScalarPtrVector & getOrderKeys() const
static std::vector< RowValues > copy(std::vector< RowValues > const &rhs)
RetType visitCase(const RexCase *rex_case) const override
RetType defaultResult() const override
std::unique_ptr< const RexScalar > RetType
T visitLiteral(const RexLiteral *) const override