use of io.confluent.ksql.schema.ksql.LogicalSchema in project ksql by confluentinc.
the class ExpressionTypeManagerTest method shouldThrowGoodErrorMessageForSubscriptOnScalar.
@Test
public void shouldThrowGoodErrorMessageForSubscriptOnScalar() {
// Given:
final LogicalSchema schema = LogicalSchema.builder().keyColumn(SystemColumns.ROWKEY_NAME, SqlTypes.STRING).valueColumn(COL0, SqlTypes.INTEGER).build();
expressionTypeManager = new ExpressionTypeManager(schema, functionRegistry);
final Expression expression = new SubscriptExpression(Optional.empty(), TestExpressions.COL0, new StringLiteral("IN0"));
// When:
final UnsupportedOperationException e = assertThrows(UnsupportedOperationException.class, () -> expressionTypeManager.getExpressionSqlType(expression));
// Then:
assertThat(e.getMessage(), is("Subscript expression (COL0['IN0']) do not apply to INTEGER."));
}
use of io.confluent.ksql.schema.ksql.LogicalSchema in project ksql by confluentinc.
the class ExpressionTypeManagerTest method shouldThrowGoodErrorMessageForSubscriptOnStruct.
@Test
public void shouldThrowGoodErrorMessageForSubscriptOnStruct() {
// Given:
final SqlStruct structType = SqlTypes.struct().field("IN0", SqlTypes.INTEGER).build();
final LogicalSchema schema = LogicalSchema.builder().keyColumn(SystemColumns.ROWKEY_NAME, SqlTypes.STRING).valueColumn(COL0, structType).build();
expressionTypeManager = new ExpressionTypeManager(schema, functionRegistry);
final Expression expression = new SubscriptExpression(Optional.empty(), TestExpressions.COL0, new StringLiteral("IN0"));
// When:
final UnsupportedOperationException e = assertThrows(UnsupportedOperationException.class, () -> expressionTypeManager.getExpressionSqlType(expression));
// Then:
assertThat(e.getMessage(), is("Subscript expression (COL0['IN0']) do not apply to STRUCT<`IN0` INTEGER>. " + "Use the dereference operator for STRUCTS: COL0->'IN0'"));
}
use of io.confluent.ksql.schema.ksql.LogicalSchema 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));
}
use of io.confluent.ksql.schema.ksql.LogicalSchema in project ksql by confluentinc.
the class SelectionTest method shouldBuildCorrectSchemaWithNoKeyColumnNames.
@Test
public void shouldBuildCorrectSchemaWithNoKeyColumnNames() {
// Given:
selection = Selection.of(SCHEMA, ImmutableList.of(), SELECT_EXPRESSIONS, ksqlConfig, functionRegistry);
// When:
final LogicalSchema resultSchema = selection.getSchema();
// Then:
assertThat(resultSchema, equalTo(LogicalSchema.builder().keyColumn(ColumnName.of("K0"), SqlTypes.BIGINT).valueColumn(ColumnName.of("FOO"), SqlTypes.STRING).valueColumn(ColumnName.of("BAR"), SqlTypes.BIGINT).build()));
}
use of io.confluent.ksql.schema.ksql.LogicalSchema in project ksql by confluentinc.
the class TableElementsTest method shouldBuildLogicalSchemaWithWithKey.
@Test
public void shouldBuildLogicalSchemaWithWithKey() {
// Given:
final TableElements tableElements = TableElements.of(tableElement("v0", INT_TYPE), tableElement("k0", INT_TYPE, KEY_CONSTRAINT));
// When:
final LogicalSchema schema = tableElements.toLogicalSchema();
// Then:
assertThat(schema, is(LogicalSchema.builder().valueColumn(ColumnName.of("v0"), SqlTypes.INTEGER).keyColumn(ColumnName.of("k0"), SqlTypes.INTEGER).build()));
}
Aggregations