Search in sources :

Example 6 with DereferenceExpression

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")));
}
Also used : ColumnName(io.confluent.ksql.name.ColumnName) DereferenceExpression(io.confluent.ksql.execution.expression.tree.DereferenceExpression) Test(org.junit.Test)

Example 7 with DereferenceExpression

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")));
}
Also used : ColumnName(io.confluent.ksql.name.ColumnName) DereferenceExpression(io.confluent.ksql.execution.expression.tree.DereferenceExpression) Test(org.junit.Test)

Example 8 with DereferenceExpression

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")));
}
Also used : ColumnName(io.confluent.ksql.name.ColumnName) DereferenceExpression(io.confluent.ksql.execution.expression.tree.DereferenceExpression) Test(org.junit.Test)

Example 9 with DereferenceExpression

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")));
}
Also used : ColumnName(io.confluent.ksql.name.ColumnName) DereferenceExpression(io.confluent.ksql.execution.expression.tree.DereferenceExpression) Test(org.junit.Test)

Example 10 with DereferenceExpression

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));
}
Also used : SqlStruct(io.confluent.ksql.schema.ksql.types.SqlStruct) DereferenceExpression(io.confluent.ksql.execution.expression.tree.DereferenceExpression) ArithmeticBinaryExpression(io.confluent.ksql.execution.expression.tree.ArithmeticBinaryExpression) Expression(io.confluent.ksql.execution.expression.tree.Expression) CreateMapExpression(io.confluent.ksql.execution.expression.tree.CreateMapExpression) DereferenceExpression(io.confluent.ksql.execution.expression.tree.DereferenceExpression) CreateArrayExpression(io.confluent.ksql.execution.expression.tree.CreateArrayExpression) CreateStructExpression(io.confluent.ksql.execution.expression.tree.CreateStructExpression) NotExpression(io.confluent.ksql.execution.expression.tree.NotExpression) SimpleCaseExpression(io.confluent.ksql.execution.expression.tree.SimpleCaseExpression) SubscriptExpression(io.confluent.ksql.execution.expression.tree.SubscriptExpression) InListExpression(io.confluent.ksql.execution.expression.tree.InListExpression) ComparisonExpression(io.confluent.ksql.execution.expression.tree.ComparisonExpression) SearchedCaseExpression(io.confluent.ksql.execution.expression.tree.SearchedCaseExpression) SubscriptExpression(io.confluent.ksql.execution.expression.tree.SubscriptExpression) LogicalSchema(io.confluent.ksql.schema.ksql.LogicalSchema) SqlType(io.confluent.ksql.schema.ksql.types.SqlType) IntegerLiteral(io.confluent.ksql.execution.expression.tree.IntegerLiteral) Test(org.junit.Test)

Aggregations

DereferenceExpression (io.confluent.ksql.execution.expression.tree.DereferenceExpression)16 Test (org.junit.Test)16 ArithmeticBinaryExpression (io.confluent.ksql.execution.expression.tree.ArithmeticBinaryExpression)8 Expression (io.confluent.ksql.execution.expression.tree.Expression)8 UnqualifiedColumnReferenceExp (io.confluent.ksql.execution.expression.tree.UnqualifiedColumnReferenceExp)7 ComparisonExpression (io.confluent.ksql.execution.expression.tree.ComparisonExpression)6 CreateArrayExpression (io.confluent.ksql.execution.expression.tree.CreateArrayExpression)6 CreateMapExpression (io.confluent.ksql.execution.expression.tree.CreateMapExpression)6 CreateStructExpression (io.confluent.ksql.execution.expression.tree.CreateStructExpression)6 InListExpression (io.confluent.ksql.execution.expression.tree.InListExpression)6 SearchedCaseExpression (io.confluent.ksql.execution.expression.tree.SearchedCaseExpression)6 SubscriptExpression (io.confluent.ksql.execution.expression.tree.SubscriptExpression)6 LogicalSchema (io.confluent.ksql.schema.ksql.LogicalSchema)6 NotExpression (io.confluent.ksql.execution.expression.tree.NotExpression)5 SimpleCaseExpression (io.confluent.ksql.execution.expression.tree.SimpleCaseExpression)5 ColumnName (io.confluent.ksql.name.ColumnName)5 ArithmeticUnaryExpression (io.confluent.ksql.execution.expression.tree.ArithmeticUnaryExpression)4 IntegerLiteral (io.confluent.ksql.execution.expression.tree.IntegerLiteral)3 SqlType (io.confluent.ksql.schema.ksql.types.SqlType)3 LogicalBinaryExpression (io.confluent.ksql.execution.expression.tree.LogicalBinaryExpression)2