use of io.confluent.ksql.execution.expression.tree.DereferenceExpression 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.execution.expression.tree.DereferenceExpression 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")));
}
use of io.confluent.ksql.execution.expression.tree.DereferenceExpression in project ksql by confluentinc.
the class ColumnNamesTest method shouldGenerateSimpleStructColumnName.
@Test
public void shouldGenerateSimpleStructColumnName() {
// Given:
final LogicalSchema schema = LogicalSchema.builder().build();
final ColumnAliasGenerator generator = ColumnNames.columnAliasGenerator(Stream.of(schema));
final DereferenceExpression exp = new DereferenceExpression(LOCATION, STRUCT_COLUMN, "Field_name");
// When:
final ColumnName result1 = generator.uniqueAliasFor(exp);
final ColumnName result2 = generator.uniqueAliasFor(exp);
// Then:
assertThat(result1, is(ColumnName.of("Field_name")));
assertThat(result2, is(ColumnName.of("Field_name_1")));
}
use of io.confluent.ksql.execution.expression.tree.DereferenceExpression in project ksql by confluentinc.
the class ColumnNamesTest method shouldEnsureGeneratedAliasesAreCaseSensitive.
@Test
public void shouldEnsureGeneratedAliasesAreCaseSensitive() {
// Given:
final LogicalSchema schema = LogicalSchema.builder().keyColumn(ColumnName.of("KSQL_COL_0"), SqlTypes.STRING).keyColumn(ColumnName.of("KSQL_COL_1"), SqlTypes.STRING).keyColumn(ColumnName.of("ksql_COL_2"), SqlTypes.STRING).valueColumn(ColumnName.of("someField"), SqlTypes.STRING).valueColumn(ColumnName.of("SOMEFIELD_1"), SqlTypes.STRING).build();
final ColumnAliasGenerator generator = ColumnNames.columnAliasGenerator(Stream.of(schema));
// When:
final ColumnName result1 = generator.uniqueAliasFor(new DereferenceExpression(LOCATION, STRUCT_COLUMN, "KSQL_COL"));
final ColumnName result2 = generator.uniqueAliasFor(new DereferenceExpression(LOCATION, STRUCT_COLUMN, "someField"));
// Then:
assertThat(result1, is(ColumnName.of("KSQL_COL_2")));
assertThat(result2, is(ColumnName.of("someField_1")));
}
use of io.confluent.ksql.execution.expression.tree.DereferenceExpression in project ksql by confluentinc.
the class ExpressionTypeManagerTest method shouldEvaluateTypeForStructDereferenceInArray.
@Test
public void shouldEvaluateTypeForStructDereferenceInArray() {
// Given:
final SqlStruct inner = SqlTypes.struct().field("IN0", SqlTypes.INTEGER).build();
final LogicalSchema schema = LogicalSchema.builder().keyColumn(SystemColumns.ROWKEY_NAME, SqlTypes.STRING).valueColumn(COL0, SqlTypes.array(inner)).build();
expressionTypeManager = new ExpressionTypeManager(schema, functionRegistry);
final Expression expression = new DereferenceExpression(Optional.empty(), new SubscriptExpression(TestExpressions.COL0, new IntegerLiteral(1)), "IN0");
// When:
final SqlType result = expressionTypeManager.getExpressionSqlType(expression);
// Then:
assertThat(result, is(SqlTypes.INTEGER));
}
Aggregations