DeveelDB  20151217
complete SQL database system, primarly developed for .NET/Mono frameworks
QueryPlanNodeVisitor.cs
Go to the documentation of this file.
1 //
2 // Copyright 2010-2015 Deveel
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 using System;
18 
19 namespace Deveel.Data.Sql.Query {
22  return VisitNode(node);
23  }
24 
25  protected virtual IQueryPlanNode VisitNode(IQueryPlanNode node) {
26  if (node is SingleQueryPlanNode)
27  return VisitSingle((SingleQueryPlanNode) node);
28  if (node is BranchQueryPlanNode)
29  return VisitBranch((BranchQueryPlanNode) node);
30  if (node is FetchTableNode)
31  return VisitFetchTable((FetchTableNode) node);
32  if (node is FetchViewNode)
33  return VisitFetchView((FetchViewNode) node);
34  if (node is SingleRowTableNode)
35  return VisitSingleRowTable((SingleRowTableNode) node);
36 
37  throw new NotSupportedException();
38  }
39 
41  return new SingleRowTableNode();
42  }
43 
44  protected virtual IQueryPlanNode VisitFetchView(FetchViewNode node) {
45  return new FetchViewNode(node.ViewName, node.AliasName);
46  }
47 
48  protected virtual IQueryPlanNode VisitFetchTable(FetchTableNode node) {
49  return new FetchTableNode(node.TableName, node.AliasName);
50  }
51 
53  if (node is SimpleSelectNode)
54  return VisitSimpleSelect((SimpleSelectNode) node);
55  if (node is SimplePatternSelectNode)
56  return VisitSimplePatternSelect((SimplePatternSelectNode) node);
57  if (node is ExhaustiveSelectNode)
58  return VisitExhaustiveSelect((ExhaustiveSelectNode) node);
59  if (node is ConstantSelectNode)
60  return VisitConstantSelect((ConstantSelectNode) node);
61  if (node is RangeSelectNode)
62  return VisitRangeSelect((RangeSelectNode) node);
63  if (node is DistinctNode)
64  return VisitDistinct((DistinctNode) node);
65  if (node is LeftOuterJoinNode)
66  return VisitLeftOuterJoin((LeftOuterJoinNode) node);
67  if (node is CachePointNode)
68  return VisitCachePoint((CachePointNode) node);
69  if (node is MarkerNode)
70  return VisitMarker((MarkerNode) node);
71  if (node is SubsetNode)
72  return VisitSubset((SubsetNode) node);
73  if (node is GroupNode)
74  return VisitGroup((GroupNode) node);
75  if (node is SortNode)
76  return VisitSort((SortNode) node);
77  if (node is CreateFunctionsNode)
78  return VisitCreateFunctions((CreateFunctionsNode) node);
79  if (node is LimitNode)
80  return VisitLimit((LimitNode) node);
81 
82  throw new NotSupportedException();
83  }
84 
85  protected virtual IQueryPlanNode VisitLimit(LimitNode node) {
86  var child = node.Child;
87  if (child != null)
88  child = VisitNode(child);
89 
90  return new LimitNode(child, node.Offset, node.Count);
91  }
92 
94  var child = node.Child;
95  if (child != null)
96  child = VisitNode(child);
97 
98  return new CreateFunctionsNode(child, node.Functions, node.Names);
99  }
100 
102  if (node is CompositeNode)
103  return VisitComposite((CompositeNode) node);
104  if (node is JoinNode)
105  return VisitJoin((JoinNode) node);
106  if (node is EquiJoinNode)
107  return VisitEquiJoin((EquiJoinNode) node);
108  if (node is NaturalJoinNode)
109  return VisitNaturalJoin((NaturalJoinNode) node);
110  if (node is LogicalUnionNode)
111  return VisitLogicalUnion((LogicalUnionNode) node);
112  if (node is NonCorrelatedAnyAllNode)
113  return VisitNonCorrelatedAnyAll((NonCorrelatedAnyAllNode) node);
114 
115  throw new NotSupportedException();
116  }
117 
119  var left = node.Left;
120  var right = node.Right;
121  if (left != null)
122  left = VisitNode(left);
123  if (right != null)
124  right = VisitNode(right);
125 
126  return new NonCorrelatedAnyAllNode(left, right, node.LeftColumnNames, node.SubQueryType);
127  }
128 
130  var left = node.Left;
131  var right = node.Right;
132  if (left != null)
133  left = VisitNode(left);
134  if (right != null)
135  right = VisitNode(right);
136 
137  return new LogicalUnionNode(left, right);
138  }
139 
140  protected virtual IQueryPlanNode VisitJoin(JoinNode node) {
141  var left = node.Left;
142  var right = node.Right;
143  if (left != null)
144  left = VisitNode(left);
145  if (right != null)
146  right = VisitNode(right);
147 
148  return new JoinNode(left, right, node.LeftColumnName, node.Operator, node.RightExpression);
149  }
150 
152  var left = node.Left;
153  var right = node.Right;
154  if (left != null)
155  left = VisitNode(left);
156  if (right != null)
157  right = VisitNode(right);
158 
159  return new NaturalJoinNode(left, right);
160  }
161 
162  protected virtual IQueryPlanNode VisitEquiJoin(EquiJoinNode node) {
163  var left = node.Left;
164  var right = node.Right;
165  if (left != null)
166  left = VisitNode(left);
167  if (right != null)
168  right = VisitNode(right);
169 
170  return new EquiJoinNode(left, right, node.LeftColumns, node.RightColumns);
171  }
172 
173  protected virtual IQueryPlanNode VisitComposite(CompositeNode node) {
174  var left = node.Left;
175  var right = node.Right;
176  if (left != null)
177  left = VisitNode(left);
178  if (right != null)
179  right = VisitNode(right);
180 
181  return new CompositeNode(left, right, node.CompositeFunction, node.All);
182  }
183 
184  protected virtual IQueryPlanNode VisitMarker(MarkerNode node) {
185  var child = node.Child;
186  if (child != null)
187  child = VisitNode(child);
188 
189  return new MarkerNode(child, node.MarkName);
190  }
191 
193  var child = node.Child;
194  if (child != null)
195  child = VisitNode(child);
196 
197  return new LeftOuterJoinNode(child, node.MarkerName);
198  }
199 
200  protected virtual IQueryPlanNode VisitGroup(GroupNode node) {
201  var child = node.Child;
202  if (child != null)
203  child = VisitNode(child);
204 
205  return new GroupNode(child, node.ColumnNames, node.GroupMaxColumn, node.Functions, node.Names);
206  }
207 
209  var child = node.Child;
210  if (child != null)
211  child = VisitNode(child);
212 
213  return new SimplePatternSelectNode(child, node.Expression);
214  }
215 
217  var child = node.Child;
218  if (child != null)
219  child = VisitNode(child);
220 
221  return new RangeSelectNode(child, node.Expression);
222  }
223 
225  var child = node.Child;
226  if (child != null)
227  child = VisitNode(child);
228 
229  return new CachePointNode(child);
230  }
231 
232  protected virtual IQueryPlanNode VisitSort(SortNode node) {
233  var child = node.Child;
234  if (child != null)
235  child = VisitNode(child);
236 
237  return new SortNode(child, node.ColumnNames, node.Ascending);
238  }
239 
240  protected virtual IQueryPlanNode VisitDistinct(DistinctNode node) {
241  var child = node.Child;
242  if (child != null)
243  child = VisitNode(child);
244 
245  return new DistinctNode(child, node.ColumnNames);
246  }
247 
249  var child = node.Child;
250  if (child != null)
251  child = VisitNode(child);
252 
253  return new ConstantSelectNode(child, node.Expression);
254  }
255 
257  var child = node.Child;
258  if (child != null)
259  child = VisitNode(child);
260 
261  return new ExhaustiveSelectNode(child, node.Expression);
262  }
263 
265  var child = node.Child;
266  if (child != null)
267  child = VisitNode(child);
268 
269  return new SimpleSelectNode(child, node.ColumnName, node.OperatorType, node.Expression);
270  }
271 
272  protected virtual IQueryPlanNode VisitSubset(SubsetNode node) {
273  var child = node.Child;
274  if (child != null)
275  child = VisitNode(child);
276 
277  return new SubsetNode(child, node.OriginalColumnNames, node.AliasColumnNames);
278  }
279  }
280 }
IQueryPlanNode Right
Gets the right node of the branch query plan node.
bool All
If this is true, the composite includes all results from both children, otherwise removes deplicates...
A branch node for performing a composite function on two child nodes.
string[] Names
The list of names to give each function table.
ObjectName AliasName
The name to alias the table as.
virtual IQueryPlanNode VisitSort(SortNode node)
IQueryPlanNode Child
Gets the single child node of the plan.
The node for evaluating an expression that contains entirely constant values (no variables).
A IQueryPlanNode with a single child.
A query to the database to select data from a set of tables and columns.
SqlExpression Expression
A simple expression that represents the range to select. See the class comments for a description for...
virtual IQueryPlanNode VisitLeftOuterJoin(LeftOuterJoinNode node)
virtual IQueryPlanNode VisitSimplePatternSelect(SimplePatternSelectNode node)
virtual IQueryPlanNode VisitSingleRowTable(SingleRowTableNode node)
virtual IQueryPlanNode VisitConstantSelect(ConstantSelectNode node)
SqlExpressionType Operator
Definition: JoinNode.cs:43
virtual IQueryPlanNode VisitCreateFunctions(CreateFunctionsNode node)
virtual IQueryPlanNode VisitJoin(JoinNode node)
virtual IQueryPlanNode VisitRangeSelect(RangeSelectNode node)
virtual IQueryPlanNode VisitLimit(LimitNode node)
The node for performing a simple indexed query on a single column of the child node.
A node element of a query plan tree. /summary>
The node for performing a simple select operation on a table.
virtual IQueryPlanNode VisitSimpleSelect(SimpleSelectNode node)
A marker node that takes the result of a child and marks it as a name that can later be retrieved...
Definition: MarkerNode.cs:32
virtual IQueryPlanNode VisitNode(IQueryPlanNode node)
The node for merging the child node with a set of new function columns over the entire result...
virtual IQueryPlanNode VisitBranch(BranchQueryPlanNode node)
virtual IQueryPlanNode VisitNaturalJoin(NaturalJoinNode node)
SqlExpression[] Functions
The list of functions to create.
virtual IQueryPlanNode VisitFetchTable(FetchTableNode node)
SqlExpression RightExpression
Definition: JoinNode.cs:45
The node for performing a exhaustive select operation on the child node.
A branch node for a left outer join.
virtual IQueryPlanNode VisitSubset(SubsetNode node)
SqlExpression Expression
The search expression.
virtual IQueryPlanNode VisitGroup(GroupNode node)
ObjectName TableName
The name of the table to fetch.
CompositeFunction CompositeFunction
The composite operation.
virtual IQueryPlanNode VisitCachePoint(CachePointNode node)
virtual IQueryPlanNode VisitEquiJoin(EquiJoinNode node)
virtual IQueryPlanNode VisitLogicalUnion(LogicalUnionNode node)
virtual IQueryPlanNode VisitComposite(CompositeNode node)
A branch node for naturally joining two tables together.
A IQueryPlanNode implementation that is a branch with two child nodes.
virtual IQueryPlanNode VisitMarker(MarkerNode node)
virtual IQueryPlanNode VisitExhaustiveSelect(ExhaustiveSelectNode node)
virtual IQueryPlanNode VisitSingle(SingleQueryPlanNode node)
virtual IQueryPlanNode VisitDistinct(DistinctNode node)
virtual IQueryPlanNode VisitFetchView(FetchViewNode node)
IQueryPlanNode Visit(IQueryPlanNode node)
IQueryPlanNode Left
Gets the left node of the branch query plan node.
The node for fetching a table from the current transaction.
virtual IQueryPlanNode VisitNonCorrelatedAnyAll(NonCorrelatedAnyAllNode node)