Search in sources :

Example 1 with DefaultSchemaInjector

use of io.confluent.ksql.schema.ksql.inference.DefaultSchemaInjector in project ksql by confluentinc.

the class KsqlEngineTestUtil method execute.

@SuppressWarnings({ "rawtypes", "unchecked" })
private static ExecuteResult execute(final ServiceContext serviceContext, final KsqlExecutionContext executionContext, final ParsedStatement stmt, final KsqlConfig ksqlConfig, final Map<String, Object> overriddenProperties, final Optional<DefaultSchemaInjector> schemaInjector) {
    final PreparedStatement<?> prepared = executionContext.prepare(stmt);
    final ConfiguredStatement<?> configured = ConfiguredStatement.of(prepared, SessionConfig.of(ksqlConfig, overriddenProperties));
    final ConfiguredStatement<?> withFormats = new DefaultFormatInjector().inject(configured);
    final ConfiguredStatement<?> withSchema = schemaInjector.map(injector -> injector.inject(withFormats)).orElse((ConfiguredStatement) withFormats);
    final ConfiguredStatement<?> reformatted = new SqlFormatInjector(executionContext).inject(withSchema);
    try {
        return executionContext.execute(serviceContext, reformatted);
    } catch (final KsqlStatementException e) {
        // can easily check that the failed statement is the input statement
        throw new KsqlStatementException(e.getRawMessage(), stmt.getStatementText(), e.getCause());
    }
}
Also used : Query(io.confluent.ksql.parser.tree.Query) SequentialQueryIdGenerator(io.confluent.ksql.query.id.SequentialQueryIdGenerator) SchemaRegistryClient(io.confluent.kafka.schemaregistry.client.SchemaRegistryClient) ServiceContext(io.confluent.ksql.services.ServiceContext) SchemaRegistryTopicSchemaSupplier(io.confluent.ksql.schema.ksql.inference.SchemaRegistryTopicSchemaSupplier) ProcessingLogContext(io.confluent.ksql.logging.processing.ProcessingLogContext) MutableMetaStore(io.confluent.ksql.metastore.MutableMetaStore) MetricCollectors(io.confluent.ksql.metrics.MetricCollectors) Function(java.util.function.Function) SessionConfig(io.confluent.ksql.config.SessionConfig) TransientQueryMetadata(io.confluent.ksql.util.TransientQueryMetadata) ExecuteResult(io.confluent.ksql.KsqlExecutionContext.ExecuteResult) Map(java.util.Map) ParsedStatement(io.confluent.ksql.parser.KsqlParser.ParsedStatement) DefaultFormatInjector(io.confluent.ksql.format.DefaultFormatInjector) QueryIdGenerator(io.confluent.ksql.query.id.QueryIdGenerator) QueryMetadata(io.confluent.ksql.util.QueryMetadata) ConfiguredStatement(io.confluent.ksql.statement.ConfiguredStatement) KsqlConfig(io.confluent.ksql.util.KsqlConfig) DefaultSchemaInjector(io.confluent.ksql.schema.ksql.inference.DefaultSchemaInjector) Collectors(java.util.stream.Collectors) KsqlStatementException(io.confluent.ksql.util.KsqlStatementException) List(java.util.List) KsqlExecutionContext(io.confluent.ksql.KsqlExecutionContext) KsqlEngineMetrics(io.confluent.ksql.internal.KsqlEngineMetrics) Optional(java.util.Optional) Collections(java.util.Collections) PreparedStatement(io.confluent.ksql.parser.KsqlParser.PreparedStatement) DefaultFormatInjector(io.confluent.ksql.format.DefaultFormatInjector) KsqlStatementException(io.confluent.ksql.util.KsqlStatementException)

Example 2 with DefaultSchemaInjector

use of io.confluent.ksql.schema.ksql.inference.DefaultSchemaInjector in project ksql by confluentinc.

the class KsqlEngineTestUtil method execute.

/**
 * @param srClient if supplied, then schemas can be inferred from the schema registry.
 */
public static List<QueryMetadata> execute(final ServiceContext serviceContext, final KsqlEngine engine, final String sql, final KsqlConfig ksqlConfig, final Map<String, Object> overriddenProperties, final Optional<SchemaRegistryClient> srClient) {
    final List<ParsedStatement> statements = engine.parse(sql);
    final Optional<DefaultSchemaInjector> schemaInjector = srClient.map(SchemaRegistryTopicSchemaSupplier::new).map(supplier -> new DefaultSchemaInjector(supplier, engine, serviceContext));
    return statements.stream().map(stmt -> execute(serviceContext, engine, stmt, ksqlConfig, overriddenProperties, schemaInjector)).map(ExecuteResult::getQuery).filter(Optional::isPresent).map(Optional::get).collect(Collectors.toList());
}
Also used : Optional(java.util.Optional) ParsedStatement(io.confluent.ksql.parser.KsqlParser.ParsedStatement) DefaultSchemaInjector(io.confluent.ksql.schema.ksql.inference.DefaultSchemaInjector)

Aggregations

ParsedStatement (io.confluent.ksql.parser.KsqlParser.ParsedStatement)2 DefaultSchemaInjector (io.confluent.ksql.schema.ksql.inference.DefaultSchemaInjector)2 Optional (java.util.Optional)2 SchemaRegistryClient (io.confluent.kafka.schemaregistry.client.SchemaRegistryClient)1 KsqlExecutionContext (io.confluent.ksql.KsqlExecutionContext)1 ExecuteResult (io.confluent.ksql.KsqlExecutionContext.ExecuteResult)1 SessionConfig (io.confluent.ksql.config.SessionConfig)1 DefaultFormatInjector (io.confluent.ksql.format.DefaultFormatInjector)1 KsqlEngineMetrics (io.confluent.ksql.internal.KsqlEngineMetrics)1 ProcessingLogContext (io.confluent.ksql.logging.processing.ProcessingLogContext)1 MutableMetaStore (io.confluent.ksql.metastore.MutableMetaStore)1 MetricCollectors (io.confluent.ksql.metrics.MetricCollectors)1 PreparedStatement (io.confluent.ksql.parser.KsqlParser.PreparedStatement)1 Query (io.confluent.ksql.parser.tree.Query)1 QueryIdGenerator (io.confluent.ksql.query.id.QueryIdGenerator)1 SequentialQueryIdGenerator (io.confluent.ksql.query.id.SequentialQueryIdGenerator)1 SchemaRegistryTopicSchemaSupplier (io.confluent.ksql.schema.ksql.inference.SchemaRegistryTopicSchemaSupplier)1 ServiceContext (io.confluent.ksql.services.ServiceContext)1 ConfiguredStatement (io.confluent.ksql.statement.ConfiguredStatement)1 KsqlConfig (io.confluent.ksql.util.KsqlConfig)1