use of io.confluent.ksql.schema.ksql.Column in project ksql by confluentinc.
the class DefaultSchemaInjector method getCreateAsValueSchema.
private Optional<SchemaAndId> getCreateAsValueSchema(final ConfiguredStatement<CreateAsSelect> statement, final CreateSourceCommand createSourceCommand) {
final CreateAsSelect csStmt = statement.getStatement();
final CreateSourceAsProperties props = csStmt.getProperties();
final FormatInfo valueFormat = createSourceCommand.getFormats().getValueFormat();
if (!shouldInferSchema(props.getValueSchemaId(), statement, valueFormat, false)) {
return Optional.empty();
}
final SchemaAndId schemaAndId = getSchema(props.getKafkaTopic(), props.getValueSchemaId(), valueFormat, createSourceCommand.getFormats().getValueFeatures(), statement.getStatementText(), false);
final List<Column> tableColumns = createSourceCommand.getSchema().value();
checkColumnsCompatibility(props.getValueSchemaId(), tableColumns, schemaAndId.columns, false);
return Optional.of(schemaAndId);
}
use of io.confluent.ksql.schema.ksql.Column in project ksql by confluentinc.
the class SourceBuilderUtils method timestampExtractor.
static TimestampExtractor timestampExtractor(final KsqlConfig ksqlConfig, final LogicalSchema sourceSchema, final Optional<TimestampColumn> timestampColumn, final SourceStep<?> streamSource, final RuntimeBuildContext buildContext) {
final TimestampExtractionPolicy timestampPolicy = TimestampExtractionPolicyFactory.create(ksqlConfig, sourceSchema, timestampColumn);
final Optional<Column> tsColumn = timestampColumn.map(TimestampColumn::getColumn).map(c -> sourceSchema.findColumn(c).orElseThrow(IllegalStateException::new));
final QueryContext queryContext = streamSource.getProperties().getQueryContext();
return timestampPolicy.create(tsColumn, ksqlConfig.getBoolean(KsqlConfig.KSQL_TIMESTAMP_THROW_ON_INVALID), buildContext.getProcessingLogger(queryContext));
}
use of io.confluent.ksql.schema.ksql.Column in project ksql by confluentinc.
the class StreamFlatMapBuilder method buildSchema.
public static LogicalSchema buildSchema(final LogicalSchema inputSchema, final List<FunctionCall> tableFunctions, final FunctionRegistry functionRegistry) {
final LogicalSchema.Builder schemaBuilder = LogicalSchema.builder();
final List<Column> cols = inputSchema.value();
// We copy all the original columns to the output schema
schemaBuilder.keyColumns(inputSchema.key());
for (final Column col : cols) {
schemaBuilder.valueColumn(col);
}
final ExpressionTypeManager expressionTypeManager = new ExpressionTypeManager(inputSchema, functionRegistry);
// And add new columns representing the exploded values at the end
for (int i = 0; i < tableFunctions.size(); i++) {
final FunctionCall functionCall = tableFunctions.get(i);
final ColumnName colName = ColumnNames.synthesisedSchemaColumn(i);
final SqlType fieldType = expressionTypeManager.getExpressionSqlType(functionCall);
schemaBuilder.valueColumn(colName, fieldType);
}
return schemaBuilder.build();
}
use of io.confluent.ksql.schema.ksql.Column in project ksql by confluentinc.
the class JoinParamsFactory method throwOnKeyMismatch.
private static SqlType throwOnKeyMismatch(final LogicalSchema leftSchema, final LogicalSchema rightSchema) {
final List<Column> leftKeyCols = leftSchema.key();
final List<Column> rightKeyCols = rightSchema.key();
if (leftKeyCols.size() != 1 || rightKeyCols.size() != 1) {
throw new UnsupportedOperationException("Multi-key joins not supported");
}
final Column leftKey = leftKeyCols.get(0);
final Column rightKey = rightKeyCols.get(0);
if (!leftKey.type().equals(rightKey.type())) {
throw new KsqlException("Invalid join. Key types differ: " + leftKey.type() + " vs " + rightKey.type());
}
return leftKey.type();
}
Aggregations