Skip to content

Commit

Permalink
join path translation for multiple tables
Browse files Browse the repository at this point in the history
  • Loading branch information
kepingwang committed Dec 2, 2016
1 parent 2beb78a commit dc4b845
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 9 deletions.
2 changes: 1 addition & 1 deletion src/main/java/model/SQLQuery.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public class SQLQuery {
map = new HashMap<>();
map.put("SELECT", new ArrayList<String>());
map.put("FROM", new HashSet<String>());
map.put("WHERE", new ArrayList<String>());
map.put("WHERE", new HashSet<String>());
}

@Deprecated
Expand Down
25 changes: 18 additions & 7 deletions src/main/java/model/SQLTranslator.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,8 @@
public class SQLTranslator {
private SQLQuery query;
private SchemaGraph schema;
private Node root;

public SQLTranslator(Node root, SchemaGraph schema) {
this.root = root;
this.schema = schema;
query = new SQLQuery();

Expand Down Expand Up @@ -108,15 +106,28 @@ private void translateSClause(Node node) {
translateGNP(node.getChildren().get(0));
}

private void addJoinPath() {
List<String> fromTables = new ArrayList<String>(query.getCollection("FROM"));
if (fromTables.size() <= 1) { return; }
String table1 = fromTables.get(0);
String table2 = fromTables.get(1);
private void addJoinKeys(String table1, String table2) {
Set<String> joinKeys = schema.getJoinKeys(table1, table2);
for (String joinKey : joinKeys) {
query.add("WHERE", table1+"."+joinKey+" = "+table2+"."+joinKey);
}
}

private void addJoinPath(List<String> joinPath) {
for (int i = 0; i < joinPath.size()-1; i++) {
addJoinKeys(joinPath.get(i), joinPath.get(i+1));
}
}

private void addJoinPath() {
List<String> fromTables = new ArrayList<String>(query.getCollection("FROM"));
if (fromTables.size() <= 1) { return; }
for (int i = 0; i < fromTables.size()-1; i++) {
for (int j = i+1; j < fromTables.size(); j++) {
List<String> joinPath = schema.getJoinPath(fromTables.get(i), fromTables.get(j));
addJoinPath(joinPath);
}
}
}

}
3 changes: 2 additions & 1 deletion src/main/java/ui/UserView.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@
import model.NodeInfo;

public class UserView extends Application {
private static final String TEST_TEXT = "Return number of authors who published theory papers before 1980.";
private static final String TEST_TEXT = "Return the number of authors who published both journal and conference papers after 2000.";
// "Return number of authors who published theory papers before 1980."

Stage stage; // the window
Scene scene; // the main content in the window
Expand Down

0 comments on commit dc4b845

Please sign in to comment.