-
Notifications
You must be signed in to change notification settings - Fork 0
/
FromScanner.java
78 lines (70 loc) · 2.74 KB
/
FromScanner.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
import net.sf.jsqlparser.schema.Column;
import net.sf.jsqlparser.schema.Table;
import net.sf.jsqlparser.statement.create.table.ColumnDefinition;
import net.sf.jsqlparser.statement.create.table.CreateTable;
import net.sf.jsqlparser.statement.select.*;
import java.io.File;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
/**
* Created by Karan on 6/27/2017.
*/
public class FromScanner implements FromItemVisitor {
HashMap<String, CreateTable> createTableMap;
HashMap<String, String> aliasHasMap;
HashMap<String, Operator> operatorMap;
ArrayList<Column> schemaList;
public Operator source = null;
public FromScanner(HashMap<String, CreateTable> createTableMap) {
this.createTableMap = createTableMap;
aliasHasMap = new HashMap<>();
operatorMap = new HashMap<>();
schemaList = new ArrayList<>();
}
public void visit(SubJoin subjoin) {
}
public void visit(SubSelect subSelect) {
String alias = "";
Column[] tempSchema;
if(subSelect.getAlias()!=null){
alias = subSelect.getAlias().toLowerCase();
aliasHasMap.put(alias,"fromtable");
}
else {
System.out.println("WARNING: FromScanner SubSelect: alias added as FT");
alias = "ft";
}
SelectBody selectBody = subSelect.getSelectBody();
if(selectBody instanceof PlainSelect){
PlainSelect plainSelect = (PlainSelect) selectBody;
SubselectEvaluator subselectEvaluator = new SubselectEvaluator(
plainSelect, createTableMap, alias
);
subselectEvaluator.execute();
tempSchema = subselectEvaluator.schema;
for(int i = 0; i < tempSchema.length; i++){
schemaList.add(tempSchema[i]);
}
this.createTableMap = subselectEvaluator.createTableMap;
operatorMap.put("fromtable",subselectEvaluator);
}
else{
System.out.println("ERROR: FromScanner : Union not handled in subSelect");
}
}
public void visit(Table table) {
CreateTable ct = createTableMap.get(table.getName().toLowerCase());
if(table.getAlias() != null) {
aliasHasMap.put(table.getAlias().toLowerCase(), table.getName().toLowerCase());
}
List cols = ct.getColumnDefinitions();
for(int i = 0; i < cols.size(); i++) {
ColumnDefinition col = (ColumnDefinition)cols.get(i);
schemaList.add(new Column(table, col.getColumnName().toLowerCase()));
}
source = new ScanOperator(
new File(table.getName().toLowerCase() + ".csv"), ct);
operatorMap.put(table.getName().toLowerCase(), source);
}
}