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