-
Notifications
You must be signed in to change notification settings - Fork 0
Added more description and included example graph and query and updat… #23
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from 2 commits
3e0189f
ea8623c
923f53c
49f1d81
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -12,6 +12,7 @@ Graphviz is a commonly used open source graph visualization library that we can | |||||
|
||||||
|
||||||
|
||||||
|
||||||
## Local Build | ||||||
*** | ||||||
**Pre-requisite:** | ||||||
|
@@ -25,6 +26,15 @@ $ git clone https://github.com/partiql/partiql-graphviz-java.git | |||||
|
||||||
## Usage | ||||||
*** | ||||||
The PartiQL Graphviz visualization tool allows you to easily convert PartiQL queries into visual graph representations. | ||||||
To use this functionality, first create an instance of the AstToGraph class. You can then convert a PartiQL query string directly to a graph using convertQueryToGraph(String query), | ||||||
or if you already have a parsed AST statement, use convertAstToGraph(Statement statement). Once you have the graph, you can export it in various formats: save it as a DOT file with convertGraphToDot(graph, filePath), | ||||||
render it as a PNG image using convertDotToPng(graph, filePath, scale), or create an SVG with convertDotToSvg(graph, filePath, scale). The scale parameter allows you to adjust the size of the output image. | ||||||
This visualization capability is particularly useful for understanding complex query structures, debugging query issues, or educational purposes to demonstrate how PartiQL parses different query constructs. | ||||||
The generated visual representation clearly shows the hierarchical structure of the query, including SELECT clauses, FROM sources, WHERE conditions, and other query components with their relationships. | ||||||
|
||||||
|
||||||
|
||||||
### Creating and Visualizing Graphs | ||||||
NOTE: All the example code is written in java | ||||||
```java | ||||||
|
@@ -41,10 +51,12 @@ public class Query { | |||||
// Define output file paths | ||||||
String dotFilePath = "ast_graph.dot"; | ||||||
String pngFilePath = "ast_graph.png"; | ||||||
String svgFilePath = "ast_graph.svg"; | ||||||
|
||||||
// Save the graph in DOT and PNG formats | ||||||
// Save the graph in DOT, PNG and SVG formats | ||||||
astToGraph.convertGraphToDot(graph, dotFilePath); | ||||||
astToGraph.convertDotToPng(graph, pngFilePath); | ||||||
astToGraph.convertDotToPng(graph, pngFilePath, 2.0); | ||||||
astToGraph.convertDotToSvg(graph, svgFilePath, 2.0); | ||||||
} | ||||||
} | ||||||
``` | ||||||
|
@@ -56,17 +68,36 @@ import org.partiql.parser.PartiQLParser; | |||||
import org.partiql.ast.Statement; | ||||||
|
||||||
// Parse a query to get the AST | ||||||
PartiQLParser parser = PartiQLParser.standard(); | ||||||
PartiQLParser.Result parseResult = parser.parse(query); | ||||||
Statement statement = parseResult.statements.get(0); | ||||||
PartiQLParser parser = PartiQLParser.standard(); | ||||||
PartiQLParser.Result parseResult = parser.parse(query); | ||||||
Statement statement = parseResult.statements.get(0); | ||||||
|
||||||
|
||||||
// Convert the AST to a graph | ||||||
Graph graph = astToGraph.convertAstToGraph(statement); | ||||||
``` | ||||||
|
||||||
### Example Query | ||||||
|
||||||
``` | ||||||
Query: SELECT a,b,c FROM t WHERE d | ||||||
``` | ||||||
|
||||||
### Example Graph | ||||||
|
||||||
<img alt="img_1.png = 70x70" height="400" src="img_1.png" width="500"/> | ||||||
|
||||||
|
||||||
|
||||||
|
||||||
### Future Enhancements | ||||||
*** | ||||||
|
||||||
TODO: | ||||||
- Implement remaining AST nodes that are currently not handled by the visualization system | ||||||
- Extend AST visualization to PartiQL plan | ||||||
|
- Extend AST visualization to PartiQL plan | |
- Visualization of the PartiQL plan |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is all helpful info. Thanks for adding it! Looking at the rendered README file, it all shows up as one paragraph. Can you add some line breaks between the different sections? Also for code references, let's wrap the code in backticks -- https://docs.github.com/en/get-started/writing-on-github/getting-started-with-writing-and-formatting-on-github/basic-writing-and-formatting-syntax#quoting-code.