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());
}
}
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());
}
Aggregations