use of io.confluent.ksql.schema.ksql.LogicalSchema.Builder in project ksql by confluentinc.
the class JoinParamsFactory method createSchema.
public static LogicalSchema createSchema(final ColumnName keyColName, final LogicalSchema leftSchema, final LogicalSchema rightSchema) {
final SqlType keyType = throwOnKeyMismatch(leftSchema, rightSchema);
final Builder builder = LogicalSchema.builder().keyColumn(keyColName, keyType).valueColumns(leftSchema.value()).valueColumns(rightSchema.value());
if (neitherContain(keyColName, leftSchema, rightSchema)) {
// Append key to value so its accessible during processing:
builder.valueColumn(keyColName, keyType);
}
return builder.build();
}
use of io.confluent.ksql.schema.ksql.LogicalSchema.Builder in project ksql by confluentinc.
the class QueryProjectNode method buildOutputSchema.
/**
* Builds the output schema of the project node.
* The output schema comprises of exactly the columns that appear in the SELECT clause of the
* query.
* @param metaStore the metastore
* @return the project node's output schema
*/
private LogicalSchema buildOutputSchema(final MetaStore metaStore) {
final LogicalSchema outputSchema;
final LogicalSchema parentSchema = getSource().getSchema();
final boolean isWindowed = analysis.getFrom().getDataSource().getKsqlTopic().getKeyFormat().isWindowed();
if (isSelectStar()) {
outputSchema = buildPullQuerySelectStarSchema(parentSchema.withoutPseudoAndKeyColsInValue(ksqlConfig), isWindowed);
} else {
final List<SelectExpression> projects = projection.selectItems().stream().map(SingleColumn.class::cast).map(si -> SelectExpression.of(si.getAlias().orElseThrow(IllegalStateException::new), si.getExpression())).collect(Collectors.toList());
outputSchema = selectOutputSchema(metaStore, projects, isWindowed);
}
if (isScalablePush) {
// Transient queries return key columns in the value, so the projection includes them, and
// the schema needs to include them too:
final Builder builder = LogicalSchema.builder();
outputSchema.columns().forEach(builder::valueColumn);
return builder.build();
}
return outputSchema;
}
use of io.confluent.ksql.schema.ksql.LogicalSchema.Builder in project ksql by confluentinc.
the class RowGenerator method buildLogicalSchema.
private static LogicalSchema buildLogicalSchema(final Generator generator, final AvroData avroData, final String keyFieldName) {
final org.apache.kafka.connect.data.Schema connectSchema = avroData.toConnectSchema(generator.schema());
final Field keyField = connectSchema.field(keyFieldName);
if (keyField == null) {
throw new IllegalArgumentException("key field does not exist in schema: " + keyFieldName);
}
final Builder schemaBuilder = LogicalSchema.builder();
final ConnectToSqlTypeConverter converter = SchemaConverters.connectToSqlConverter();
schemaBuilder.keyColumn(KEY_COL_NAME, converter.toSqlType(keyField.schema()));
connectSchema.fields().forEach(f -> schemaBuilder.valueColumn(ColumnName.of(f.name()), converter.toSqlType(f.schema())));
return schemaBuilder.build();
}
use of io.confluent.ksql.schema.ksql.LogicalSchema.Builder in project ksql by confluentinc.
the class LogicalSchemaTest method shouldThrowOnMultipleHeadersColumns.
@Test
public void shouldThrowOnMultipleHeadersColumns() {
// Given:
final Builder builder = LogicalSchema.builder().headerColumn(H0, Optional.empty());
// When:
final Exception e = assertThrows(KsqlException.class, () -> builder.headerColumn(F0, Optional.empty()));
// Then:
assertThat(e.getMessage(), containsString("Schema already contains a HEADERS column."));
}
use of io.confluent.ksql.schema.ksql.LogicalSchema.Builder in project ksql by confluentinc.
the class LogicalSchemaTest method shouldDuplicateViaAsBuilder.
@Test
public void shouldDuplicateViaAsBuilder() {
// Given:
final Builder builder = SOME_SCHEMA.asBuilder();
// When:
final LogicalSchema clone = builder.build();
// Then:
assertThat(clone, is(SOME_SCHEMA));
}
Aggregations