Search in sources :

Example 11 with Column

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

the class KeyValueExtractor method extractValues.

public static GenericRow extractValues(final JsonObject values, final LogicalSchema logicalSchema, final SqlValueCoercer sqlValueCoercer) {
    final List<Column> valColumns = logicalSchema.value();
    final List<Object> vals = new ArrayList<>(valColumns.size());
    for (Column column : valColumns) {
        final String colName = column.name().text();
        // Need to decode JSON bytes because they are base64 encoded
        final Object val = (column.type().baseType() == SqlBaseType.BYTES) ? decodeJsonBytes((String) values.getValue(colName)) : values.getValue(colName);
        final Object coercedValue = val == null ? null : coerceObject(val, column.type(), sqlValueCoercer);
        vals.add(coercedValue);
    }
    return GenericRow.fromList(vals);
}
Also used : Column(io.confluent.ksql.schema.ksql.Column) ArrayList(java.util.ArrayList) JsonObject(io.vertx.core.json.JsonObject)

Example 12 with Column

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

the class ColumnSerdeTest method shouldDeserializeColumnString.

@Test
public void shouldDeserializeColumnString() throws IOException {
    final Column column = MAPPER.readValue(COLUMN_STRING, Column.class);
    assertThat(column.name(), equalTo(COLUMN.name()));
    assertThat(column.type(), equalTo(COLUMN.type()));
    assertThat(column.namespace(), equalTo(COLUMN.namespace()));
}
Also used : Column(io.confluent.ksql.schema.ksql.Column) Test(org.junit.Test)

Example 13 with Column

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

the class TombstoneFactory method buildKeyIdx.

private static ImmutableMap<Integer, Integer> buildKeyIdx(final LogicalSchema schema, final ResultType resultType) {
    final List<ColumnName> keyColumns = keyColumnNames(schema, resultType);
    final List<Column> projection = schema.value();
    final Map<ColumnName, Integer> columnIndexes = new HashMap<>(projection.size());
    for (int columnIndex = 0; columnIndex < projection.size(); columnIndex++) {
        final Column column = projection.get(columnIndex);
        columnIndexes.put(column.name(), columnIndex);
    }
    final Builder<Integer, Integer> builder = ImmutableMap.builder();
    for (int keyIndex = 0; keyIndex < keyColumns.size(); keyIndex++) {
        final Integer columnIndex = columnIndexes.get(keyColumns.get(keyIndex));
        if (columnIndex == null) {
            // Not in projection
            continue;
        }
        builder.put(columnIndex, keyIndex);
    }
    return builder.build();
}
Also used : ColumnName(io.confluent.ksql.name.ColumnName) SimpleColumn(io.confluent.ksql.schema.ksql.SimpleColumn) Column(io.confluent.ksql.schema.ksql.Column) HashMap(java.util.HashMap)

Example 14 with Column

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

the class AggregateParamsFactory method buildSchema.

private static LogicalSchema buildSchema(final LogicalSchema schema, final List<ColumnName> nonAggregateColumns, final List<KsqlAggregateFunction<?, ?, ?>> aggregateFunctions, final boolean useAggregate, final boolean addWindowBounds) {
    final LogicalSchema.Builder schemaBuilder = LogicalSchema.builder();
    schemaBuilder.keyColumns(schema.key());
    for (final ColumnName columnName : nonAggregateColumns) {
        final Column col = schema.findValueColumn(columnName).orElseThrow(IllegalArgumentException::new);
        schemaBuilder.valueColumn(col);
    }
    for (int i = 0; i < aggregateFunctions.size(); i++) {
        final KsqlAggregateFunction<?, ?, ?> aggregateFunction = aggregateFunctions.get(i);
        final ColumnName colName = ColumnNames.aggregateColumn(i);
        final SqlType fieldType = useAggregate ? aggregateFunction.getAggregateType() : aggregateFunction.returnType();
        schemaBuilder.valueColumn(colName, fieldType);
    }
    if (addWindowBounds) {
        // Add window bounds columns, as populated by WindowBoundsPopulator
        schemaBuilder.valueColumn(SystemColumns.WINDOWSTART_NAME, SystemColumns.WINDOWBOUND_TYPE);
        schemaBuilder.valueColumn(SystemColumns.WINDOWEND_NAME, SystemColumns.WINDOWBOUND_TYPE);
    }
    return schemaBuilder.build();
}
Also used : ColumnName(io.confluent.ksql.name.ColumnName) Column(io.confluent.ksql.schema.ksql.Column) LogicalSchema(io.confluent.ksql.schema.ksql.LogicalSchema) SqlType(io.confluent.ksql.schema.ksql.types.SqlType)

Example 15 with Column

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

the class SchemaKTableTest method buildJoinSchema.

private LogicalSchema buildJoinSchema(final KsqlTable table) {
    final LogicalSchema.Builder builder = LogicalSchema.builder();
    builder.keyColumns(table.getSchema().key());
    for (final Column c : table.getSchema().value()) {
        builder.valueColumn(ColumnNames.generatedJoinColumnAlias(table.getName(), c.name()), c.type());
    }
    return builder.build();
}
Also used : Column(io.confluent.ksql.schema.ksql.Column) LogicalSchema(io.confluent.ksql.schema.ksql.LogicalSchema)

Aggregations

Column (io.confluent.ksql.schema.ksql.Column)29 ColumnName (io.confluent.ksql.name.ColumnName)14 LogicalSchema (io.confluent.ksql.schema.ksql.LogicalSchema)14 Collectors (java.util.stream.Collectors)9 Expression (io.confluent.ksql.execution.expression.tree.Expression)8 UnqualifiedColumnReferenceExp (io.confluent.ksql.execution.expression.tree.UnqualifiedColumnReferenceExp)8 SqlType (io.confluent.ksql.schema.ksql.types.SqlType)8 KsqlException (io.confluent.ksql.util.KsqlException)8 List (java.util.List)8 Optional (java.util.Optional)8 ColumnReferenceExp (io.confluent.ksql.execution.expression.tree.ColumnReferenceExp)7 TimestampColumn (io.confluent.ksql.execution.timestamp.TimestampColumn)7 ExpressionTypeManager (io.confluent.ksql.execution.util.ExpressionTypeManager)7 Set (java.util.Set)7 SelectExpression (io.confluent.ksql.execution.plan.SelectExpression)6 KsqlTopic (io.confluent.ksql.execution.ddl.commands.KsqlTopic)5 DataSource (io.confluent.ksql.metastore.model.DataSource)5 SourceName (io.confluent.ksql.name.SourceName)5 Builder (io.confluent.ksql.schema.ksql.LogicalSchema.Builder)5 FormatInfo (io.confluent.ksql.serde.FormatInfo)5