-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathSqlBaseVisitor.cs
More file actions
189 lines (166 loc) · 6.61 KB
/
SqlBaseVisitor.cs
File metadata and controls
189 lines (166 loc) · 6.61 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
// Licensed under the Apache License, Version 2.0 (the "License")
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
using SqlParser.Ast;
namespace FlowtideDotNet.Substrait.Sql.Internal
{
internal class SqlBaseVisitor<TReturn, TState>
{
public virtual TReturn Visit(Statement statement, TState state)
{
if (statement is Statement.Insert insert)
{
return VisitInsertStatement(insert, state);
}
if (statement is Statement.Select select)
{
return VisitQuery(select.Query, state);
}
if (statement is Statement.CreateTable createTable)
{
return VisitCreateTable(createTable, state);
}
if (statement is Statement.CreateView createView)
{
return VisitCreateView(createView, state);
}
if (statement is BeginSubStream beginSubStream)
{
return VisitBeginSubStream(beginSubStream);
}
if (statement is Statement.SetVariable setVariable)
{
return VisitSetVariable(setVariable);
}
throw new NotImplementedException();
}
protected virtual TReturn VisitSetVariable(Statement.SetVariable setVariable)
{
throw new NotImplementedException();
}
protected virtual TReturn VisitBeginSubStream(BeginSubStream beginSubStream)
{
throw new NotImplementedException();
}
protected virtual TReturn VisitCreateView(Statement.CreateView createView, TState state)
{
throw new NotImplementedException();
}
protected virtual TReturn VisitCreateTable(Statement.CreateTable createTable, TState state)
{
throw new NotImplementedException();
}
protected virtual TReturn VisitInsertStatement(Statement.Insert insert, TState state)
{
throw new NotImplementedException();
}
protected virtual TReturn VisitQuery(Query query, TState state)
{
throw new NotImplementedException();
}
public virtual TReturn Visit(Expression expression, TState state)
{
if (expression is Expression.BinaryOp binaryOp)
{
return VisitBinaryOperation(binaryOp, state);
}
if (expression is Expression.CompoundIdentifier compoundIdentifier)
{
return VisitCompoundIdentifier(compoundIdentifier, state);
}
throw new NotImplementedException();
}
protected virtual TReturn VisitCompoundIdentifier(Expression.CompoundIdentifier compoundIdentifier, TState state)
{
throw new NotImplementedException();
}
protected virtual TReturn VisitBinaryOperation(Expression.BinaryOp binaryOp, TState state)
{
throw new NotImplementedException();
}
public virtual TReturn Visit(SetExpression setExpression, TState state)
{
if (setExpression is SetExpression.Insert insert)
{
return VisitInsertSetExpression(insert, state);
}
if (setExpression is SetExpression.QueryExpression queryExpression)
{
return VisitQuery(queryExpression.Query, state);
}
if (setExpression is SetExpression.SelectExpression selectExpression)
{
return VisitSelectSetExpression(selectExpression, state);
}
if (setExpression is SetExpression.SetOperation setOperation)
{
return VisitSetOperation(setOperation, state);
}
if (setExpression is SetExpression.ValuesExpression valuesExpression)
{
return VisitValuesExpression(valuesExpression, state);
}
throw new NotImplementedException($"{setExpression.GetType().Name} is not yet supported in SQL.");
}
protected virtual TReturn VisitValuesExpression(SetExpression.ValuesExpression valuesExpression, TState state)
{
throw new NotImplementedException();
}
protected virtual TReturn VisitSetOperation(SetExpression.SetOperation setOperation, TState state)
{
throw new NotImplementedException($"{setOperation.GetType().Name} is not yet supported in SQL.");
}
private TReturn VisitInsertSetExpression(SetExpression.Insert insert, TState state)
{
return Visit(insert.Statement, state);
}
private TReturn VisitQuerySetExpression(SetExpression.QueryExpression queryExpression, TState state)
{
throw new NotImplementedException();
}
private TReturn VisitSelectSetExpression(SetExpression.SelectExpression selectExpression, TState state)
{
return VisitSelect(selectExpression.Select, state);
}
protected virtual TReturn VisitSelect(Select select, TState state)
{
throw new NotImplementedException();
}
public virtual TReturn Visit(TableWithJoins tableWithJoins, TState state)
{
return VisitTableWithJoins(tableWithJoins, state);
}
protected virtual TReturn VisitTableWithJoins(TableWithJoins tableWithJoins, TState state)
{
throw new NotImplementedException();
}
public virtual TReturn Visit(TableFactor tableFactor, TState state)
{
if (tableFactor is TableFactor.Table table)
{
return VisitTable(table, state);
}
if (tableFactor is TableFactor.Derived derived)
{
return VisitDerivedTable(derived, state);
}
throw new NotImplementedException();
}
protected virtual TReturn VisitDerivedTable(TableFactor.Derived derived, TState state)
{
throw new NotImplementedException();
}
protected virtual TReturn VisitTable(TableFactor.Table table, TState state)
{
throw new NotImplementedException();
}
}
}