Skip to content

AstBuilder.Visitor

Visitor is a SqlBaseBaseVisitor to build a Node tree (that AstBuilder uses to build a parsed tree).

ANTLR

SqlBaseBaseVisitor is generated from SqlBase.g4 SQL grammar by ANTLR at build time.

Creating Instance

Visitor takes the following to be created:

Visitor is created when:

Parsing Statements

ALTER SOURCE

Node visitAlterSource(
  AlterSourceContext ctx)

visitAlterSource is part of the SqlBaseBaseVisitor abstraction to handle ALTER SYSTEM statements.

ALTER (STREAM | TABLE) sourceName alterOption (',' alterOption)*

alterOption
    : ADD (COLUMN)? identifier type
    ;

visitAlterSource creates an AlterSource.

ALTER SYSTEM

Node visitAlterSystemProperty(
  SqlBaseParser.AlterSystemPropertyContext context)

visitAlterSystemProperty is part of the SqlBaseBaseVisitor abstraction to handle ALTER SYSTEM statements.

ALTER SYSTEM name = value   #alterSystemProperty

visitAlterSystemProperty creates an AlterSystemProperty.

Not supported

Not supported with ksql.runtime.feature.shared.enabled turned off (createForAlterSystemQuery).

ASSERT TABLE

Node visitAssertTable(
  AssertTableContext context)

visitAssertTable is part of the SqlBaseBaseVisitor abstraction to handle ASSERT TABLE statements:

ASSERT TABLE sourceName
(tableElements)?
(WITH tableProperties)?

visitAssertTable creates an AssertTable with a CreateTable.

CREATE STREAM

Node visitCreateStream(
  SqlBaseParser.CreateStreamContext context)

visitCreateStream is part of the SqlBaseBaseVisitor abstraction to handle CREATE STREAM statements.

CREATE (OR REPLACE)? (SOURCE)? STREAM (IF NOT EXISTS)? sourceName
(tableElements)?
(WITH tableProperties)?

tableElements
    : '(' tableElement (',' tableElement)* ')'
    ;

tableElement
    : identifier type columnConstraints?
    ;

type
    : type ARRAY
    | ARRAY '<' type '>'
    | MAP '<' type ',' type '>'
    | STRUCT '<' (identifier type (',' identifier type)*)? '>'
    | DECIMAL '(' number ',' number ')'
    | baseType ('(' typeParameter (',' typeParameter)* ')')?
    ;

columnConstraints
    : ((PRIMARY)? KEY)
    | HEADERS
    | HEADER '(' text ')'
    ;

tableProperties
    : '(' tableProperty (',' tableProperty)* ')'
    ;

visitCreateStream creates a CreateStream.

CREATE STREAM AS SELECT

Node visitCreateStreamAs(
  SqlBaseParser.CreateStreamAsContext context)

visitCreateStreamAs is part of the SqlBaseBaseVisitor abstraction to handle CREATE STREAM AS (CSAS) statements.

CREATE (OR REPLACE)? STREAM (IF NOT EXISTS)? sourceName
  (WITH tableProperties)?
  AS query

visitCreateStreamAs creates a CreateStreamAsSelect.

CREATE TABLE

Node visitCreateTable(
  SqlBaseParser.CreateTableContext context)

visitCreateTable is part of the SqlBaseBaseVisitor abstraction to handle CREATE TABLE statements.

CREATE (OR REPLACE)? (SOURCE)? TABLE (IF NOT EXISTS)? sourceName
(tableElements)?
(WITH tableProperties)?

tableElements
    : '(' tableElement (',' tableElement)* ')'
    ;

tableElement
    : identifier type columnConstraints?
    ;

columnConstraints
    : ((PRIMARY)? KEY)
    | HEADERS
    | HEADER '(' STRING ')'
    ;

visitCreateTable creates a CreateTable.

CREATE TABLE AS SELECT

Node visitCreateTableAs(
  SqlBaseParser.CreateTableAsContext context)

visitCreateTableAs is part of the SqlBaseBaseVisitor abstraction to handle CREATE TABLE AS SELECT (CTAS) statements.

CREATE (OR REPLACE)? TABLE (IF NOT EXISTS)? sourceName
  (WITH tableProperties)?
  AS query

visitCreateTableAs creates a CreateTableAsSelect.

DESCRIBE SOURCE

visitShowColumns handles DESCRIBE [source] statements.

DESCRIBE sourceName EXTENDED?

visitShowColumns creates the following:

EXPLAIN

Node visitExplain(
  SqlBaseParser.ExplainContext ctx)

visitExplain is part of the SqlBaseBaseVisitor abstraction to handle EXPLAIN statements.

EXPLAIN (statement | identifier)

visitExplain creates an Explain.

INSERT INTO

visitInsertInto handles INSERT INTO statements.

INSERT INTO sourceName
  (WITH tableProperties)?
  query

visitInsertInto creates an InsertInto.

LIST STREAMS

Node visitListStreams(
  SqlBaseParser.ListStreamsContext context)

visitListStreams is part of the SqlBaseBaseVisitor abstraction to handle LIST STREAMS statements.

(LIST | SHOW) STREAMS EXTENDED?

visitListStreams creates a ListStreams.

SELECT

Query visitQuery(
  SqlBaseParser.QueryContext context)

visitQuery is part of the SqlBaseBaseVisitor abstraction to handle SELECT statements (queries).

query
    : SELECT selectItem (',' selectItem)*
      FROM from=relation
      (WINDOW  windowExpression)?
      (WHERE where=booleanExpression)?
      (GROUP BY groupBy)?
      (PARTITION BY partitionBy)?
      (HAVING having=booleanExpression)?
      (EMIT resultMaterialization)?
      limitClause?
    ;

visitQuery creates a Query.

buildingPersistentQuery Flag

Visitor defines buildingPersistentQuery internal flag that is false when created.

buildingPersistentQuery flag is turned on (true) when withinPersistentQuery.

withinPersistentQuery

T withinPersistentQuery(
  Supplier<T> task)

withinPersistentQuery...FIXME

withinPersistentQuery is used when: