Skip to content


EngineContext is the execution context of ksqlDB engine.

Creating Instance

EngineContext takes the following to be created:

EngineContext is created using create and createSandbox factories.


EngineContext is given a ProcessingLogContext when created.

The ProcessingLogContext is used when:


EngineContext creates a DdlCommandExec when created.

The DdlCommandExec is used to execute DDL commands.


EngineContext is given a QueryRegistry when created.

The QueryRegistry is used when:


QueryRegistry getQueryRegistry()

getQueryRegistry is used when:

Creating QueryEngine

QueryEngine createQueryEngine(
  ServiceContext serviceContext)

createQueryEngine creates a QueryEngine (with the given ServiceContext and the ProcessingLogContext).

createQueryEngine is simply a convenient factory method that does nothing but new QueryEngine and that little programming trick makes for a more readable fluent client code.


createQueryEngine is used when:


EngineContext creates a CommandFactories when created.

The CommandFactories is used to create a DdlCommand.

Parsing SQL Statements

List<ParsedStatement> parse(
  String sql)

parse requests the KsqlParser to parse the given SQL statements.

parse is used when:

Preparing Statement for Execution

PreparedStatement<?> prepare(
  ParsedStatement stmt,
  Map<String, String> variablesMap)

prepare substitutes variables (in the given ParsedStatement with the variablesMap) and then requests the KsqlParser to prepare the ParsedStatement (with the variables resolved).

prepare sanitizes the statement based on the following configuration properties (in the KsqlConfig):

In the end, prepare creates a new PreparedStatement (with an unmasked KSQL statement in text format and the sanitized Statement).

prepare is used when (the available KsqlExecutionContexts are requested to prepare a KSQL statement for execution):

Variable Substitution

ParsedStatement substituteVariables(
  ParsedStatement stmt,
  Map<String, String> variablesMap)

substituteVariables substitutes variables (in the given ParsedStatement with the variablesMap) and then parses the SQL text.

Creating EngineContext

EngineContext create(
  ServiceContext serviceContext,
  ProcessingLogContext processingLogContext,
  MutableMetaStore metaStore,
  QueryIdGenerator queryIdGenerator,
  QueryCleanupService cleanupService,
  KsqlConfig ksqlConfig,
  Collection<QueryEventListener> registrationListeners)

create creates an EngineContext (with a new DefaultKsqlParser, a new QueryRegistryImpl and the others).

create is used when:

Creating Sandboxed EngineContext

EngineContext createSandbox(
  ServiceContext serviceContext)

createSandbox creates an EngineContext (with a SandboxedServiceContext, a new DefaultKsqlParser, and the others sandboxed).

createSandbox is used when:

  • SandboxedExecutionContext is created

Creating DdlCommand

DdlCommand createDdlCommand(
  KsqlStructuredDataOutputNode outputNode)
DdlCommand createDdlCommand(
  String sqlExpression,
  ExecutableDdlStatement statement,
  SessionConfig config)

createDdlCommand requests the CommandFactories to create a DdlCommand.

createDdlCommand is used when:

Executing DDL Command

String executeDdl(
  String sqlExpression,
  DdlCommand command,
  boolean withQuery,
  Set<SourceName> withQuerySources,
  boolean restoreInProgress)

executeDdl requests the DdlCommandExec to execute the DDL command.


executeDdl cares about DropSourceCommand more.

executeDdl is used when: