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