Search in sources :

Example 11 with DereferenceExpression

use of io.confluent.ksql.execution.expression.tree.DereferenceExpression in project ksql by confluentinc.

the class ExpressionTypeManagerTest method shouldHandleStructFieldDereference.

@Test
public void shouldHandleStructFieldDereference() {
    // Given:
    final Expression expression = new DereferenceExpression(Optional.empty(), new UnqualifiedColumnReferenceExp(ColumnName.of("COL6")), "STREET");
    // When:
    final SqlType result = expressionTypeManager.getExpressionSqlType(expression);
    assertThat(result, is(SqlTypes.STRING));
}
Also used : 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) SqlType(io.confluent.ksql.schema.ksql.types.SqlType) UnqualifiedColumnReferenceExp(io.confluent.ksql.execution.expression.tree.UnqualifiedColumnReferenceExp) Test(org.junit.Test)

Example 12 with DereferenceExpression

use of io.confluent.ksql.execution.expression.tree.DereferenceExpression in project ksql by confluentinc.

the class ColumnNamesTest method shouldEnsureGeneratedStructAliasesDoNotClashForNumericFieldNames.

@Test
public void shouldEnsureGeneratedStructAliasesDoNotClashForNumericFieldNames() {
    // Given:
    final LogicalSchema schema = LogicalSchema.builder().keyColumn(ColumnName.of("1"), SqlTypes.STRING).keyColumn(ColumnName.of("2"), SqlTypes.STRING).keyColumn(ColumnName.of("3_1"), SqlTypes.STRING).valueColumn(ColumnName.of("4"), SqlTypes.STRING).valueColumn(ColumnName.of("5"), SqlTypes.STRING).build();
    final ColumnAliasGenerator generator = ColumnNames.columnAliasGenerator(Stream.of(schema));
    final DereferenceExpression fieldWithNameClash = new DereferenceExpression(LOCATION, STRUCT_COLUMN, "3");
    // When:
    final ColumnName result1 = generator.uniqueAliasFor(fieldWithNameClash);
    final ColumnName result2 = generator.uniqueAliasFor(fieldWithNameClash);
    // Then:
    assertThat(result1, is(ColumnName.of("3")));
    assertThat(result2, is(ColumnName.of("3_2")));
}
Also used : ColumnName(io.confluent.ksql.name.ColumnName) DereferenceExpression(io.confluent.ksql.execution.expression.tree.DereferenceExpression) Test(org.junit.Test)

Example 13 with DereferenceExpression

use of io.confluent.ksql.execution.expression.tree.DereferenceExpression in project ksql by confluentinc.

the class ExpressionFormatterTest method shouldFormatDereferenceExpression.

@Test
public void shouldFormatDereferenceExpression() {
    // Given:
    final DereferenceExpression expression = new DereferenceExpression(Optional.of(LOCATION), new StringLiteral("foo"), "name");
    // When:
    final String text = ExpressionFormatter.formatExpression(expression);
    // Then:
    assertThat(text, equalTo("'foo'->name"));
}
Also used : DereferenceExpression(io.confluent.ksql.execution.expression.tree.DereferenceExpression) StringLiteral(io.confluent.ksql.execution.expression.tree.StringLiteral) Test(org.junit.Test)

Example 14 with DereferenceExpression

use of io.confluent.ksql.execution.expression.tree.DereferenceExpression in project ksql by confluentinc.

the class InterpretedExpressionTest method shouldEvaluateStructDereference.

@Test
public void shouldEvaluateStructDereference() {
    // Given:
    final Expression expression1 = new DereferenceExpression(Optional.empty(), new CreateStructExpression(ImmutableList.of(new Field("A", new IntegerLiteral(10)), new Field("B", new StringLiteral("abc")))), "A");
    // When:
    InterpretedExpression interpreter1 = interpreter(expression1);
    // Then:
    assertThat(interpreter1.evaluate(ROW), is(10));
}
Also used : Field(io.confluent.ksql.execution.expression.tree.CreateStructExpression.Field) DereferenceExpression(io.confluent.ksql.execution.expression.tree.DereferenceExpression) StringLiteral(io.confluent.ksql.execution.expression.tree.StringLiteral) ArithmeticBinaryExpression(io.confluent.ksql.execution.expression.tree.ArithmeticBinaryExpression) LogicalBinaryExpression(io.confluent.ksql.execution.expression.tree.LogicalBinaryExpression) Expression(io.confluent.ksql.execution.expression.tree.Expression) CreateMapExpression(io.confluent.ksql.execution.expression.tree.CreateMapExpression) DereferenceExpression(io.confluent.ksql.execution.expression.tree.DereferenceExpression) ArithmeticUnaryExpression(io.confluent.ksql.execution.expression.tree.ArithmeticUnaryExpression) CreateArrayExpression(io.confluent.ksql.execution.expression.tree.CreateArrayExpression) CreateStructExpression(io.confluent.ksql.execution.expression.tree.CreateStructExpression) 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) CreateStructExpression(io.confluent.ksql.execution.expression.tree.CreateStructExpression) IntegerLiteral(io.confluent.ksql.execution.expression.tree.IntegerLiteral) Test(org.junit.Test)

Example 15 with DereferenceExpression

use of io.confluent.ksql.execution.expression.tree.DereferenceExpression in project ksql by confluentinc.

the class GroupByParamsV1FactoryTest method shouldSetKeyNameFromSingleGroupByFieldName.

@Test
public void shouldSetKeyNameFromSingleGroupByFieldName() {
    // Given:
    when(groupBy0.getExpression()).thenReturn(new DereferenceExpression(Optional.empty(), new UnqualifiedColumnReferenceExp(COL3), "someField"));
    // When:
    final LogicalSchema schema = GroupByParamsV1Factory.buildSchema(SOURCE_SCHEMA, ImmutableList.of(groupBy0));
    // Then:
    assertThat(schema, is(LogicalSchema.builder().keyColumn(ColumnName.of("someField"), SqlTypes.INTEGER).valueColumns(SOURCE_SCHEMA.value()).build()));
}
Also used : DereferenceExpression(io.confluent.ksql.execution.expression.tree.DereferenceExpression) LogicalSchema(io.confluent.ksql.schema.ksql.LogicalSchema) UnqualifiedColumnReferenceExp(io.confluent.ksql.execution.expression.tree.UnqualifiedColumnReferenceExp) 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