Search in sources :

Example 6 with NullLiteral

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)));
}
Also used : CreateArrayExpression(io.confluent.ksql.execution.expression.tree.CreateArrayExpression) 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) SqlType(io.confluent.ksql.schema.ksql.types.SqlType) UnqualifiedColumnReferenceExp(io.confluent.ksql.execution.expression.tree.UnqualifiedColumnReferenceExp) NullLiteral(io.confluent.ksql.execution.expression.tree.NullLiteral) Test(org.junit.Test)

Example 7 with NullLiteral

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())));
}
Also used : CreateArrayExpression(io.confluent.ksql.execution.expression.tree.CreateArrayExpression) CreateStructExpression(io.confluent.ksql.execution.expression.tree.CreateStructExpression) Expression(io.confluent.ksql.execution.expression.tree.Expression) CreateMapExpression(io.confluent.ksql.execution.expression.tree.CreateMapExpression) LongLiteral(io.confluent.ksql.execution.expression.tree.LongLiteral) NullLiteral(io.confluent.ksql.execution.expression.tree.NullLiteral) IntegerLiteral(io.confluent.ksql.execution.expression.tree.IntegerLiteral) Result(io.confluent.ksql.execution.util.CoercionUtil.Result) Test(org.junit.Test)

Example 8 with 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())));
}
Also used : Iterator(java.util.Iterator) ImmutableMap(com.google.common.collect.ImmutableMap) Expression(io.confluent.ksql.execution.expression.tree.Expression) Field(org.apache.kafka.connect.data.Field) SqlBooleans(io.confluent.ksql.schema.ksql.SqlBooleans) BiFunction(java.util.function.BiFunction) InPredicate(io.confluent.ksql.execution.expression.tree.InPredicate) Function(java.util.function.Function) Collectors(java.util.stream.Collectors) Schema(org.apache.kafka.connect.data.Schema) BigDecimal(java.math.BigDecimal) List(java.util.List) ImmutableList(com.google.common.collect.ImmutableList) InListExpression(io.confluent.ksql.execution.expression.tree.InListExpression) Map(java.util.Map) Struct(org.apache.kafka.connect.data.Struct) CoercionUtil(io.confluent.ksql.execution.util.CoercionUtil) ExpressionTypeManager(io.confluent.ksql.execution.util.ExpressionTypeManager) Entry(java.util.Map.Entry) NullLiteral(io.confluent.ksql.execution.expression.tree.NullLiteral) Optional(java.util.Optional) SqlType(io.confluent.ksql.schema.ksql.types.SqlType) RoundingMode(java.math.RoundingMode) Expression(io.confluent.ksql.execution.expression.tree.Expression) InListExpression(io.confluent.ksql.execution.expression.tree.InListExpression) InListExpression(io.confluent.ksql.execution.expression.tree.InListExpression) InPredicate(io.confluent.ksql.execution.expression.tree.InPredicate) NullLiteral(io.confluent.ksql.execution.expression.tree.NullLiteral)

Example 9 with NullLiteral

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"));
}
Also used : StringLiteral(io.confluent.ksql.execution.expression.tree.StringLiteral) LongLiteral(io.confluent.ksql.execution.expression.tree.LongLiteral) InsertValues(io.confluent.ksql.parser.tree.InsertValues) NullLiteral(io.confluent.ksql.execution.expression.tree.NullLiteral) SerializationException(org.apache.kafka.common.errors.SerializationException) RestClientException(io.confluent.kafka.schemaregistry.client.rest.exceptions.RestClientException) KsqlException(io.confluent.ksql.util.KsqlException) ExecutionException(java.util.concurrent.ExecutionException) TopicAuthorizationException(org.apache.kafka.common.errors.TopicAuthorizationException) Test(org.junit.Test)

Example 10 with NullLiteral

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"));
}
Also used : StringLiteral(io.confluent.ksql.execution.expression.tree.StringLiteral) LongLiteral(io.confluent.ksql.execution.expression.tree.LongLiteral) InsertValues(io.confluent.ksql.parser.tree.InsertValues) NullLiteral(io.confluent.ksql.execution.expression.tree.NullLiteral) SerializationException(org.apache.kafka.common.errors.SerializationException) RestClientException(io.confluent.kafka.schemaregistry.client.rest.exceptions.RestClientException) KsqlException(io.confluent.ksql.util.KsqlException) ExecutionException(java.util.concurrent.ExecutionException) TopicAuthorizationException(org.apache.kafka.common.errors.TopicAuthorizationException) Test(org.junit.Test)

Aggregations

NullLiteral (io.confluent.ksql.execution.expression.tree.NullLiteral)18 Test (org.junit.Test)17 Expression (io.confluent.ksql.execution.expression.tree.Expression)13 CreateStructExpression (io.confluent.ksql.execution.expression.tree.CreateStructExpression)9 CreateArrayExpression (io.confluent.ksql.execution.expression.tree.CreateArrayExpression)8 CreateMapExpression (io.confluent.ksql.execution.expression.tree.CreateMapExpression)8 ArithmeticBinaryExpression (io.confluent.ksql.execution.expression.tree.ArithmeticBinaryExpression)7 DereferenceExpression (io.confluent.ksql.execution.expression.tree.DereferenceExpression)7 InListExpression (io.confluent.ksql.execution.expression.tree.InListExpression)7 KsqlException (io.confluent.ksql.util.KsqlException)7 ComparisonExpression (io.confluent.ksql.execution.expression.tree.ComparisonExpression)6 ArithmeticUnaryExpression (io.confluent.ksql.execution.expression.tree.ArithmeticUnaryExpression)5 SearchedCaseExpression (io.confluent.ksql.execution.expression.tree.SearchedCaseExpression)5 StringLiteral (io.confluent.ksql.execution.expression.tree.StringLiteral)5 SubscriptExpression (io.confluent.ksql.execution.expression.tree.SubscriptExpression)5 LongLiteral (io.confluent.ksql.execution.expression.tree.LongLiteral)4 RestClientException (io.confluent.kafka.schemaregistry.client.rest.exceptions.RestClientException)3 LogicalBinaryExpression (io.confluent.ksql.execution.expression.tree.LogicalBinaryExpression)3 NotExpression (io.confluent.ksql.execution.expression.tree.NotExpression)3 SimpleCaseExpression (io.confluent.ksql.execution.expression.tree.SimpleCaseExpression)3