use of io.confluent.ksql.execution.expression.tree.DereferenceExpression in project ksql by confluentinc.
the class ExpressionTreeRewriterTest method shouldRewriteDereferenceExpression.
@Test
public void shouldRewriteDereferenceExpression() {
// Given:
final DereferenceExpression parsed = parseExpression("col0->foo");
when(processor.apply(parsed.getBase(), context)).thenReturn(expr1);
// When:
final Expression rewritten = expressionRewriter.rewrite(parsed, context);
// Then:
assertThat(rewritten, equalTo(new DereferenceExpression(parsed.getLocation(), expr1, parsed.getFieldName())));
}
use of io.confluent.ksql.execution.expression.tree.DereferenceExpression in project ksql by confluentinc.
the class PartitionByParamsFactoryTest method shouldBuildResultSchemaWhenPartitioningByStructField.
@Test
public void shouldBuildResultSchemaWhenPartitioningByStructField() {
// Given:
final List<Expression> partitionBy = ImmutableList.of(new DereferenceExpression(Optional.empty(), new UnqualifiedColumnReferenceExp(COL3), "someField"));
// When:
final LogicalSchema resultSchema = PartitionByParamsFactory.buildSchema(SCHEMA, partitionBy, functionRegistry);
// Then:
assertThat(resultSchema, is(LogicalSchema.builder().keyColumn(ColumnName.of("someField"), SqlTypes.BIGINT).valueColumn(COL1, SqlTypes.INTEGER).valueColumn(COL2, SqlTypes.INTEGER).valueColumn(COL3, COL3_TYPE).valueColumn(SystemColumns.ROWTIME_NAME, SqlTypes.BIGINT).valueColumn(COL0, SqlTypes.STRING).valueColumn(ColumnName.of("someField"), SqlTypes.BIGINT).build()));
}
use of io.confluent.ksql.execution.expression.tree.DereferenceExpression in project ksql by confluentinc.
the class GroupByParamsFactoryTest method shouldSetKeyNameFromFieldName.
@Test
public void shouldSetKeyNameFromFieldName() {
// Given:
when(groupBy0.getExpression()).thenReturn(new DereferenceExpression(Optional.empty(), new UnqualifiedColumnReferenceExp(COL3), "someField"));
// When:
final LogicalSchema schema = GroupByParamsFactory.buildSchema(SOURCE_SCHEMA, ImmutableList.of(groupBy0, groupBy1));
// Then:
assertThat(schema, is(LogicalSchema.builder().keyColumn(ColumnName.of("someField"), SqlTypes.INTEGER).keyColumn(ColumnName.of("K1"), SqlTypes.INTEGER).valueColumns(SOURCE_SCHEMA.value()).build()));
}
use of io.confluent.ksql.execution.expression.tree.DereferenceExpression in project ksql by confluentinc.
the class ExpressionTypeManagerTest method shouldFailIfThereIsInvalidFieldNameInStructCall.
@Test
public void shouldFailIfThereIsInvalidFieldNameInStructCall() {
// Given:
final Expression expression = new DereferenceExpression(Optional.empty(), new UnqualifiedColumnReferenceExp(ColumnName.of("COL6")), "ZIP");
// When:
final Exception e = assertThrows(KsqlException.class, () -> expressionTypeManager.getExpressionSqlType(expression));
// Then:
assertThat(e.getMessage(), containsString("Could not find field 'ZIP' in 'COL6'."));
}
use of io.confluent.ksql.execution.expression.tree.DereferenceExpression in project ksql by confluentinc.
the class ExpressionTypeManagerTest method shouldEvaluateTypeForArrayReferenceInStruct.
@Test
public void shouldEvaluateTypeForArrayReferenceInStruct() {
// Given:
final SqlStruct inner = SqlTypes.struct().field("IN0", SqlTypes.array(SqlTypes.INTEGER)).build();
final LogicalSchema schema = LogicalSchema.builder().keyColumn(SystemColumns.ROWKEY_NAME, SqlTypes.STRING).valueColumn(COL0, inner).build();
expressionTypeManager = new ExpressionTypeManager(schema, functionRegistry);
final Expression structRef = new DereferenceExpression(Optional.empty(), new UnqualifiedColumnReferenceExp(COL0), "IN0");
final Expression expression = new SubscriptExpression(structRef, new IntegerLiteral(1));
// When:
final SqlType result = expressionTypeManager.getExpressionSqlType(expression);
// Then:
assertThat(result, is(SqlTypes.INTEGER));
}
Aggregations