OmniSciDB  a5dc49c757
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
RangeTableIndexVisitor.h
Go to the documentation of this file.
1 /*
2  * Copyright 2022 HEAVY.AI, Inc.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #pragma once
18 
19 #include <set>
20 
21 #include "ScalarExprVisitor.h"
22 
24  protected:
25  int visitColumnVar(const Analyzer::ColumnVar* column) const override {
26  return column->get_rte_idx();
27  }
28 
29  int visitColumnVarTuple(const Analyzer::ExpressionTuple* expr_tuple) const override {
31  int max_range_table_idx = 0;
32  for (const auto& expr_component : expr_tuple->getTuple()) {
33  max_range_table_idx =
34  std::max(max_range_table_idx, visitor.visit(expr_component.get()));
35  }
36  return max_range_table_idx;
37  }
38 
39  int aggregateResult(const int& aggregate, const int& next_result) const override {
40  return std::max(aggregate, next_result);
41  }
42 };
43 
44 class AllRangeTableIndexVisitor : public ScalarExprVisitor<std::set<int>> {
45  protected:
46  std::set<int> visitColumnVar(const Analyzer::ColumnVar* column) const override {
47  return {column->get_rte_idx()};
48  }
49 
50  std::set<int> visitColumnVarTuple(
51  const Analyzer::ExpressionTuple* expr_tuple) const override {
53  std::set<int> result;
54  for (const auto& expr_component : expr_tuple->getTuple()) {
55  const auto component_rte_set = visitor.visit(expr_component.get());
56  result.insert(component_rte_set.begin(), component_rte_set.end());
57  }
58  return result;
59  }
60 
61  std::set<int> aggregateResult(const std::set<int>& aggregate,
62  const std::set<int>& next_result) const override {
63  auto result = aggregate;
64  result.insert(next_result.begin(), next_result.end());
65  return result;
66  }
67 };
int aggregateResult(const int &aggregate, const int &next_result) const override
T visit(const Analyzer::Expr *expr) const
const std::vector< std::shared_ptr< Analyzer::Expr > > & getTuple() const
Definition: Analyzer.h:253
int visitColumnVar(const Analyzer::ColumnVar *column) const override
std::set< int > visitColumnVar(const Analyzer::ColumnVar *column) const override
std::set< int > aggregateResult(const std::set< int > &aggregate, const std::set< int > &next_result) const override
int visitColumnVarTuple(const Analyzer::ExpressionTuple *expr_tuple) const override
std::set< int > visitColumnVarTuple(const Analyzer::ExpressionTuple *expr_tuple) const override
int32_t get_rte_idx() const
Definition: Analyzer.h:202