Skip to content
Open
Changes from 2 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
41 changes: 36 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ Graphviz is a commonly used open source graph visualization library that we can




## Local Build
***
**Pre-requisite:**
Expand All @@ -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.
Copy link
Member

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.




### Creating and Visualizing Graphs
NOTE: All the example code is written in java
```java
Expand All @@ -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);
}
}
```
Expand All @@ -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);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: let's revert this added spacing. it doesn't align with the above comment


// 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"/>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.




### Future Enhancements
***

TODO:
- Implement remaining AST nodes that are currently not handled by the visualization system
- Extend AST visualization to PartiQL plan
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: slightly incorrect. the AST visualization would be its own thing from the Plan visualization

Suggested change
- Extend AST visualization to PartiQL plan
- Visualization of the PartiQL plan

- Introduce additional customization options for node appearance, edge styles, and color schemes
- Provide configuration parameters to control visualization verbosity, allowing for more compact graph representations when desired
- Integrate the PartiQL logo into generated visualizations

## Contributing
***

Expand Down
Loading