Skip to content

partiql/partiql-graphviz-java

PartiQL Graphviz Java


A visualization tool for PartiQL Abstract Syntax Trees (ASTs) using Graphviz, making it easier to understand and debug complex PartiQL queries.

About


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.

Local Build


Pre-requisite:

To build this project locally you can clone the repository:

$ git clone https://github.com/partiql/partiql-graphviz-java.git

Usage


Creating and Visualizing Graphs

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);
    }
}

Working with AST Nodes Directly

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);

Contributing


See CONTRIBUTING.

License


See the LICENSE file.

About

Visualization tool for PartiQL queries

Resources

License

Code of conduct

Contributing

Security policy

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 3

  •  
  •  
  •  

Languages