-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathOrderEvaluator.java
76 lines (67 loc) · 2.83 KB
/
OrderEvaluator.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
import net.sf.jsqlparser.expression.Expression;
import net.sf.jsqlparser.expression.Function;
import net.sf.jsqlparser.expression.PrimitiveValue;
import net.sf.jsqlparser.schema.Column;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Set;
/**
* Created by Mugdha on 7/4/2017.
*/
public class OrderEvaluator {
HashMap<PrimitiveValue,ArrayList<PrimitiveValue[]>> groupByMap;
ArrayList<PrimitiveValue[]> outputTupleList; // output of group or having or selection operation
HashMap<String, String> aliasHashMap;
Column[] schema;
Function function;
Boolean isAsc;
public OrderEvaluator(Function function, HashMap groupByMap, HashMap aliasHashMap,
Column[] schema, ArrayList outputTupleList, Boolean isAsc){
this.function = function;
this.groupByMap = groupByMap;
this.aliasHashMap = aliasHashMap;
this.schema = schema;
this.outputTupleList = outputTupleList;
this.isAsc = isAsc;
}
public ArrayList execute(){
String funcitonName = function.getName();
Boolean allColumns = function.isAllColumns();
int columnIndex = 0;
Expression columnExpression;
String tableName;
if(!allColumns){
columnExpression = function.getParameters().getExpressions().get(0);
if(columnExpression instanceof Column){
Column column = (Column)columnExpression;
if(column.getTable().getName().toLowerCase() != null) {
if(aliasHashMap.containsKey(column.getTable().getName().toLowerCase())) {
tableName = aliasHashMap.get(column.getTable().getName().toLowerCase());
for(int i = 0; i < schema.length; i++) {
if(schema[i].getTable().getName().toLowerCase().equals(tableName)) {
if(schema[i].getColumnName().toLowerCase().equals(column.getColumnName().toLowerCase())) {
columnIndex = i;
break;
}
}
}
} else {
System.out.println("ERROR in OrderEvaluator: alias not present in aliasHashMap");
}
}
else {
for(int i = 0; i < schema.length; i++) {
if(schema[i].getColumnName().toLowerCase().equals(column.getColumnName().toLowerCase())) {
columnIndex = i;
break;
}
}
}
}
Set keySet = groupByMap.keySet();
Iterator itr = keySet.iterator();
}
return outputTupleList;
}
}