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