OmniSciDB  2e3a973ef4
RelRexDagVisitor.h
Go to the documentation of this file.
1 /*
2  * Copyright 2020 OmniSci, 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 /*
18  * @description Visit all RelAlgNode and RexScalar nodes in a RA/Rex DAG.
19  * How to use:
20  * 1) Inherit from RelRexDagVisitor as a public interface.
21  Don't forget to add using RelRexDagVisitor::visit.
22  * 2) Add accumulator members as needed to collect data.
23  * 3) Override any virtual methods as needed, and include a call
24  * to the parent RelRexDagVisitor method to continue visitation.
25  */
26 
27 #pragma once
28 
29 #include "../RelAlgDagBuilder.h"
30 #include "TypeHandler.h"
31 
32 #include <array>
33 
35  public:
36  virtual ~RelRexDagVisitor() = default;
37  void visit(RelAlgNode const*);
38  virtual void visit(RexScalar const*);
39 
40  protected:
41  virtual void visit(RelAggregate const*) {}
42  virtual void visit(RelCompound const*);
43  virtual void visit(RelFilter const*);
44  virtual void visit(RelJoin const*);
45  virtual void visit(RelLeftDeepInnerJoin const*);
46  virtual void visit(RelLogicalUnion const*) {}
47  virtual void visit(RelLogicalValues const*);
48  virtual void visit(RelModify const*) {}
49  virtual void visit(RelProject const*);
50  virtual void visit(RelScan const*) {}
51  virtual void visit(RelSort const*) {}
52  virtual void visit(RelTableFunction const*);
53 
54  virtual void visit(RexAbstractInput const*) {}
55  virtual void visit(RexCase const*);
56  virtual void visit(RexFunctionOperator const*);
57  virtual void visit(RexInput const*) {} // Don't visit SourceNode
58  virtual void visit(RexLiteral const*) {}
59  virtual void visit(RexOperator const*);
60  virtual void visit(RexRef const*) {}
61  virtual void visit(RexSubQuery const*);
62  virtual void visit(RexWindowFunctionOperator const*);
63 
64  private:
65  template <typename T, typename U>
66  void cast(T const* node) {
67  visit(dynamic_cast<U const*>(node));
68  }
69 
70  template <typename T, size_t N>
71  using Handlers = std::array<TypeHandler<RelRexDagVisitor, T>, N>;
72 
73  template <typename T, typename... Ts>
74  static Handlers<T, sizeof...(Ts)> make_handlers();
75 };
virtual void visit(RelScan const *)
void cast(T const *node)
void visit(RelAlgNode const *)
virtual void visit(RexInput const *)
virtual void visit(RexRef const *)
virtual void visit(RexAbstractInput const *)
std::array< TypeHandler< RelRexDagVisitor, T >, N > Handlers
static Handlers< T, sizeof...(Ts)> make_handlers()
virtual void visit(RexLiteral const *)
virtual void visit(RelAggregate const *)
virtual ~RelRexDagVisitor()=default
virtual void visit(RelLogicalUnion const *)
virtual void visit(RelSort const *)
virtual void visit(RelModify const *)