use of io.confluent.ksql.execution.expression.tree.StringLiteral 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.execution.expression.tree.StringLiteral 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.execution.expression.tree.StringLiteral in project ksql by confluentinc.
the class ExpressionTypeManagerTest method shouldGetCorrectSchemaForSearchedCase.
@Test
public void shouldGetCorrectSchemaForSearchedCase() {
// Given:
final Expression expression = new SearchedCaseExpression(ImmutableList.of(new WhenClause(new ComparisonExpression(Type.LESS_THAN, COL7, new IntegerLiteral(10)), new StringLiteral("small")), new WhenClause(new ComparisonExpression(Type.LESS_THAN, COL7, new IntegerLiteral(100)), new StringLiteral("medium"))), Optional.of(new StringLiteral("large")));
// When:
final SqlType result = expressionTypeManager.getExpressionSqlType(expression);
// Then:
assertThat(result, is(SqlTypes.STRING));
}
use of io.confluent.ksql.execution.expression.tree.StringLiteral in project ksql by confluentinc.
the class ExpressionTypeManagerTest method shouldEvaluateBooleanSchemaForInExpression.
@Test
public void shouldEvaluateBooleanSchemaForInExpression() {
final Expression expression = new InPredicate(TestExpressions.COL0, new InListExpression(ImmutableList.of(new StringLiteral("key1"))));
final SqlType exprType0 = expressionTypeManager.getExpressionSqlType(expression);
assertThat(exprType0, is(SqlTypes.BOOLEAN));
}
use of io.confluent.ksql.execution.expression.tree.StringLiteral in project ksql by confluentinc.
the class ExpressionTypeManagerTest method shouldThrowOnMapOfNullValues.
@Test
public void shouldThrowOnMapOfNullValues() {
// Given:
Expression expression = new CreateMapExpression(ImmutableMap.of(new StringLiteral("foo"), new NullLiteral()));
// When:
final Exception e = assertThrows(KsqlException.class, () -> expressionTypeManager.getExpressionSqlType(expression));
// Then:
assertThat(e.getMessage(), containsString("Cannot construct a map with all NULL values"));
}
Aggregations