OmniSciDB  a5dc49c757
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
RelRexDagVisitor.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 
28 #pragma once
29 
30 #include "QueryEngine/RelAlgDag.h"
31 #include "TypeHandler.h"
32 
33 #include "ThirdParty/robin_hood/robin_hood.h"
34 
35 #include <array>
36 
38  public:
39  virtual ~RelRexDagVisitor() = default;
40  virtual void visit(RelAlgNode const*);
41  virtual void visit(RexScalar const*);
42 
43  protected:
44  virtual void visit(RelAggregate const*) {}
45  virtual void visit(RelCompound const*);
46  virtual void visit(RelFilter const*);
47  virtual void visit(RelJoin const*);
48  virtual void visit(RelLeftDeepInnerJoin const*);
49  virtual void visit(RelLogicalUnion const*) {}
50  virtual void visit(RelLogicalValues const*);
51  virtual void visit(RelModify const*) {}
52  virtual void visit(RelProject const*);
53  virtual void visit(RelScan const*) {}
54  virtual void visit(RelSort const*) {}
55  virtual void visit(RelTableFunction const*);
56  virtual void visit(RelTranslatedJoin const*);
57 
58  virtual void visit(RexAbstractInput const*) {}
59  virtual void visit(RexCase const*);
60  virtual void visit(RexFunctionOperator const*);
61  virtual void visit(RexInput const*);
62  virtual void visit(RexLiteral const*) {}
63  virtual void visit(RexOperator const*);
64  virtual void visit(RexRef const*) {}
65  virtual void visit(RexSubQuery const*);
66  virtual void visit(RexWindowFunctionOperator const*);
67 
68  void castAndVisit(RelAlgNode const*);
69 
70  private:
71  using Cache = robin_hood::unordered_set<void const*>;
72  Cache cache_; // Don't visit nodes more than once
73 
74  template <typename T, typename U>
75  void cast(T const* node) {
76  visit(dynamic_cast<U const*>(node));
77  }
78 
79  template <typename T, size_t N>
80  using Handlers = std::array<TypeHandler<RelRexDagVisitor, T>, N>;
81 
82  template <typename T, typename... Ts>
83  static Handlers<T, sizeof...(Ts)> make_handlers();
84 };
virtual void visit(RelScan const *)
void cast(T const *node)
virtual void visit(RelAlgNode const *)
virtual void visit(RexRef const *)
virtual void visit(RexAbstractInput const *)
std::array< TypeHandler< RelRexDagVisitor, T >, N > Handlers
robin_hood::unordered_set< void const * > Cache
static Handlers< T, sizeof...(Ts)> make_handlers()
virtual void visit(RexLiteral const *)
virtual void visit(RelAggregate const *)
void castAndVisit(RelAlgNode const *)
constexpr unsigned N
Definition: Utm.h:110
virtual ~RelRexDagVisitor()=default
virtual void visit(RelLogicalUnion const *)
virtual void visit(RelSort const *)
Sortable utility struct for visitor patterns.
virtual void visit(RelModify const *)