A visualization tool for PartiQL Abstract Syntax Trees (ASTs) using Graphviz, making it easier to understand and debug complex PartiQL queries.
The PartiQL parser generates an abstract syntax tree (AST) from PartiQL query text. The AST is then converted to DOT language format and Graphviz renders the DOT representation as visual graphs. Graphviz is a commonly used open source graph visualization library that we can use to provide visual representations of these query structures.
Pre-requisite:
- Building this project requires Java 11+.
- Installing graphviz -- follow installation steps here: https://graphviz.org/download/.
To build this project locally you can clone the repository:
$ git clone https://github.com/partiql/partiql-graphviz-java.git
NOTE: All the example code is written in java
import org.partiql.graphviz.AstToGraph;
import guru.nidi.graphviz.model.Graph;
import java.io.IOException;
public class Query {
public static void main(String[] args) throws IOException {
AstToGraph astToGraph = new AstToGraph();
// Convert a simple arithmetic expression to a graph
Graph graph = astToGraph.convertQueryToGraph("12345 * 34567");
// Define output file paths
String dotFilePath = "ast_graph.dot";
String pngFilePath = "ast_graph.png";
// Save the graph in DOT and PNG formats
astToGraph.convertGraphToDot(graph, dotFilePath);
astToGraph.convertDotToPng(graph, pngFilePath);
}
}
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);
// Convert the AST to a graph
Graph graph = astToGraph.convertAstToGraph(statement);
See CONTRIBUTING.
See the LICENSE file.