Search in sources :

Example 91 with LogicalSchema

use of io.confluent.ksql.schema.ksql.LogicalSchema in project ksql by confluentinc.

the class EntityUtilTest method shouldBuildCorrectPrimitiveField.

private static void shouldBuildCorrectPrimitiveField(final SqlType primitiveSchema, final String schemaName) {
    // Given:
    final LogicalSchema schema = LogicalSchema.builder().valueColumn(ColumnName.of("field"), primitiveSchema).build();
    // When:
    final List<FieldInfo> fields = EntityUtil.buildSourceSchemaEntity(schema);
    // Then:
    assertThat(fields.get(0).getName(), equalTo("field"));
    assertThat(fields.get(0).getSchema().getTypeName(), equalTo(schemaName));
    assertThat(fields.get(0).getSchema().getFields(), equalTo(Optional.empty()));
    assertThat(fields.get(0).getSchema().getMemberSchema(), equalTo(Optional.empty()));
    assertThat(fields.get(0).getType(), equalTo(Optional.empty()));
}
Also used : LogicalSchema(io.confluent.ksql.schema.ksql.LogicalSchema) FieldInfo(io.confluent.ksql.rest.entity.FieldInfo)

Example 92 with LogicalSchema

use of io.confluent.ksql.schema.ksql.LogicalSchema in project ksql by confluentinc.

the class EntityUtilTest method shouldSupportSchemasWithAllHeadersColumn.

@Test
public void shouldSupportSchemasWithAllHeadersColumn() {
    // Given:
    final LogicalSchema schema = LogicalSchema.builder().headerColumn(ColumnName.of("field1"), Optional.empty()).build();
    // When:
    final List<FieldInfo> fields = EntityUtil.buildSourceSchemaEntity(schema);
    // Then:
    assertThat(fields, hasSize(1));
    assertThat(fields.get(0).getName(), equalTo("field1"));
    assertThat(fields.get(0).getSchema().getTypeName(), equalTo("ARRAY"));
    assertThat(fields.get(0).getType(), equalTo(Optional.of(FieldType.HEADER)));
    assertThat(fields.get(0).getHeaderKey(), equalTo(Optional.empty()));
}
Also used : LogicalSchema(io.confluent.ksql.schema.ksql.LogicalSchema) FieldInfo(io.confluent.ksql.rest.entity.FieldInfo) Test(org.junit.Test)

Example 93 with LogicalSchema

use of io.confluent.ksql.schema.ksql.LogicalSchema in project ksql by confluentinc.

the class EntityUtilTest method shouldSupportSchemasWithExtractedHeaderColumns.

@Test
public void shouldSupportSchemasWithExtractedHeaderColumns() {
    // Given:
    final LogicalSchema schema = LogicalSchema.builder().headerColumn(ColumnName.of("field1"), Optional.of("abc")).build();
    // When:
    final List<FieldInfo> fields = EntityUtil.buildSourceSchemaEntity(schema);
    // Then:
    assertThat(fields, hasSize(1));
    assertThat(fields.get(0).getName(), equalTo("field1"));
    assertThat(fields.get(0).getSchema().getTypeName(), equalTo("BYTES"));
    assertThat(fields.get(0).getType(), equalTo(Optional.of(FieldType.HEADER)));
    assertThat(fields.get(0).getHeaderKey(), equalTo(Optional.of("abc")));
}
Also used : LogicalSchema(io.confluent.ksql.schema.ksql.LogicalSchema) FieldInfo(io.confluent.ksql.rest.entity.FieldInfo) Test(org.junit.Test)

Example 94 with LogicalSchema

use of io.confluent.ksql.schema.ksql.LogicalSchema in project ksql by confluentinc.

the class EntityUtilTest method shouldSupportRowTimeAndKeyInValueSchema.

@Test
public void shouldSupportRowTimeAndKeyInValueSchema() {
    // Given:
    final LogicalSchema schema = LogicalSchema.builder().valueColumn(ColumnName.of("ROWKEY"), SqlTypes.STRING).valueColumn(ColumnName.of("ROWTIME"), SqlTypes.INTEGER).valueColumn(ColumnName.of("field1"), SqlTypes.INTEGER).build();
    // When:
    final List<FieldInfo> fields = EntityUtil.buildSourceSchemaEntity(schema);
    // Then:
    assertThat(fields, hasSize(3));
    assertThat(fields.get(0).getName(), equalTo("ROWKEY"));
    assertThat(fields.get(0).getType(), equalTo(Optional.empty()));
    assertThat(fields.get(1).getName(), equalTo("ROWTIME"));
    assertThat(fields.get(1).getType(), equalTo(Optional.empty()));
}
Also used : LogicalSchema(io.confluent.ksql.schema.ksql.LogicalSchema) FieldInfo(io.confluent.ksql.rest.entity.FieldInfo) Test(org.junit.Test)

Example 95 with LogicalSchema

use of io.confluent.ksql.schema.ksql.LogicalSchema in project ksql by confluentinc.

the class PartitionByParamsFactory method build.

