Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
1. Make sure you have Java 11 installed by running `java -v`
2. Clone the repo
3. In root, run `mvn clean install`
4. Set up Google style. To do this in IntelliJ, follow this guide: https://medium.com/swlh/configuring-google-style-guide-for-java-for-intellij-c727af4ef248
5. In IntelliJ, you may need to go to each module, click on src folder, mark directory as -> sources root.
This will let you run IntelliJ
3 changes: 2 additions & 1 deletion common/pom.xml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

Expand Down
6 changes: 0 additions & 6 deletions common/src/Main.java

This file was deleted.

3 changes: 2 additions & 1 deletion common/src/README.md
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
Common resources for other packages. To prevent circular dependencies, avoid adding dependencies on other packages to common.
Common resources for other packages. To prevent circular dependencies, avoid adding dependencies on
other packages to common.
12 changes: 12 additions & 0 deletions common/src/logical_node/Node.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package logical_node;

import java.util.List;

public abstract class Node {

public <R, C> R accept(Visitor<R, C> visitor, C context) {
return visitor.visitPlan(this, context);
}

List<Node> children;
}
13 changes: 13 additions & 0 deletions common/src/logical_node/Visitor.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package logical_node;

// Visitor interface needs to be aware of all implementations of Node to have visit{x}Node methods declared for each.
public abstract class Visitor<R, C> {

abstract R visitPlan(Node node, C context);

// Example visit node function. See examples directory for complete example of implemented visitor pattern.
// R visitDogNode(DogNode node, C context) {
// return visitPlan(node, context);
// }

}
12 changes: 12 additions & 0 deletions common/src/logical_node/examples/AnimalNode.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package logical_node.examples;

import java.util.List;

public abstract class AnimalNode {

public <R, C> R accept(AnimalVisitor<R, C> visitor, C context) {
return visitor.visitPlan(this, context);
}

List<AnimalNode> children;
}
15 changes: 15 additions & 0 deletions common/src/logical_node/examples/AnimalVisitor.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package logical_node.examples;

// Visitor interface needs to be aware of all implementations of Node to have visit{x}Node methods declared for each.
public abstract class AnimalVisitor<R, C> {

abstract R visitPlan(AnimalNode node, C context);

R visitDogNode(DogNode node, C context) {
return visitPlan(node, context);
}

R visitCatNode(CatNode node, C context) {
return visitPlan(node, context);
}
}
23 changes: 23 additions & 0 deletions common/src/logical_node/examples/CatNode.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package logical_node.examples;

public class CatNode extends AnimalNode {

@Override
public <R, C> R accept(AnimalVisitor<R, C> visitor, C context) {
return visitor.visitCatNode(this, context);
}

public CatNode(String id) {
this.children = null;
this.id = id;
}

@Override
public String toString() {
return "logical_node.examples.CatNode{" +
"id='" + id + '\'' +
'}';
}

String id;
}
25 changes: 25 additions & 0 deletions common/src/logical_node/examples/DogNode.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package logical_node.examples;

import java.util.List;

public class DogNode extends AnimalNode {

@Override
public <R, C> R accept(AnimalVisitor<R, C> visitor, C context) {
return visitor.visitDogNode(this, context);
}

public DogNode(String id, List<AnimalNode> children) {
this.children = children;
this.id = id;
}

@Override
public String toString() {
return "logical_node.examples.DogNode{" +
"id='" + id + '\'' +
'}';
}

String id;
}
26 changes: 26 additions & 0 deletions common/src/logical_node/examples/Main.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package logical_node.examples;

import java.util.ArrayList;
import java.util.List;

public class Main {

static AnimalNode createDogTree() {
DogNode dog1 = new DogNode("Leaf doggo", new ArrayList<>());
CatNode cat1 = new CatNode("Leaf kitty1");
CatNode cat2 = new CatNode("Leaf kitty2");
DogNode dog2 = new DogNode("Intermediate doggo", List.of(cat1, dog1));
DogNode dog3 = new DogNode("Root doggo", List.of(dog2, cat2));

return dog3;
}

public static void main(String[] args) {
AnimalNode node = createDogTree();

PrettyPrintVisitor visitor = new PrettyPrintVisitor();

// Enter plan on unknown node type
visitor.visitPlan(node, "");
}
}
27 changes: 27 additions & 0 deletions common/src/logical_node/examples/PrettyPrintVisitor.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package logical_node.examples;

public class PrettyPrintVisitor extends AnimalVisitor<Void, String> {

@Override
Void visitPlan(AnimalNode node, String context) {
node.accept(this, context);
return null;
}

@Override
Void visitDogNode(DogNode node, String context) {
// Print it's a good boy
System.out.println(context + node.toString());
// Enter children
for (AnimalNode n : node.children) {
visitPlan(n, context + " ");
}
return null;
}

@Override
Void visitCatNode(CatNode node, String context) {
System.out.println(context + node.toString());
return null;
}
}
4 changes: 4 additions & 0 deletions common/src/logical_node/examples/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Example of how to implement a visitor.

