use of io.confluent.ksql.execution.expression.tree.IntegerLiteral in project ksql by confluentinc.
the class ExpressionTypeManagerTest method shouldFailIfWhenIsNotBoolean.
@Test
public void shouldFailIfWhenIsNotBoolean() {
// Given:
final Expression expression = new SearchedCaseExpression(ImmutableList.of(new WhenClause(new ArithmeticBinaryExpression(Operator.ADD, TestExpressions.COL0, new IntegerLiteral(10)), new StringLiteral("foo"))), Optional.empty());
// When:
final Exception e = assertThrows(KsqlException.class, () -> expressionTypeManager.getExpressionSqlType(expression));
// Then:
assertThat(e.getMessage(), containsString("WHEN operand type should be boolean." + System.lineSeparator() + "Type for '(COL0 + 10)' is BIGINT"));
}
use of io.confluent.ksql.execution.expression.tree.IntegerLiteral in project ksql by confluentinc.
the class ExpressionTypeManagerTest method shouldFailOnInconsistentWhenResultType.
@Test
public void shouldFailOnInconsistentWhenResultType() {
// Given:
final Expression expression = new SearchedCaseExpression(ImmutableList.of(new WhenClause(new ComparisonExpression(Type.EQUAL, TestExpressions.COL0, new IntegerLiteral(100)), new StringLiteral("one-hundred")), new WhenClause(new ComparisonExpression(Type.EQUAL, TestExpressions.COL0, new IntegerLiteral(10)), new IntegerLiteral(10))), Optional.empty());
// When:
final Exception e = assertThrows(KsqlException.class, () -> expressionTypeManager.getExpressionSqlType(expression));
// Then:
assertThat(e.getMessage(), containsString("Invalid Case expression. Type for all 'THEN' clauses should be the same." + System.lineSeparator() + "THEN expression 'WHEN (COL0 = 10) THEN 10' has type: INTEGER." + System.lineSeparator() + "Previous THEN expression(s) type: STRING."));
}
use of io.confluent.ksql.execution.expression.tree.IntegerLiteral in project ksql by confluentinc.
the class CoercionUtilTest method shouldNotCoerceStructWithDifferentExpression.
@Test
public void shouldNotCoerceStructWithDifferentExpression() {
// Given:
final ImmutableList<Expression> expressions = ImmutableList.of(new CreateStructExpression(ImmutableList.of(new Field("a", new IntegerLiteral(10)))), new CreateStructExpression(ImmutableList.of(new Field("a", STRING_EXPRESSION))));
// When:
final Exception e = assertThrows(KsqlException.class, () -> CoercionUtil.coerceUserList(expressions, typeManager));
// Then:
assertThat(e.getMessage(), startsWith("operator does not exist: STRUCT<`a` INTEGER> = STRUCT<`a` STRING> (STRUCT(a:=STR))"));
}
use of io.confluent.ksql.execution.expression.tree.IntegerLiteral in project ksql by confluentinc.
the class CoercionUtilTest method shouldCoerceToInts.
@Test
public void shouldCoerceToInts() {
// Given:
final ImmutableList<Expression> expressions = ImmutableList.of(new IntegerLiteral(10), new StringLiteral("\t -100 \t"), INT_EXPRESSION);
// When:
final Result result = CoercionUtil.coerceUserList(expressions, typeManager);
// Then:
assertThat(result.commonType(), is(Optional.of(SqlTypes.INTEGER)));
assertThat(result.expressions(), is(ImmutableList.of(new IntegerLiteral(10), new IntegerLiteral(-100), INT_EXPRESSION)));
}
use of io.confluent.ksql.execution.expression.tree.IntegerLiteral in project ksql by confluentinc.
the class CoercionUtilTest method shouldCoerceToBigInts.
@Test
public void shouldCoerceToBigInts() {
// Given:
final ImmutableList<Expression> expressions = ImmutableList.of(new IntegerLiteral(10), new LongLiteral(1234567890), new StringLiteral("\t -100 \t"), BIGINT_EXPRESSION, INT_EXPRESSION);
// When:
final Result result = CoercionUtil.coerceUserList(expressions, typeManager);
// Then:
assertThat(result.commonType(), is(Optional.of(SqlTypes.BIGINT)));
assertThat(result.expressions(), is(ImmutableList.of(new LongLiteral(10), new LongLiteral(1234567890), new LongLiteral(-100), BIGINT_EXPRESSION, cast(INT_EXPRESSION, SqlTypes.BIGINT))));
}
Aggregations