DeveelDB  20151217
complete SQL database system, primarly developed for .NET/Mono frameworks
QueryNodeTableNameVisitor.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 using System.Collections.Generic;
19 namespace Deveel.Data.Sql.Query {
21  private readonly IList<ObjectName> tableNames;
22 
24  tableNames = new List<ObjectName>();
25  }
26 
27  public IList<ObjectName> Discover(IQueryPlanNode queryPlan) {
28  VisitNode(queryPlan);
29  return tableNames;
30  }
31 
32  protected override IQueryPlanNode VisitFetchTable(FetchTableNode node) {
33  if (!tableNames.Contains(node.TableName))
34  tableNames.Add(node.TableName);
35 
36  return base.VisitFetchTable(node);
37  }
38 
39  protected override IQueryPlanNode VisitFetchView(FetchViewNode node) {
40  if (!tableNames.Contains(node.ViewName))
41  tableNames.Add(node.ViewName);
42 
43  return base.VisitFetchView(node);
44  }
45 
46  protected override IQueryPlanNode VisitJoin(JoinNode node) {
47  if (node.RightExpression != null)
48  node.RightExpression.DiscoverTableNames(tableNames);
49 
50  return base.VisitJoin(node);
51  }
52 
54  if (node.Expression != null)
55  node.Expression.DiscoverTableNames(tableNames);
56 
57  return base.VisitConstantSelect(node);
58  }
59 
60  protected override IQueryPlanNode VisitRangeSelect(RangeSelectNode node) {
61  if (node.Expression != null)
62  node.Expression.DiscoverTableNames(tableNames);
63 
64  return base.VisitRangeSelect(node);
65  }
66 
68  if (node.Expression != null)
69  node.Expression.DiscoverTableNames(tableNames);
70 
71  return base.VisitSimpleSelect(node);
72  }
73 
74  protected override IQueryPlanNode VisitGroup(GroupNode node) {
75  if (node.Functions != null) {
76  foreach (var function in node.Functions) {
77  function.DiscoverTableNames(tableNames);
78  }
79  }
80 
81  return base.VisitGroup(node);
82  }
83 
85  if (node.Expression != null)
86  node.Expression.DiscoverTableNames(tableNames);
87 
88  return base.VisitExhaustiveSelect(node);
89  }
90 
92  if (node.Expression != null)
93  node.Expression.DiscoverTableNames(tableNames);
94 
95  return base.VisitSimplePatternSelect(node);
96  }
97  }
98 }
The node for evaluating an expression that contains entirely constant values (no variables).
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...
override IQueryPlanNode VisitFetchView(FetchViewNode node)
override IQueryPlanNode VisitGroup(GroupNode 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.
override IQueryPlanNode VisitRangeSelect(RangeSelectNode node)
override IQueryPlanNode VisitJoin(JoinNode node)
override IQueryPlanNode VisitExhaustiveSelect(ExhaustiveSelectNode node)
SqlExpression RightExpression
Definition: JoinNode.cs:45
The node for performing a exhaustive select operation on the child node.
SqlExpression Expression
The search expression.
override IQueryPlanNode VisitSimpleSelect(SimpleSelectNode node)
ObjectName TableName
The name of the table to fetch.
override IQueryPlanNode VisitSimplePatternSelect(SimplePatternSelectNode node)
override IQueryPlanNode VisitConstantSelect(ConstantSelectNode node)
override IQueryPlanNode VisitFetchTable(FetchTableNode node)
IList< ObjectName > Discover(IQueryPlanNode queryPlan)
The node for fetching a table from the current transaction.