From c788bc1d408aef1cfd7965c662f6fc5629ac11d4 Mon Sep 17 00:00:00 2001 From: Patrick Date: Sat, 30 Mar 2024 18:05:05 -0700 Subject: [PATCH 1/3] change pom to java11 and add visitor + examples --- common/src/Main.java | 6 ---- common/src/logical_node/Node.java | 13 ++++++++ common/src/logical_node/Visitor.java | 13 ++++++++ .../src/logical_node/examples/AnimalNode.java | 13 ++++++++ .../logical_node/examples/AnimalVisitor.java | 15 ++++++++++ common/src/logical_node/examples/CatNode.java | 25 ++++++++++++++++ common/src/logical_node/examples/DogNode.java | 27 +++++++++++++++++ common/src/logical_node/examples/Main.java | 26 ++++++++++++++++ .../examples/PrettyPrintVisitor.java | 30 +++++++++++++++++++ common/src/logical_node/examples/README.md | 4 +++ common/src/types/Type.java | 1 - main/src/Main.java | 6 ---- .../common/README.md | 1 - .../common/types/Type.java | 11 ------- .../execution/ExecutionNode.java | 7 ----- .../parser/README.md | 6 ---- .../planner/PlanNode.java | 13 -------- .../planner/ProjectNode.java | 16 ---------- pom.xml | 5 ++++ 19 files changed, 171 insertions(+), 67 deletions(-) delete mode 100644 common/src/Main.java create mode 100644 common/src/logical_node/Node.java create mode 100644 common/src/logical_node/Visitor.java create mode 100644 common/src/logical_node/examples/AnimalNode.java create mode 100644 common/src/logical_node/examples/AnimalVisitor.java create mode 100644 common/src/logical_node/examples/CatNode.java create mode 100644 common/src/logical_node/examples/DogNode.java create mode 100644 common/src/logical_node/examples/Main.java create mode 100644 common/src/logical_node/examples/PrettyPrintVisitor.java create mode 100644 common/src/logical_node/examples/README.md delete mode 100644 main/src/Main.java delete mode 100644 main/src/main.java.com.mycompany.app/common/README.md delete mode 100644 main/src/main.java.com.mycompany.app/common/types/Type.java delete mode 100644 main/src/main.java.com.mycompany.app/execution/ExecutionNode.java delete mode 100644 main/src/main.java.com.mycompany.app/parser/README.md delete mode 100644 main/src/main.java.com.mycompany.app/planner/PlanNode.java delete mode 100644 main/src/main.java.com.mycompany.app/planner/ProjectNode.java diff --git a/common/src/Main.java b/common/src/Main.java deleted file mode 100644 index 69420ef..0000000 --- a/common/src/Main.java +++ /dev/null @@ -1,6 +0,0 @@ -public class Main { - - public static void main(String[] args) { - System.out.println("Hello world!"); - } -} \ No newline at end of file diff --git a/common/src/logical_node/Node.java b/common/src/logical_node/Node.java new file mode 100644 index 0000000..ad22194 --- /dev/null +++ b/common/src/logical_node/Node.java @@ -0,0 +1,13 @@ +package logical_node; + +import java.util.List; + +public abstract class Node { + + public R accept(Visitor visitor, C context) + { + return visitor.visitPlan(this, context); + } + + List children; +} diff --git a/common/src/logical_node/Visitor.java b/common/src/logical_node/Visitor.java new file mode 100644 index 0000000..a583a4f --- /dev/null +++ b/common/src/logical_node/Visitor.java @@ -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 { + + 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); +// } + +} \ No newline at end of file diff --git a/common/src/logical_node/examples/AnimalNode.java b/common/src/logical_node/examples/AnimalNode.java new file mode 100644 index 0000000..8c0909e --- /dev/null +++ b/common/src/logical_node/examples/AnimalNode.java @@ -0,0 +1,13 @@ +package logical_node.examples; + +import java.util.List; + +public abstract class AnimalNode { + + public R accept(AnimalVisitor visitor, C context) + { + return visitor.visitPlan(this, context); + } + + List children; +} diff --git a/common/src/logical_node/examples/AnimalVisitor.java b/common/src/logical_node/examples/AnimalVisitor.java new file mode 100644 index 0000000..0e4e29f --- /dev/null +++ b/common/src/logical_node/examples/AnimalVisitor.java @@ -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 { + + 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); + } +} \ No newline at end of file diff --git a/common/src/logical_node/examples/CatNode.java b/common/src/logical_node/examples/CatNode.java new file mode 100644 index 0000000..0ecd0ef --- /dev/null +++ b/common/src/logical_node/examples/CatNode.java @@ -0,0 +1,25 @@ +package logical_node.examples; + +import logical_node.Node; +import logical_node.Visitor; + +public class CatNode extends AnimalNode { + @Override + public R accept(AnimalVisitor 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; +} diff --git a/common/src/logical_node/examples/DogNode.java b/common/src/logical_node/examples/DogNode.java new file mode 100644 index 0000000..2878dff --- /dev/null +++ b/common/src/logical_node/examples/DogNode.java @@ -0,0 +1,27 @@ +package logical_node.examples; + +import logical_node.Node; +import logical_node.Visitor; + +import java.util.List; + +public class DogNode extends AnimalNode { + @Override + public R accept(AnimalVisitor visitor, C context) { + return visitor.visitDogNode(this, context); + } + + public DogNode(String id, List children) { + this.children = children; + this.id = id; + } + + @Override + public String toString() { + return "logical_node.examples.DogNode{" + + "id='" + id + '\'' + + '}'; + } + + String id; +} diff --git a/common/src/logical_node/examples/Main.java b/common/src/logical_node/examples/Main.java new file mode 100644 index 0000000..aec0519 --- /dev/null +++ b/common/src/logical_node/examples/Main.java @@ -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, ""); + } +} \ No newline at end of file diff --git a/common/src/logical_node/examples/PrettyPrintVisitor.java b/common/src/logical_node/examples/PrettyPrintVisitor.java new file mode 100644 index 0000000..2142de3 --- /dev/null +++ b/common/src/logical_node/examples/PrettyPrintVisitor.java @@ -0,0 +1,30 @@ +package logical_node.examples; + +import logical_node.Node; +import logical_node.Visitor; + +public class PrettyPrintVisitor extends AnimalVisitor { + + @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; + } +} diff --git a/common/src/logical_node/examples/README.md b/common/src/logical_node/examples/README.md new file mode 100644 index 0000000..508bf96 --- /dev/null +++ b/common/src/logical_node/examples/README.md @@ -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 \ No newline at end of file diff --git a/common/src/types/Type.java b/common/src/types/Type.java index 49bd798..dbc8f75 100644 --- a/common/src/types/Type.java +++ b/common/src/types/Type.java @@ -8,4 +8,3 @@ public enum Type { VARCHAR, BOOL } - diff --git a/main/src/Main.java b/main/src/Main.java deleted file mode 100644 index 69420ef..0000000 --- a/main/src/Main.java +++ /dev/null @@ -1,6 +0,0 @@ -public class Main { - - public static void main(String[] args) { - System.out.println("Hello world!"); - } -} \ No newline at end of file diff --git a/main/src/main.java.com.mycompany.app/common/README.md b/main/src/main.java.com.mycompany.app/common/README.md deleted file mode 100644 index ee742e9..0000000 --- a/main/src/main.java.com.mycompany.app/common/README.md +++ /dev/null @@ -1 +0,0 @@ -Common resources for other packages. To prevent circular dependencies, avoid adding dependencies on other packages to common. \ No newline at end of file diff --git a/main/src/main.java.com.mycompany.app/common/types/Type.java b/main/src/main.java.com.mycompany.app/common/types/Type.java deleted file mode 100644 index b1a0034..0000000 --- a/main/src/main.java.com.mycompany.app/common/types/Type.java +++ /dev/null @@ -1,11 +0,0 @@ -package main.java.com.mycompany.app.common.types; - -/** - * Types must map - */ -public enum Type { - INT, - VARCHAR, - BOOL -} - diff --git a/main/src/main.java.com.mycompany.app/execution/ExecutionNode.java b/main/src/main.java.com.mycompany.app/execution/ExecutionNode.java deleted file mode 100644 index aab64cf..0000000 --- a/main/src/main.java.com.mycompany.app/execution/ExecutionNode.java +++ /dev/null @@ -1,7 +0,0 @@ -package main.java.com.mycompany.app.execution; - -import com.mycompany.app.common.types.Type; - -public interface ExecutionNode { - -} diff --git a/main/src/main.java.com.mycompany.app/parser/README.md b/main/src/main.java.com.mycompany.app/parser/README.md deleted file mode 100644 index 35356d4..0000000 --- a/main/src/main.java.com.mycompany.app/parser/README.md +++ /dev/null @@ -1,6 +0,0 @@ -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 \ No newline at end of file diff --git a/main/src/main.java.com.mycompany.app/planner/PlanNode.java b/main/src/main.java.com.mycompany.app/planner/PlanNode.java deleted file mode 100644 index 195aa1a..0000000 --- a/main/src/main.java.com.mycompany.app/planner/PlanNode.java +++ /dev/null @@ -1,13 +0,0 @@ -package main.java.com.mycompany.app.planner; - -import com.mycompany.app.common.types.Type; - -/** - * A PlanNode represents a node in the plan tree which will eventually be translated into an execution node - * in the execution tree. Data cannot actually flow through a plan tree (i.e. there is no next() method on the nodes), - * instead each PlanNode has a translateToExecutionNode method which will use information from the PlanNode to build - * a corresponding execution node - */ -public interface PlanNode { - -} diff --git a/main/src/main.java.com.mycompany.app/planner/ProjectNode.java b/main/src/main.java.com.mycompany.app/planner/ProjectNode.java deleted file mode 100644 index 360a425..0000000 --- a/main/src/main.java.com.mycompany.app/planner/ProjectNode.java +++ /dev/null @@ -1,16 +0,0 @@ -package main.java.com.mycompany.app.planner; - -import com.mycompany.app.common.types.Type; - -import java.util.List; - -/** - * Think about how this works E2E: - * How do we - */ -public class ProjectNode implements PlanNode{ - List getSources() { - - } -} - diff --git a/pom.xml b/pom.xml index 037c836..4dc95c2 100644 --- a/pom.xml +++ b/pom.xml @@ -6,6 +6,11 @@ 1 pom + + 11 + 11 + + parser planner From b6187e5ff17cc5fa82ce3b341abd2c179c85ceb8 Mon Sep 17 00:00:00 2001 From: Patrick Date: Sat, 30 Mar 2024 21:23:06 -0700 Subject: [PATCH 2/3] refactor with google style --- common/pom.xml | 3 +- common/src/README.md | 3 +- common/src/logical_node/Node.java | 9 ++-- common/src/logical_node/Visitor.java | 4 +- .../src/logical_node/examples/AnimalNode.java | 9 ++-- .../logical_node/examples/AnimalVisitor.java | 14 +++---- common/src/logical_node/examples/CatNode.java | 34 ++++++++------- common/src/logical_node/examples/DogNode.java | 34 ++++++++------- .../examples/PrettyPrintVisitor.java | 41 +++++++++---------- common/src/types/Type.java | 6 +-- execution/pom.xml | 3 +- main/pom.xml | 3 +- main/src/Main.java | 3 ++ parser/pom.xml | 3 +- parser/src/README.md | 10 +++-- .../src/main/antlr4/org/mycompany/README.md | 6 ++- parser/src/main/java.org.mycompany/Main.java | 10 +++-- planner/pom.xml | 3 +- planner/src/Main.java | 7 ++-- planner/src/PlanNode.java | 8 ++-- planner/src/ProjectNode.java | 11 ++--- 21 files changed, 116 insertions(+), 108 deletions(-) create mode 100644 main/src/Main.java diff --git a/common/pom.xml b/common/pom.xml index f132bc5..825228a 100644 --- a/common/pom.xml +++ b/common/pom.xml @@ -1,4 +1,5 @@ - 4.0.0 diff --git a/common/src/README.md b/common/src/README.md index ee742e9..8751b18 100644 --- a/common/src/README.md +++ b/common/src/README.md @@ -1 +1,2 @@ -Common resources for other packages. To prevent circular dependencies, avoid adding dependencies on other packages to common. \ No newline at end of file +Common resources for other packages. To prevent circular dependencies, avoid adding dependencies on +other packages to common. \ No newline at end of file diff --git a/common/src/logical_node/Node.java b/common/src/logical_node/Node.java index ad22194..74b415c 100644 --- a/common/src/logical_node/Node.java +++ b/common/src/logical_node/Node.java @@ -4,10 +4,9 @@ public abstract class Node { - public R accept(Visitor visitor, C context) - { - return visitor.visitPlan(this, context); - } + public R accept(Visitor visitor, C context) { + return visitor.visitPlan(this, context); + } - List children; + List children; } diff --git a/common/src/logical_node/Visitor.java b/common/src/logical_node/Visitor.java index a583a4f..e70a2c7 100644 --- a/common/src/logical_node/Visitor.java +++ b/common/src/logical_node/Visitor.java @@ -3,9 +3,9 @@ // Visitor interface needs to be aware of all implementations of Node to have visit{x}Node methods declared for each. public abstract class Visitor { - abstract R visitPlan(Node node, C context); + abstract R visitPlan(Node node, C context); - // Example visit node function. See examples directory for complete example of implemented visitor pattern. + // Example visit node function. See examples directory for complete example of implemented visitor pattern. // R visitDogNode(DogNode node, C context) { // return visitPlan(node, context); // } diff --git a/common/src/logical_node/examples/AnimalNode.java b/common/src/logical_node/examples/AnimalNode.java index 8c0909e..d70f1d7 100644 --- a/common/src/logical_node/examples/AnimalNode.java +++ b/common/src/logical_node/examples/AnimalNode.java @@ -4,10 +4,9 @@ public abstract class AnimalNode { - public R accept(AnimalVisitor visitor, C context) - { - return visitor.visitPlan(this, context); - } + public R accept(AnimalVisitor visitor, C context) { + return visitor.visitPlan(this, context); + } - List children; + List children; } diff --git a/common/src/logical_node/examples/AnimalVisitor.java b/common/src/logical_node/examples/AnimalVisitor.java index 0e4e29f..8dae67b 100644 --- a/common/src/logical_node/examples/AnimalVisitor.java +++ b/common/src/logical_node/examples/AnimalVisitor.java @@ -3,13 +3,13 @@ // Visitor interface needs to be aware of all implementations of Node to have visit{x}Node methods declared for each. public abstract class AnimalVisitor { - abstract R visitPlan(AnimalNode node, C context); + abstract R visitPlan(AnimalNode node, C context); - R visitDogNode(DogNode node, C context) { - return visitPlan(node, context); - } + R visitDogNode(DogNode node, C context) { + return visitPlan(node, context); + } - R visitCatNode(CatNode node, C context) { - return visitPlan(node, context); - } + R visitCatNode(CatNode node, C context) { + return visitPlan(node, context); + } } \ No newline at end of file diff --git a/common/src/logical_node/examples/CatNode.java b/common/src/logical_node/examples/CatNode.java index 0ecd0ef..6606b98 100644 --- a/common/src/logical_node/examples/CatNode.java +++ b/common/src/logical_node/examples/CatNode.java @@ -1,25 +1,23 @@ package logical_node.examples; -import logical_node.Node; -import logical_node.Visitor; - public class CatNode extends AnimalNode { - @Override - public R accept(AnimalVisitor visitor, C context) { - return visitor.visitCatNode(this, context); - } - public CatNode(String id) { - this.children = null; - this.id = id; - } + @Override + public R accept(AnimalVisitor 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 + '\'' + - '}'; - } + @Override + public String toString() { + return "logical_node.examples.CatNode{" + + "id='" + id + '\'' + + '}'; + } - String id; + String id; } diff --git a/common/src/logical_node/examples/DogNode.java b/common/src/logical_node/examples/DogNode.java index 2878dff..5d86033 100644 --- a/common/src/logical_node/examples/DogNode.java +++ b/common/src/logical_node/examples/DogNode.java @@ -1,27 +1,25 @@ package logical_node.examples; -import logical_node.Node; -import logical_node.Visitor; - import java.util.List; public class DogNode extends AnimalNode { - @Override - public R accept(AnimalVisitor visitor, C context) { - return visitor.visitDogNode(this, context); - } - public DogNode(String id, List children) { - this.children = children; - this.id = id; - } + @Override + public R accept(AnimalVisitor visitor, C context) { + return visitor.visitDogNode(this, context); + } + + public DogNode(String id, List children) { + this.children = children; + this.id = id; + } - @Override - public String toString() { - return "logical_node.examples.DogNode{" + - "id='" + id + '\'' + - '}'; - } + @Override + public String toString() { + return "logical_node.examples.DogNode{" + + "id='" + id + '\'' + + '}'; + } - String id; + String id; } diff --git a/common/src/logical_node/examples/PrettyPrintVisitor.java b/common/src/logical_node/examples/PrettyPrintVisitor.java index 2142de3..f3ddd9d 100644 --- a/common/src/logical_node/examples/PrettyPrintVisitor.java +++ b/common/src/logical_node/examples/PrettyPrintVisitor.java @@ -1,30 +1,27 @@ package logical_node.examples; -import logical_node.Node; -import logical_node.Visitor; - public class PrettyPrintVisitor extends AnimalVisitor { - @Override - Void visitPlan(AnimalNode node, String context) { - node.accept(this, context); - return null; - } + @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 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; - } + @Override + Void visitCatNode(CatNode node, String context) { + System.out.println(context + node.toString()); + return null; + } } diff --git a/common/src/types/Type.java b/common/src/types/Type.java index dbc8f75..1ac8a57 100644 --- a/common/src/types/Type.java +++ b/common/src/types/Type.java @@ -4,7 +4,7 @@ * Types must map */ public enum Type { - INT, - VARCHAR, - BOOL + INT, + VARCHAR, + BOOL } diff --git a/execution/pom.xml b/execution/pom.xml index 5695237..888e797 100644 --- a/execution/pom.xml +++ b/execution/pom.xml @@ -1,4 +1,5 @@ - 4.0.0 diff --git a/main/pom.xml b/main/pom.xml index b0a7bea..a4b44e4 100644 --- a/main/pom.xml +++ b/main/pom.xml @@ -1,4 +1,5 @@ - 4.0.0 diff --git a/main/src/Main.java b/main/src/Main.java new file mode 100644 index 0000000..9b4320d --- /dev/null +++ b/main/src/Main.java @@ -0,0 +1,3 @@ +public class Main { + +} diff --git a/parser/pom.xml b/parser/pom.xml index 7a28045..d2ce266 100644 --- a/parser/pom.xml +++ b/parser/pom.xml @@ -1,6 +1,7 @@ - 4.0.0 diff --git a/parser/src/README.md b/parser/src/README.md index 35356d4..5d433e6 100644 --- a/parser/src/README.md +++ b/parser/src/README.md @@ -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 \ No newline at end of file +- 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 \ No newline at end of file diff --git a/parser/src/main/antlr4/org/mycompany/README.md b/parser/src/main/antlr4/org/mycompany/README.md index 59dc018..82f3a70 100644 --- a/parser/src/main/antlr4/org/mycompany/README.md +++ b/parser/src/main/antlr4/org/mycompany/README.md @@ -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. \ No newline at end of file diff --git a/parser/src/main/java.org.mycompany/Main.java b/parser/src/main/java.org.mycompany/Main.java index d36c786..5bce10d 100644 --- a/parser/src/main/java.org.mycompany/Main.java +++ b/parser/src/main/java.org.mycompany/Main.java @@ -86,6 +86,7 @@ public void exitConstants(ConstantsContext ctx) { @Override public void enterExpressionList(ExpressionListContext ctx) { } + @Override public void exitExpressionList(ExpressionListContext ctx) { @@ -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) { @@ -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 @@ -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); @@ -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 } } \ No newline at end of file diff --git a/planner/pom.xml b/planner/pom.xml index 9cfe110..70c1746 100644 --- a/planner/pom.xml +++ b/planner/pom.xml @@ -1,4 +1,5 @@ - 4.0.0 diff --git a/planner/src/Main.java b/planner/src/Main.java index 3e59c38..69420ef 100644 --- a/planner/src/Main.java +++ b/planner/src/Main.java @@ -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!"); + } } \ No newline at end of file diff --git a/planner/src/PlanNode.java b/planner/src/PlanNode.java index 383233b..567486b 100644 --- a/planner/src/PlanNode.java +++ b/planner/src/PlanNode.java @@ -1,10 +1,10 @@ import com.mycompany.app.common.types.Type; /** - * A PlanNode represents a node in the plan tree which will eventually be translated into an execution node - * in the execution tree. Data cannot actually flow through a plan tree (i.e. there is no next() method on the nodes), - * instead each PlanNode has a translateToExecutionNode method which will use information from the PlanNode to build - * a corresponding execution node + * A PlanNode represents a node in the plan tree which will eventually be translated into an + * execution node in the execution tree. Data cannot actually flow through a plan tree (i.e. there + * is no next() method on the nodes), instead each PlanNode has a translateToExecutionNode method + * which will use information from the PlanNode to build a corresponding execution node */ public interface PlanNode { diff --git a/planner/src/ProjectNode.java b/planner/src/ProjectNode.java index 7be179c..cabe611 100644 --- a/planner/src/ProjectNode.java +++ b/planner/src/ProjectNode.java @@ -3,12 +3,13 @@ import java.util.List; /** - * Think about how this works E2E: - * How do we + * Think about how this works E2E: How do we */ -public class ProjectNode implements PlanNode{ - List getSources() { +public class ProjectNode implements + PlanNode { - } + List getSources() { + + } } From c3502a2923b8671aa45948fc62231069bca45747 Mon Sep 17 00:00:00 2001 From: Patrick Sullivan Date: Sun, 31 Mar 2024 00:34:50 -0700 Subject: [PATCH 3/3] add contributing.md --- CONTRIBUTING.md | 6 ++++++ 1 file changed, 6 insertions(+) create mode 100644 CONTRIBUTING.md diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md new file mode 100644 index 0000000..890f62f --- /dev/null +++ b/CONTRIBUTING.md @@ -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 \ No newline at end of file