Search in sources :

Example 11 with Builder

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

the class LogicalSchemaTest method shouldThrowOnRepeatedHeaderKey.

@Test
public void shouldThrowOnRepeatedHeaderKey() {
    // Given:
    final Builder builder = LogicalSchema.builder().headerColumn(H0, Optional.of("key"));
    // When:
    final Exception e = assertThrows(KsqlException.class, () -> builder.headerColumn(F0, Optional.of("key")));
    // Then:
    assertThat(e.getMessage(), containsString("Schema already contains a HEADER('key') column."));
}
Also used : Builder(io.confluent.ksql.schema.ksql.LogicalSchema.Builder) KsqlException(io.confluent.ksql.util.KsqlException) Test(org.junit.Test)

Example 12 with Builder

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

the class LogicalSchemaTest method shouldDetectDuplicateValuesViaAsBuilder.

@Test
public void shouldDetectDuplicateValuesViaAsBuilder() {
    // Given:
    final Builder builder = SOME_SCHEMA.asBuilder();
    // When:
    assertThrows(KsqlException.class, () -> builder.valueColumn(F0, STRING));
}
Also used : Builder(io.confluent.ksql.schema.ksql.LogicalSchema.Builder) Test(org.junit.Test)

Example 13 with Builder

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

the class LogicalSchemaTest method shouldDetectDuplicateKeysViaAsBuilder.

@Test
public void shouldDetectDuplicateKeysViaAsBuilder() {
    // Given:
    final Builder builder = SOME_SCHEMA.asBuilder();
    // When:
    assertThrows(KsqlException.class, () -> builder.keyColumn(K0, STRING));
}
Also used : Builder(io.confluent.ksql.schema.ksql.LogicalSchema.Builder) Test(org.junit.Test)

Example 14 with Builder

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

the class LogicalSchemaTest method shouldAddColumnsViaAsBuilder.

@Test
public void shouldAddColumnsViaAsBuilder() {
    // Given:
    final Builder builder = SOME_SCHEMA.asBuilder();
    // When:
    final LogicalSchema clone = builder.keyColumn(K1, INTEGER).valueColumn(V1, STRING).build();
    // Then:
    assertThat(clone, is(LogicalSchema.builder().valueColumn(F0, STRING).keyColumn(K0, BIGINT).valueColumn(F1, BIGINT).headerColumn(H0, Optional.empty()).keyColumn(K1, INTEGER).valueColumn(V1, STRING).build()));
}
Also used : Builder(io.confluent.ksql.schema.ksql.LogicalSchema.Builder) Test(org.junit.Test)

Example 15 with Builder

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

the class PartitionByParamsFactory method buildSchema.

private static LogicalSchema buildSchema(final LogicalSchema sourceSchema, final List<Expression> partitionBys, final FunctionRegistry functionRegistry, final List<PartitionByColumn> partitionByCols) {
    final ExpressionTypeManager expressionTypeManager = new ExpressionTypeManager(sourceSchema, functionRegistry);
    final List<SqlType> keyTypes = partitionBys.stream().map(expressionTypeManager::getExpressionSqlType).collect(Collectors.toList());
    if (isPartitionByNull(partitionBys)) {
        final Builder builder = LogicalSchema.builder();
        builder.valueColumns(sourceSchema.value());
        return builder.build();
    } else {
        final Builder builder = LogicalSchema.builder();
        for (int i = 0; i < partitionBys.size(); i++) {
            builder.keyColumn(partitionByCols.get(i).name, keyTypes.get(i));
        }
        builder.valueColumns(sourceSchema.value());
        for (int i = 0; i < partitionBys.size(); i++) {
            if (partitionByCols.get(i).shouldAppend) {
                // New key column added, copy in to value schema:
                builder.valueColumn(partitionByCols.get(i).name, keyTypes.get(i));
            }
        }
        return builder.build();
    }
}
Also used : ExpressionTypeManager(io.confluent.ksql.execution.util.ExpressionTypeManager) Builder(io.confluent.ksql.schema.ksql.LogicalSchema.Builder) SqlType(io.confluent.ksql.schema.ksql.types.SqlType)

Aggregations

Builder (io.confluent.ksql.schema.ksql.LogicalSchema.Builder)22 KsqlException (io.confluent.ksql.util.KsqlException)9 Test (org.junit.Test)9 SqlType (io.confluent.ksql.schema.ksql.types.SqlType)7 LogicalSchema (io.confluent.ksql.schema.ksql.LogicalSchema)6 SelectExpression (io.confluent.ksql.execution.plan.SelectExpression)5 ExpressionTypeManager (io.confluent.ksql.execution.util.ExpressionTypeManager)5 ColumnName (io.confluent.ksql.name.ColumnName)4 List (java.util.List)4 Optional (java.util.Optional)4 Collectors (java.util.stream.Collectors)4 ColumnReferenceExp (io.confluent.ksql.execution.expression.tree.ColumnReferenceExp)3 Expression (io.confluent.ksql.execution.expression.tree.Expression)3 UnqualifiedColumnReferenceExp (io.confluent.ksql.execution.expression.tree.UnqualifiedColumnReferenceExp)3 ImmutableList (com.google.common.collect.ImmutableList)2 SuppressFBWarnings (edu.umd.cs.findbugs.annotations.SuppressFBWarnings)2 RewrittenAnalysis (io.confluent.ksql.analyzer.RewrittenAnalysis)2 CodeGenRunner (io.confluent.ksql.execution.codegen.CodeGenRunner)2 ExpressionEvaluator (io.confluent.ksql.execution.transform.ExpressionEvaluator)2 MetaStore (io.confluent.ksql.metastore.MetaStore)2