use of io.confluent.ksql.execution.expression.tree.IntegerLiteral in project ksql by confluentinc.
the class CoercionUtilTest method shouldCoerceMapOfCompatibleLiterals.
@Test
public void shouldCoerceMapOfCompatibleLiterals() {
// Given:
final ImmutableList<Expression> expressions = ImmutableList.of(new CreateMapExpression(ImmutableMap.of(new IntegerLiteral(10), new IntegerLiteral(289476))), new CreateMapExpression(ImmutableMap.of(new StringLiteral("123456789000"), new StringLiteral("\t -100 \t"))));
// When:
final Result result = CoercionUtil.coerceUserList(expressions, typeManager);
// Then:
assertThat(result.commonType(), is(Optional.of(SqlTypes.map(SqlTypes.BIGINT, SqlTypes.INTEGER))));
assertThat(result.expressions(), is(ImmutableList.of(cast(new CreateMapExpression(ImmutableMap.of(new IntegerLiteral(10), new IntegerLiteral(289476))), SqlTypes.map(SqlTypes.BIGINT, SqlTypes.INTEGER)), cast(new CreateMapExpression(ImmutableMap.of(new StringLiteral("123456789000"), new StringLiteral("\t -100 \t"))), SqlTypes.map(SqlTypes.BIGINT, SqlTypes.INTEGER)))));
}
use of io.confluent.ksql.execution.expression.tree.IntegerLiteral in project ksql by confluentinc.
the class CoercionUtilTest method shouldThrowOnIncompatible.
@Test
public void shouldThrowOnIncompatible() {
// Given:
final ImmutableList<Expression> expressions = ImmutableList.of(new BooleanLiteral(true), // <-- can not be coerced to boolean.
new IntegerLiteral(10));
// When:
final Exception e = assertThrows(KsqlException.class, () -> CoercionUtil.coerceUserList(expressions, typeManager));
// Then:
assertThat(e.getMessage(), is("operator does not exist: BOOLEAN = INTEGER (10)" + System.lineSeparator() + "Hint: You might need to add explicit type casts."));
}
use of io.confluent.ksql.execution.expression.tree.IntegerLiteral in project ksql by confluentinc.
the class CoercionUtilTest method shouldNotCoerceMapOfIncompatibleValueLiterals.
@Test
public void shouldNotCoerceMapOfIncompatibleValueLiterals() {
// Given:
final ImmutableList<Expression> expressions = ImmutableList.of(new CreateMapExpression(ImmutableMap.of(new IntegerLiteral(10), new IntegerLiteral(289476))), new CreateMapExpression(ImmutableMap.of(new StringLiteral("123456789000"), new BooleanLiteral(false))));
// When:
final Exception e = assertThrows(KsqlException.class, () -> CoercionUtil.coerceUserList(expressions, typeManager));
// Then:
assertThat(e.getMessage(), startsWith("operator does not exist: MAP<INTEGER, INTEGER> = MAP<STRING, BOOLEAN> (MAP('123456789000':=false))"));
}
use of io.confluent.ksql.execution.expression.tree.IntegerLiteral in project ksql by confluentinc.
the class ExpressionTypeManagerTest method shouldFailIfDefaultHasDifferentTypeToWhen.
@Test
public void shouldFailIfDefaultHasDifferentTypeToWhen() {
// Given:
final Expression expression = new SearchedCaseExpression(ImmutableList.of(new WhenClause(new ComparisonExpression(Type.EQUAL, TestExpressions.COL0, new IntegerLiteral(10)), new StringLiteral("good"))), Optional.of(new BooleanLiteral("true")));
// When:
final Exception e = assertThrows(KsqlException.class, () -> expressionTypeManager.getExpressionSqlType(expression));
// Then:
assertThat(e.getMessage(), containsString("Invalid Case expression. Type for the default clause should be the same as for 'THEN' clauses." + System.lineSeparator() + "THEN type: STRING." + System.lineSeparator() + "DEFAULT type: BOOLEAN."));
}
use of io.confluent.ksql.execution.expression.tree.IntegerLiteral in project ksql by confluentinc.
the class CreateSourcePropertiesTest method shouldSetPartitions.
@Test
public void shouldSetPartitions() {
// When:
final CreateSourceProperties properties = CreateSourceProperties.from(ImmutableMap.<String, Literal>builder().putAll(MINIMUM_VALID_PROPS).put(CommonCreateConfigs.SOURCE_NUMBER_OF_PARTITIONS, new IntegerLiteral(2)).build());
// Then:
assertThat(properties.getPartitions(), is(Optional.of(2)));
}
Aggregations