use of io.confluent.ksql.execution.expression.tree.NullLiteral in project ksql by confluentinc.
the class ExpressionTypeManagerTest method shouldEvaluateTypeForCreateArrayExpressionWithNull.
@Test
public void shouldEvaluateTypeForCreateArrayExpressionWithNull() {
// Given:
Expression expression = new CreateArrayExpression(ImmutableList.of(new UnqualifiedColumnReferenceExp(COL0), new NullLiteral()));
// When:
final SqlType type = expressionTypeManager.getExpressionSqlType(expression);
// Then:
assertThat(type, is(SqlTypes.array(SqlTypes.BIGINT)));
}
use of io.confluent.ksql.execution.expression.tree.NullLiteral in project ksql by confluentinc.
the class CoercionUtilTest method shouldHandleSomeNulls.
@Test
public void shouldHandleSomeNulls() {
// Given:
final ImmutableList<Expression> expressions = ImmutableList.of(new NullLiteral(), new IntegerLiteral(10), new NullLiteral(), new LongLiteral(20L), new NullLiteral());
// When:
final Result result = CoercionUtil.coerceUserList(expressions, typeManager);
// Then:
assertThat(result.commonType(), is(Optional.of(SqlTypes.BIGINT)));
assertThat(result.expressions(), is(ImmutableList.of(new NullLiteral(), new LongLiteral(10), new NullLiteral(), new LongLiteral(20L), new NullLiteral())));
}
use of io.confluent.ksql.execution.expression.tree.NullLiteral in project ksql by confluentinc.
the class InListEvaluator method preprocess.
/**
* Preprocess the list of possible expression, ensuring compatible types, performing literal
* coercion and removing null literals (which can never match).
*
* @param predicate The predicate to process
* @param typeManager the type manager for the predicate
* @param lambdaTypeMapping mapping of lambda variables to type
* @return {@code predicate} after processing.
*/
public static InPredicate preprocess(final InPredicate predicate, final ExpressionTypeManager typeManager, final Map<String, SqlType> lambdaTypeMapping) {
final List<Expression> nonNull = ImmutableList.<Expression>builder().add(predicate.getValue()).addAll(predicate.getValueList().getValues().stream().filter(e -> !(e instanceof NullLiteral)).collect(Collectors.toList())).build();
final List<Expression> coerced = CoercionUtil.coerceUserList(nonNull, typeManager, lambdaTypeMapping).expressions();
return new InPredicate(predicate.getLocation(), coerced.get(0), new InListExpression(predicate.getValueList().getLocation(), coerced.subList(1, coerced.size())));
}
use of io.confluent.ksql.execution.expression.tree.NullLiteral in project ksql by confluentinc.
the class InsertValuesExecutorTest method shouldThrowOnInsertKeyHeaders.
@Test
public void shouldThrowOnInsertKeyHeaders() {
// Given:
givenSourceStreamWithSchema(SCHEMA_WITH_KEY_HEADERS, SerdeFeatures.of(), SerdeFeatures.of());
final ConfiguredStatement<InsertValues> statement = givenInsertValues(allColumnNames(SCHEMA_WITH_KEY_HEADERS), ImmutableList.of(new StringLiteral("key"), new StringLiteral("str"), new LongLiteral(2L), new NullLiteral(), new NullLiteral()));
// When:
final Exception e = assertThrows(KsqlException.class, () -> executor.execute(statement, mock(SessionProperties.class), engine, serviceContext));
// Then:
assertThat(e.getMessage(), is("Cannot insert into HEADER columns: HEAD0, HEAD1"));
}
use of io.confluent.ksql.execution.expression.tree.NullLiteral in project ksql by confluentinc.
the class InsertValuesExecutorTest method shouldThrowOnInsertHeaders.
@Test
public void shouldThrowOnInsertHeaders() {
// Given:
givenSourceStreamWithSchema(SCHEMA_WITH_HEADERS, SerdeFeatures.of(), SerdeFeatures.of());
final ConfiguredStatement<InsertValues> statement = givenInsertValues(allColumnNames(SCHEMA_WITH_HEADERS), ImmutableList.of(new StringLiteral("key"), new StringLiteral("str"), new LongLiteral(2L), new NullLiteral()));
// When:
final Exception e = assertThrows(KsqlException.class, () -> executor.execute(statement, mock(SessionProperties.class), engine, serviceContext));
// Then:
assertThat(e.getMessage(), is("Cannot insert into HEADER columns: HEAD0"));
}
Aggregations