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
45 changes: 43 additions & 2 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,25 @@ $ 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)`
- 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
Expand All @@ -41,10 +61,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 @@ -64,8 +86,27 @@ Statement statement = parseResult.statements.get(0);
Graph graph = astToGraph.convertAstToGraph(statement);
```

### Example Query

```
Query: SELECT a,b,c FROM t WHERE d
```

### Example Graph

<img alt="img.png" height="350" src="img.png" width="400"/>



### Future Enhancements
***

TODO:
- Implement remaining AST nodes that are currently not handled by the visualization system
- 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
Binary file added img.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading