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