public static <K> PartitionByParams<K> build(final LogicalSchema sourceSchema, final ExecutionKeyFactory<K> serdeFactory, final List<Expression> partitionBys, final KsqlConfig ksqlConfig, final FunctionRegistry functionRegistry, final ProcessingLogger logger) {
    final List<PartitionByColumn> partitionByCols = getPartitionByColumnName(sourceSchema, partitionBys);
    final LogicalSchema resultSchema = buildSchema(sourceSchema, partitionBys, functionRegistry, partitionByCols);
    final Mapper<K> mapper;
    if (isPartitionByNull(partitionBys)) {
        // In case of PARTITION BY NULL, it is sufficient to set the new key to null as the old key
        // is already present in the current value
        mapper = (k, v) -> new KeyValue<>(null, v);
    } else {
        final List<PartitionByExpressionEvaluator> evaluators = partitionBys.stream().map(pby -> {
            final Set<? extends ColumnReferenceExp> sourceColsInPartitionBy = ColumnExtractor.extractColumns(pby);
            final boolean partitionByInvolvesKeyColsOnly = sourceColsInPartitionBy.stream().map(ColumnReferenceExp::getColumnName).allMatch(sourceSchema::isKeyColumn);
            return buildExpressionEvaluator(sourceSchema, pby, ksqlConfig, functionRegistry, logger, partitionByInvolvesKeyColsOnly);
        }).collect(Collectors.toList());
        mapper = buildMapper(partitionByCols, evaluators, serdeFactory);
    }
    return new PartitionByParams<>(resultSchema, mapper);
}
Also used : ColumnExtractor(io.confluent.ksql.execution.util.ColumnExtractor) ColumnName(io.confluent.ksql.name.ColumnName) CompiledExpression(io.confluent.ksql.execution.codegen.CompiledExpression) KeyUtil(io.confluent.ksql.execution.util.KeyUtil) Supplier(java.util.function.Supplier) CodeGenRunner(io.confluent.ksql.execution.codegen.CodeGenRunner) ExpressionTypeManager(io.confluent.ksql.execution.util.ExpressionTypeManager) ProcessingLogger(io.confluent.ksql.logging.processing.ProcessingLogger) NullLiteral(io.confluent.ksql.execution.expression.tree.NullLiteral) ColumnReferenceExp(io.confluent.ksql.execution.expression.tree.ColumnReferenceExp) Mapper(io.confluent.ksql.execution.streams.PartitionByParams.Mapper) SqlType(io.confluent.ksql.schema.ksql.types.SqlType) ColumnNames(io.confluent.ksql.schema.ksql.ColumnNames) Expression(io.confluent.ksql.execution.expression.tree.Expression) FunctionRegistry(io.confluent.ksql.function.FunctionRegistry) KeyValue(org.apache.kafka.streams.KeyValue) Set(java.util.Set) KsqlConfig(io.confluent.ksql.util.KsqlConfig) ExecutionKeyFactory(io.confluent.ksql.execution.plan.ExecutionKeyFactory) LogicalSchema(io.confluent.ksql.schema.ksql.LogicalSchema) Collectors(java.util.stream.Collectors) Builder(io.confluent.ksql.schema.ksql.LogicalSchema.Builder) Objects(java.util.Objects) List(java.util.List) ColumnAliasGenerator(io.confluent.ksql.schema.ksql.ColumnAliasGenerator) Stream(java.util.stream.Stream) GenericRow(io.confluent.ksql.GenericRow) KsqlException(io.confluent.ksql.util.KsqlException) GenericKey(io.confluent.ksql.GenericKey) Column(io.confluent.ksql.schema.ksql.Column) ColumnReferenceExp(io.confluent.ksql.execution.expression.tree.ColumnReferenceExp) Set(java.util.Set) LogicalSchema(io.confluent.ksql.schema.ksql.LogicalSchema)

Aggregations

LogicalSchema (io.confluent.ksql.schema.ksql.LogicalSchema)223 Test (org.junit.Test)152 Expression (io.confluent.ksql.execution.expression.tree.Expression)44 ColumnName (io.confluent.ksql.name.ColumnName)31 GenericRow (io.confluent.ksql.GenericRow)30 UnqualifiedColumnReferenceExp (io.confluent.ksql.execution.expression.tree.UnqualifiedColumnReferenceExp)29 KsqlException (io.confluent.ksql.util.KsqlException)27 GenericKey (io.confluent.ksql.GenericKey)20 StringLiteral (io.confluent.ksql.execution.expression.tree.StringLiteral)19 List (java.util.List)16 TimestampColumn (io.confluent.ksql.execution.timestamp.TimestampColumn)14 SqlType (io.confluent.ksql.schema.ksql.types.SqlType)14 Optional (java.util.Optional)14 Collectors (java.util.stream.Collectors)14 QueryContext (io.confluent.ksql.execution.context.QueryContext)13 ArithmeticBinaryExpression (io.confluent.ksql.execution.expression.tree.ArithmeticBinaryExpression)12 DereferenceExpression (io.confluent.ksql.execution.expression.tree.DereferenceExpression)12 SelectExpression (io.confluent.ksql.execution.plan.SelectExpression)12 Column (io.confluent.ksql.schema.ksql.Column)12 ComparisonExpression (io.confluent.ksql.execution.expression.tree.ComparisonExpression)11