-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathExpressionFinder.java
215 lines (195 loc) · 7.07 KB
/
ExpressionFinder.java
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
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
import net.sf.jsqlparser.eval.Eval;
import net.sf.jsqlparser.expression.*;
import net.sf.jsqlparser.expression.operators.arithmetic.*;
import net.sf.jsqlparser.expression.operators.conditional.AndExpression;
import net.sf.jsqlparser.expression.operators.conditional.OrExpression;
import net.sf.jsqlparser.expression.operators.relational.*;
import net.sf.jsqlparser.schema.Column;
import net.sf.jsqlparser.statement.create.table.CreateTable;
import net.sf.jsqlparser.statement.select.SubSelect;
import java.util.HashMap;
class ExpressionFinder implements ExpressionVisitor {
ExpressionFinder(Expression expression) {
expression.accept(this);
}
public void solve(Expression e) {
e.accept(this);
}
public void visit(NullValue nullValue) {
System.out.println("InsideNullValueExpression");
}
public void visit(Function function) {
System.out.println("InsideFunctionExpression");
}
public void visit(InverseExpression inverseExpression) {
System.out.println("InsideInverseExpression");
}
public void visit(JdbcParameter jdbcParameter) {
System.out.println("InsideJdbcParameterExpression");
}
public void visit(DoubleValue doubleValue) {
System.out.println("InsideDoubleValueExpression");
}
public void visit(LongValue longValue) {
System.out.println("InsideLongValueExpression");
}
public void visit(DateValue dateValue) {
System.out.println("InsideDateValueExpression");
}
public void visit(TimeValue timeValue) {
System.out.println("InsideTimeValueExpression");
}
public void visit(TimestampValue timestampValue) {
System.out.println("InsideTimeStampValueExpression");
}
public void visit(BooleanValue booleanValue) {
System.out.println("InsideBooleanValueExpression");
}
public void visit(StringValue stringValue) {
System.out.println("InsideStringValueExpression");
}
public void visit(Addition addition) {
System.out.println("InsideAdditionExpression");
}
public void visit(Division division) {
System.out.println("InsideDivisionExpression");
}
public void visit(Multiplication multiplication) {
System.out.println("InsideMultiplicationExpression");
}
public void visit(Subtraction subtraction) {
System.out.println("InsideSubtractionExpression");
}
public void visit(AndExpression andExpression) {
System.out.println("InsideANDExpression");
Expression leftExpression = andExpression.getLeftExpression();
System.out.println("VisitingLeftANDExpression");
leftExpression.accept(this);
Expression rightExpression = andExpression.getRightExpression();
System.out.println("VisitingRightANDExpression");
rightExpression.accept(this);
}
public void visit(OrExpression orExpression) {
System.out.println("InsideORExpression");
}
public void visit(Between between) {
System.out.println("InsideBetweenExpression");
}
public void visit(EqualsTo equalsTo) {
/* System.out.println("InsideEqualsToExpression");
Expression leftExpression = equalsTo.getLeftExpression();
Expression rightExpression = equalsTo.getRightExpression();
if(leftExpression instanceof Column && rightExpression instanceof Column) {
System.out.println("Found Join");
System.out.println(((Column)leftExpression).getTable().getName());
System.out.println(((Column)rightExpression).getTable().getName());
Column col1 = (Column)leftExpression;
Column col2 = (Column)rightExpression;
String tableName1 = col1.getTable().getName();
String tableName2 = col2.getTable().getName();
if(!(aliasTableMap.get(tableName1) == null)) {
tableName1 = aliasTableMap.get(tableName1);
}
if(!(aliasTableMap.get(tableName2) == null)) {
tableName2 = aliasTableMap.get(tableName2);
}
ScanOperator leftScanner = new ScanOperator(tableName1, tableMap);
ScanOperator rightScanner = new ScanOperator(tableName2, tableMap);
PrimitiveValue[] reader1;
PrimitiveValue[] reader2;
while((reader1 = leftScanner.readOneTuple()) != null) {
rightScanner.reset();
while((reader2 = rightScanner.readOneTuple()) != null) {
Eval eval = new Eval(){
public PrimitiveValue eval(Column c) {
String colName = c.getColumnName();
String tableName = c.getTable().getName();
if(!(aliasTableMap.get(tableName) == null)) {
tableName = aliasTableMap.get(tableName);
}
System.out.println("Column: " + colName +" AND Table: " + tableName);
PrimitiveValue ret = null;
if (colName.equals(col1.getColumnName())) {
//ret = reader1[schemas.get(tableName).get(colName).colId];
}
if (colName.equals(col2.getColumnName())) {
//ret = reader2[schemas.get(tableName).get(colName).colId];
}
//PrimitiveValue ret = new DoubleValue(7.0);
return ret;
}
};
//PrimitiveValue result = eval.eval(equalsTo);
*//*if(result.toBool()) {
System.out.println("Result: " + result);
System.out.println("Row : " + reader2);
}else {
}*//*
}
}
//PrimitiveValue result = eval.eval(equalsTo);
}else if(leftExpression instanceof Column && rightExpression instanceof PrimitiveValue) {
System.out.println("Found Comparison condition");
}*/
}
public void visit(GreaterThan greaterThan) {
System.out.println("InsideGreaterThanExpression");
}
public void visit(GreaterThanEquals greaterThanEquals) {
System.out.println("InsideGreaterThanEqualsExpression");
}
public void visit(InExpression inExpression) {
System.out.println("InsideInExpression");
}
public void visit(IsNullExpression isNullExpression) {
System.out.println("InsideIsNullExpression");
}
public void visit(LikeExpression likeExpression) {
System.out.println("InsideLikeExpression");
}
public void visit(MinorThan minorThan) {
System.out.println("InsideMinorThanExpression");
}
public void visit(MinorThanEquals minorThanEquals) {
System.out.println("InsideMinorThanEqualsExpression");
}
public void visit(NotEqualsTo notEqualsTo) {
System.out.println("InsideNotEqualsToExpression");
}
public void visit(Column tableColumn) {
System.out.println("InsideTableColumnExpression");
}
public void visit(SubSelect subSelect) {
System.out.println("InsideSubSelectExpression");
}
public void visit(CaseExpression caseExpression) {
System.out.println("InsideCaseExpression");
}
public void visit(WhenClause whenClause) {
System.out.println("InsideWhenClauseExpression");
}
public void visit(ExistsExpression existsExpression) {
System.out.println("InsideExistsExpression");
}
public void visit(AllComparisonExpression allComparisonExpression) {
System.out.println("InsideAllComparisonExpression");
}
public void visit(AnyComparisonExpression anyComparisonExpression) {
System.out.println("InsideAnyComparisonExpression");
}
public void visit(Concat concat) {
System.out.println("InsideConcatExpression");
}
public void visit(Matches matches) {
System.out.println("InsideMatchesExpression");
}
public void visit(BitwiseAnd bitwiseAnd) {
System.out.println("InsideBitwiseAndExpression");
}
public void visit(BitwiseOr bitwiseOr) {
System.out.println("InsideBitwiseORExpression");
}
public void visit(BitwiseXor bitwiseXor) {
System.out.println("InsideBitwiseXORExpression");
}
}