use of io.confluent.ksql.name.ColumnName in project ksql by confluentinc.
the class Selection method buildSchema.
private static LogicalSchema buildSchema(final LogicalSchema sourceSchema, final SelectValueMapper<?> mapper, final List<ColumnName> keyColumnNames) {
final List<ColumnName> keyNames = keyColumnNames.isEmpty() ? getKeyColumnNames(sourceSchema) : keyColumnNames;
final List<Column> keyCols = sourceSchema.key();
if (keyNames.size() != keyCols.size()) {
throw new IllegalArgumentException("key name count mismatch. " + "names: " + keyNames + ", " + "keys: " + keyCols);
}
final LogicalSchema.Builder schemaBuilder = LogicalSchema.builder();
for (int i = 0; i != keyCols.size(); ++i) {
schemaBuilder.keyColumn(keyNames.get(i), keyCols.get(i).type());
}
for (final SelectInfo select : mapper.getSelects()) {
schemaBuilder.valueColumn(select.getFieldName(), select.getEvaluator().getExpressionType());
}
return schemaBuilder.build();
}
use of io.confluent.ksql.name.ColumnName in project ksql by confluentinc.
the class ColumnReferenceValidatorTest method shouldGetSourceForUnqualifiedColumnRef.
@Test
public void shouldGetSourceForUnqualifiedColumnRef() {
// Given:
final ColumnName column = ColumnName.of("qualified");
final Expression expression = new QualifiedColumnReferenceExp(SourceName.of("fully"), column);
when(sourceSchemas.sourcesWithField(any(), any())).thenReturn(sourceNames("something"));
// When:
analyzer.analyzeExpression(expression, CLAUSE_TYPE);
// Then:
verify(sourceSchemas).sourcesWithField(Optional.of(SourceName.of("fully")), column);
}
use of io.confluent.ksql.name.ColumnName in project ksql by confluentinc.
the class ColumnNamesTest method shouldIncrementSyntheticJoinColumnOnClashes.
@Test
public void shouldIncrementSyntheticJoinColumnOnClashes() {
// Given:
final LogicalSchema schema = LogicalSchema.builder().keyColumn(ColumnName.of("ROWKEY"), SqlTypes.STRING).keyColumn(ColumnName.of("ROWKEY_1"), SqlTypes.STRING).keyColumn(ColumnName.of("ROWKEY_2"), SqlTypes.STRING).valueColumn(ColumnName.of("someField"), SqlTypes.STRING).valueColumn(ColumnName.of("ROWKEY_3"), SqlTypes.STRING).build();
// When:
final ColumnName columnName = ColumnNames.generateSyntheticJoinKey(Stream.of(schema));
// Then:
assertThat(columnName, is(ColumnName.of("ROWKEY_4")));
}
use of io.confluent.ksql.name.ColumnName in project ksql by confluentinc.
the class ColumnNamesTest method shouldGenerateStructAliasesForSchemasWithAnyColumnNames.
@Test
public void shouldGenerateStructAliasesForSchemasWithAnyColumnNames() {
// Given:
final LogicalSchema schema = LogicalSchema.builder().keyColumn(ColumnName.of("12345"), SqlTypes.STRING).keyColumn(ColumnName.of("12startsWithNumbers"), SqlTypes.STRING).keyColumn(ColumnName.of("12startsAndEndsWithNumbers84"), SqlTypes.STRING).valueColumn(ColumnName.of("numbers12In45Middle"), SqlTypes.STRING).valueColumn(ColumnName.of("endsWithZero0"), SqlTypes.STRING).build();
final ColumnAliasGenerator generator = ColumnNames.columnAliasGenerator(Stream.of(schema));
final DereferenceExpression fieldWithNameClash = new DereferenceExpression(LOCATION, STRUCT_COLUMN, "12345");
// When:
final ColumnName result = generator.uniqueAliasFor(fieldWithNameClash);
// Then:
assertThat(result, is(ColumnName.of("12345_1")));
}
use of io.confluent.ksql.name.ColumnName in project ksql by confluentinc.
the class ColumnNamesTest method shouldEnsureGeneratedStructAliasesDoNotClash.
@Test
public void shouldEnsureGeneratedStructAliasesDoNotClash() {
// Given:
final LogicalSchema schema = LogicalSchema.builder().keyColumn(ColumnName.of("someField_2"), SqlTypes.STRING).keyColumn(ColumnName.of("other"), SqlTypes.STRING).keyColumn(ColumnName.of("someField_3"), SqlTypes.STRING).valueColumn(ColumnName.of("another"), SqlTypes.STRING).valueColumn(ColumnName.of("someField"), SqlTypes.STRING).build();
final ColumnAliasGenerator generator = ColumnNames.columnAliasGenerator(Stream.of(schema));
final DereferenceExpression fieldWithNameClash = new DereferenceExpression(LOCATION, STRUCT_COLUMN, "someField");
// When:
final ColumnName result1 = generator.uniqueAliasFor(fieldWithNameClash);
final ColumnName result2 = generator.uniqueAliasFor(fieldWithNameClash);
// Then:
assertThat(result1, is(ColumnName.of("someField_1")));
assertThat(result2, is(ColumnName.of("someField_4")));
}
Aggregations