Search in sources :

Example 81 with LogicalSchema

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

Example 82 with LogicalSchema

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'"));
}
Also used : SqlStruct(io.confluent.ksql.schema.ksql.types.SqlStruct) StringLiteral(io.confluent.ksql.execution.expression.tree.StringLiteral) 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) Test(org.junit.Test)

Example 83 with LogicalSchema

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));
}
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) UnqualifiedColumnReferenceExp(io.confluent.ksql.execution.expression.tree.UnqualifiedColumnReferenceExp) IntegerLiteral(io.confluent.ksql.execution.expression.tree.IntegerLiteral) Test(org.junit.Test)

Example 84 with LogicalSchema

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()));
}
Also used : LogicalSchema(io.confluent.ksql.schema.ksql.LogicalSchema) Test(org.junit.Test)

Example 85 with LogicalSchema

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()));
}
Also used : LogicalSchema(io.confluent.ksql.schema.ksql.LogicalSchema) Test(org.junit.Test)

Aggregations

LogicalSchema (io.confluent.ksql.schema.ksql.LogicalSchema)223 Test (org.junit.Test)152 Expression (io.confluent.ksql.execution.expression.tree.Expression)44 ColumnName (io.confluent.ksql.name.ColumnName)31 GenericRow (io.confluent.ksql.GenericRow)30 UnqualifiedColumnReferenceExp (io.confluent.ksql.execution.expression.tree.UnqualifiedColumnReferenceExp)29 KsqlException (io.confluent.ksql.util.KsqlException)27 GenericKey (io.confluent.ksql.GenericKey)20 StringLiteral (io.confluent.ksql.execution.expression.tree.StringLiteral)19 List (java.util.List)16 TimestampColumn (io.confluent.ksql.execution.timestamp.TimestampColumn)14 SqlType (io.confluent.ksql.schema.ksql.types.SqlType)14 Optional (java.util.Optional)14 Collectors (java.util.stream.Collectors)14 QueryContext (io.confluent.ksql.execution.context.QueryContext)13 ArithmeticBinaryExpression (io.confluent.ksql.execution.expression.tree.ArithmeticBinaryExpression)12 DereferenceExpression (io.confluent.ksql.execution.expression.tree.DereferenceExpression)12 SelectExpression (io.confluent.ksql.execution.plan.SelectExpression)12 Column (io.confluent.ksql.schema.ksql.Column)12 ComparisonExpression (io.confluent.ksql.execution.expression.tree.ComparisonExpression)11