DefaultKsqlParser¶
DefaultKsqlParser
is a KsqlParser.
Demo¶
import io.confluent.ksql.parser.DefaultKsqlParser
val parser = new DefaultKsqlParser()
val ksql = "SELECT * FROM my_stream;"
val statements = parser.parse(ksql)
import scala.jdk.CollectionConverters._
val pstmt = statements.asScala.head
assert(pstmt.isInstanceOf[io.confluent.ksql.parser.KsqlParser.ParsedStatement])
Creating Instance¶
DefaultKsqlParser
takes no arguments to be created.
DefaultKsqlParser
is created when:
Cli
is createdEngineContext
utility is used to create an EngineContext and createSandboxKsqlResource
is requested for TERMINATE_CLUSTER
Parsing SQL Statements (parse)¶
List<ParsedStatement> parse(
String sql)
parse
parses the given sql
(using ANTLR) and creates as many ParsedStatement
s as there are SQL statements in the sql
.
ANTLR
This is when a SQL text is parsed (transformed) using ANTLR into a collection of ksqlDB's ParsedStatement
s according to the SqlBase.g4
grammar:
statements
: (singleStatement)* EOF
;
Every ParsedStatement
s maps exactly to a singleStatement
.
parse
is part of the KsqlParser abstraction.
Preparing Statement for Execution¶
PreparedStatement<?> prepare(
ParsedStatement stmt,
TypeRegistry typeRegistry)
prepare
is part of the KsqlParser abstraction.
prepare
creates an AstBuilder (with the given TypeRegistry) to build a Statement.
In the end, prepare
creates a PreparedStatement
(with the KSQL statement in text format and the Statement).