Skip to content

Commit 0b77d96

Browse files
committed
Working on execution part, main structure completed.
1 parent cd49ebb commit 0b77d96

File tree

7 files changed

+101
-17
lines changed

7 files changed

+101
-17
lines changed

Query/Engine/QueryExecution.java

Lines changed: 57 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,15 @@
22

33
import Query.Entities.PlanTree;
44
import Query.Execution.AllNodeScanExec;
5+
import Query.Execution.Execution;
56
import Query.Execution.ResultTable;
6-
import Query.Plan.AllNodeScanPlan;
7+
import Query.Plan.*;
78
import Utility.DBUtil;
89

10+
import java.util.ArrayList;
11+
import java.util.List;
12+
import java.util.Stack;
13+
914
/**
1015
* Created by liuche on 5/28/17.
1116
*
@@ -18,14 +23,61 @@ public class QueryExecution {
1823
this.dbUtil = util;
1924
}
2025

21-
2226
public void setTree(PlanTree tree){
2327
this.tree = tree;
2428
}
2529

26-
public ResultTable execute(AllNodeScanPlan plan){
27-
AllNodeScanExec allNodeScanExec = new AllNodeScanExec(dbUtil, plan);
28-
return allNodeScanExec.execute();
30+
public ResultTable execute(){
31+
List<Execution> executionList = new ArrayList<>();
32+
for(Plan plan : tree.toList()){
33+
if(plan instanceof AllNodeScanPlan){
34+
35+
}else if(plan instanceof ScanByLabelPlan){
36+
37+
}else if(plan instanceof ScanByPropertyPlan){
38+
39+
}else if(plan instanceof ScanByIdPlan){
40+
41+
}else if(plan instanceof ExpandIntoPlan){
42+
43+
}else if(plan instanceof ExpandAllPlan){
44+
45+
}else if(plan instanceof RangeExpandAllPlan){
46+
47+
}else if(plan instanceof RangeExpandIntoPlan){
48+
49+
}else if(plan instanceof NodeHashJoinPlan){
50+
51+
}else if(plan instanceof CartesianProductPlan){
52+
53+
}
54+
}
55+
56+
Stack<ResultTable> resStack = new Stack<>();
57+
for(Execution execution : executionList){
58+
switch (execution.operandCount()){
59+
case 0:
60+
resStack.push(execution.execute());
61+
break;
62+
case 1:
63+
ResultTable table = resStack.peek();
64+
resStack.pop();
65+
resStack.push(execution.execute(table));
66+
break;
67+
case 2:
68+
ResultTable table1 = resStack.peek();
69+
resStack.pop();
70+
ResultTable table2 = resStack.peek();
71+
resStack.pop();
72+
resStack.push(execution.execute(table1, table2));
73+
break;
74+
default:
75+
break;
76+
}
77+
}
78+
assert resStack.size() == 1;
79+
return resStack.peek();
80+
2981
}
3082

3183

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package Query.Execution;
22

33
import Query.Plan.AllNodeScanPlan;
4-
import Query.Plan.Plan;
54
import Utility.DBUtil;
65

76
/**
@@ -11,6 +10,17 @@ public class AllNodeScanExec extends Execution{
1110

1211
public AllNodeScanExec(DBUtil util, AllNodeScanPlan plan) {
1312
super(util, plan);
13+
this.isLeaf = true;
1414
}
15-
15+
16+
@Override
17+
public ResultTable execute() {
18+
this.dbUtil.startRecording();
19+
ResultTable table = new ResultTable();
20+
table.idTable.put(ResultTable.GID, getAllNodeGid());
21+
this.dbUtil.stopRecording();
22+
this.querySQL = this.dbUtil.getExecuteHistory();
23+
return table;
24+
}
25+
1626
}

Query/Execution/Execution.java

Lines changed: 28 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import Utility.DBUtil;
55
import DataImport.FileParser;
66

7+
import java.util.ArrayList;
78
import java.util.HashMap;
89
import java.util.List;
910
import java.util.Map;
@@ -12,46 +13,64 @@
1213
* Created by liuche on 6/5/17.
1314
*/
1415
public class Execution {
15-
private ResultTable resultTable;
16-
private Plan plan;
17-
private DBUtil dbUtil;
16+
protected ResultTable resultTable;
17+
protected Plan plan;
18+
protected int operandCount = 0;
19+
protected DBUtil dbUtil;
20+
protected List<String> querySQL = new ArrayList<>();
1821

1922
public Execution(DBUtil util, Plan plan){
2023
this.dbUtil = util;
2124
this.resultTable = new ResultTable();
2225
this.plan = plan;
2326
}
2427

28+
public int operandCount(){
29+
return operandCount();
30+
}
31+
32+
public List<String> getQuerySQL(){
33+
return this.querySQL;
34+
}
35+
2536
public ResultTable execute(){
2637
return resultTable;
2738
}
2839

29-
private List<String> getAllNodeGid(){
40+
public ResultTable execute(ResultTable table1){
41+
return resultTable;
42+
}
43+
44+
public ResultTable execute(ResultTable table1, ResultTable table2){
45+
return resultTable;
46+
}
47+
48+
protected List<String> getAllNodeGid(){
3049
String statement = "SELECT COUNT(*) FROM ObjectType WHERE type != \"0\";";
3150
return dbUtil.getListFromSQL(statement);
3251
}
3352

34-
private List<String> getNodeGidBy(String field, String value){
53+
protected List<String> getNodeGidBy(String field, String value){
3554
String statement = "SELECT gid FROM P_" + field + "WHERE " + field + " = \"" + value + "\";";
3655
return dbUtil.getListFromSQL(statement);
3756
}
3857

39-
private List<String> getEdgeIdByFromGid(String node1){
58+
protected List<String> getEdgeIdByFromGid(String node1){
4059
String statement = "SELECT eid FROM Edge WHERE node1 = \"" + node1 + "\";";
4160
return dbUtil.getListFromSQL(statement);
4261
}
4362

44-
private List<String> getEdgeIdByToGid(String node1){
63+
protected List<String> getEdgeIdByToGid(String node1){
4564
String statement = "SELECT eid FROM Edge WHERE node2 = \"" + node1 + "\";";
4665
return dbUtil.getListFromSQL(statement);
4766
}
4867

49-
private Map<String, String> expandEdge(String eid){
68+
protected Map<String, String> expandEdge(String eid){
5069
String statement = "SELECT * FROM edge WHERE eid = \"" + eid + "\";";
5170
return dbUtil.getObjectFromSQL(statement);
5271
}
5372

54-
private Map<String, String> expandObject(Integer gid){
73+
protected Map<String, String> expandObject(Integer gid){
5574
String statement = "SELECT type FROM ObjectType WHERE gid = \"" + gid.toString() + "\";";
5675
Integer nodeType = dbUtil.getIntegerFromSQL(statement);
5776
statement = "SELECT name FROM typeProperty WHERE id = \"" + nodeType.toString() + "\";";

Query/Execution/ResultTable.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
* Created by liuche on 6/5/17.
99
*/
1010
public class ResultTable {
11+
public static final String GID = "gid";
1112
public enum ObjectType {OBJECT, STRING, LIST, ID}
1213

1314
public Map<String, List<String>> idTable = new HashMap<>();

Query/Plan/ScanByIdPlan.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ public ScanByIdPlan(QueryIndexer queryIndexer, String node) {
2020
public void applyTo(PlanTable table) {
2121
table.nodes.add(variable);
2222
table.estimatedSize = estimatedSize;
23+
table.cost += 1;
2324
table.plans.add(this);
2425
}
2526

Query/Plan/ScanByLabelPlan.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ public ScanByLabelPlan(QueryIndexer queryIndexer, String node, List<String> labe
2727
public void applyTo(PlanTable table) {
2828
table.nodes.add(variable);
2929
table.estimatedSize = estimatedSize;
30+
table.cost += estimatedSize;
3031
table.plans.add(this);
3132
}
3233

Utility/DBUtil.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ public void startRecording(){
2222
this.recording = true;
2323
}
2424

25-
public void endRecording(){
25+
public void stopRecording(){
2626
this.recording = false;
2727
}
2828

0 commit comments

Comments
 (0)