-
Notifications
You must be signed in to change notification settings - Fork 0
/
ScanOperator.java
84 lines (78 loc) · 2.37 KB
/
ScanOperator.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
import net.sf.jsqlparser.expression.*;
import net.sf.jsqlparser.statement.create.table.ColumnDefinition;
import net.sf.jsqlparser.statement.create.table.CreateTable;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import java.lang.reflect.Field;
import java.util.DoubleSummaryStatistics;
import java.util.HashMap;
import java.util.List;
/**
* Created by Karan on 6/26/2017.
*/
public class ScanOperator implements Operator {
BufferedReader input;
File f;
CreateTable ct;
public ScanOperator(File f, CreateTable ct) {
this.f = f;
this.ct = ct;
reset();
}
public PrimitiveValue[] readOneTuple() {
if (input == null) {
return null;
}
String line = null;
try {
line = input.readLine();
} catch (IOException e) {
e.printStackTrace();
}
if (line == null) {
return null;
}
String[] cols = line.split("\\|");
PrimitiveValue ret[] = new PrimitiveValue[cols.length];
List<ColumnDefinition> columnDefinitionList = ct.getColumnDefinitions();
for (int i = 0; i < cols.length; i++) {
if(cols[i].equals("NULL")) {
ret[i] = new NullValue();
continue;
}
String colDataType = columnDefinitionList.get(i).getColDataType().getDataType();
switch (colDataType) {
case "STRING":
case "VARCHAR":
case "CHAR":
ret[i] = new StringValue(cols[i]);
break;
case "INTEGER":
ret[i] = new LongValue(cols[i]);
break;
case "DECIMAL":
ret[i] = new DoubleValue(cols[i]);
break;
case "DATE":
ret[i] = new DateValue(cols[i]);
break;
case "DOUBLE":
ret[i] = new DoubleValue(cols[i]);
break;
default:
ret[i] = null;
}
}
return ret;
}
public void reset() {
try {
input = new BufferedReader(new FileReader(f));
} catch (IOException e) {
e.printStackTrace();
input = null;
}
}
}