Skip to content


AstBuilder uses AstBuilder.Visitor to parse SQL statements (using ANTLR).

Creating Instance

AstBuilder takes the following to be created:

AstBuilder is created when:

  • QueryAnonymizer.Visitor is requested to visitExpression
  • DefaultKsqlParser is requested to prepare a statement for execution
  • ExpressionParser is requested to parseSelectExpression, parseExpression, parseWindowExpression

Building Statement

Statement buildStatement(
  ParserRuleContext parseTree)

buildStatement collects the source names (in the SQL statement as a parsed tree) first and then builds a Statement.

buildStatement is used when:

Collecting Source Names

Set<SourceName> getSources(
  ParseTree parseTree)

getSources creates a SourceAccumulator to visit (the nodes of) the given ParseTree. In the end, getSources requests the SourceAccumulator for the sources.

Building Node

<T extends Node> T build(
  Optional<Set<SourceName>> sources, // (1)!
  ParserRuleContext parseTree)
  1. sources are only given for building a Statement

build creates an AstBuilder.Visitor to build one of the following Nodes (for a given ParserRuleContext that is a parsed SQL statement):