-- todo(jason) -> Put down our learnings as bullet points here- explain what a visitor does,
how to implement one for a specific type of node, how to add a new visitor/node
7 changes: 3 additions & 4 deletions common/src/types/Type.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@
* Types must map
*/
public enum Type {
INT,
VARCHAR,
BOOL
INT,
VARCHAR,
BOOL
}

3 changes: 2 additions & 1 deletion execution/pom.xml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

Expand Down
3 changes: 2 additions & 1 deletion main/pom.xml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

Expand Down
5 changes: 1 addition & 4 deletions main/src/Main.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
public class Main {

public static void main(String[] args) {
System.out.println("Hello world!");
}
}
}
1 change: 0 additions & 1 deletion main/src/main.java.com.mycompany.app/common/README.md

This file was deleted.

11 changes: 0 additions & 11 deletions main/src/main.java.com.mycompany.app/common/types/Type.java

This file was deleted.

This file was deleted.

6 changes: 0 additions & 6 deletions main/src/main.java.com.mycompany.app/parser/README.md

This file was deleted.

13 changes: 0 additions & 13 deletions main/src/main.java.com.mycompany.app/planner/PlanNode.java

This file was deleted.

16 changes: 0 additions & 16 deletions main/src/main.java.com.mycompany.app/planner/ProjectNode.java

This file was deleted.

3 changes: 2 additions & 1 deletion parser/pom.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

Expand Down
10 changes: 6 additions & 4 deletions parser/src/README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
Parser layer does this:


- Tokenize the input SQL statement. `SELECT (c1, c3) FROM tbl` should be converted to `[select,(,c1,c3,),FROM,tbl`
- Turn tokenized input into an AST. Then on the AST, do some language-level optimizations: CSE, const folding (use visitor pattern)
- Turn AST into IR. Maybe this should be a different layer? Anyways, figure out the difference, if there is one, between IR and the nodes we perform logical optimizations on
- Tokenize the input SQL statement. `SELECT (c1, c3) FROM tbl` should be converted
to `[select,(,c1,c3,),FROM,tbl`
- Turn tokenized input into an AST. Then on the AST, do some language-level optimizations: CSE,
const folding (use visitor pattern)
- Turn AST into IR. Maybe this should be a different layer? Anyways, figure out the difference, if
there is one, between IR and the nodes we perform logical optimizations on
6 changes: 4 additions & 2 deletions parser/src/main/antlr4/org/mycompany/README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
- SqlBase is a copy of Presto's grammar file. It was not apparent to me how to initialize all the available grammars
- SqlGrammarCopy is a direct copy from https://medium.com/@sasidharc/build-sql-parser-using-antlr4-part1-2044916a8406
- SqlBase is a copy of Presto's grammar file. It was not apparent to me how to initialize all the
available grammars
- SqlGrammarCopy is a direct copy
from https://medium.com/@sasidharc/build-sql-parser-using-antlr4-part1-2044916a8406
- SqlGrammar is the above, but edited. Use this as a sandbox.
10 changes: 6 additions & 4 deletions parser/src/main/java.org.mycompany/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ public void exitConstants(ConstantsContext ctx) {
@Override
public void enterExpressionList(ExpressionListContext ctx) {
}

@Override
public void exitExpressionList(ExpressionListContext ctx) {

Expand Down Expand Up @@ -122,7 +123,7 @@ public void exitExpression(ExpressionContext ctx) {

@Override
public void enterIdentifier(IdentifierContext ctx) {
int size = ctx.IDENTIFIER().size();
int size = ctx.IDENTIFIER().size();
if (size == 2) {
// Qualified with table name
} else if (size == 1) {
Expand Down Expand Up @@ -183,6 +184,7 @@ public void exitEveryRule(ParserRuleContext parserRuleContext) {

}
}

public static void main(String[] args) throws IOException {

// This works in lexer/parser, but not lexer/parser{2} (presto grammar). Cookie for who
Expand All @@ -192,11 +194,11 @@ public static void main(String[] args) throws IOException {
// create a CharStream that reads from standard input
ANTLRInputStream input = new ANTLRInputStream(inputString);

// create a lexer that feeds off of input CharStream
// create a lexer that feeds off of input CharStream
SqlGrammarLexer lexer = new SqlGrammarLexer(input);

// create a buffer of tokens pulled from the lexer
CommonTokenStream tokens = new CommonTokenStream(lexer);
CommonTokenStream tokens = new CommonTokenStream(lexer);

// create a parser that feeds off the tokens buffer
SqlGrammarParser parser = new SqlGrammarParser(tokens);
Expand All @@ -208,7 +210,7 @@ public static void main(String[] args) throws IOException {
SqlGrammarListener listener = new MyListener();
walker.walk(listener, tree);

System.out.println(tree.toStringTree(parser)); // print LISP-style tree
System.out.println(tree.toStringTree(parser)); // print LISP-style tree

}
}
3 changes: 2 additions & 1 deletion planner/pom.xml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

Expand Down
7 changes: 4 additions & 3 deletions planner/src/Main.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
public class Main {
public static void main(String[] args) {
System.out.println("Hello world!");
}

public static void main(String[] args) {
System.out.println("Hello world!");
}
}
Loading