Search in sources :

Example 11 with NullLiteral

use of io.confluent.ksql.execution.expression.tree.NullLiteral in project ksql by confluentinc.

the class InsertValuesExecutorTest method shouldThrowOnInsertAllWithHeaders.

@Test
public void shouldThrowOnInsertAllWithHeaders() {
    // Given:
    givenSourceStreamWithSchema(SCHEMA_WITH_HEADERS, SerdeFeatures.of(), SerdeFeatures.of());
    final ConfiguredStatement<InsertValues> statement = givenInsertValues(ImmutableList.of(), 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)

Example 12 with NullLiteral

use of io.confluent.ksql.execution.expression.tree.NullLiteral in project ksql by confluentinc.

the class CoercionUtilTest method shouldDriveCoercionFromFirstNonNullExpression.

@Test
public void shouldDriveCoercionFromFirstNonNullExpression() {
    // Given:
    final ImmutableList<Expression> stringFirst = ImmutableList.of(new NullLiteral(), new StringLiteral("false"), new BooleanLiteral(true));
    final ImmutableList<Expression> boolFirst = ImmutableList.of(new NullLiteral(), new BooleanLiteral(true), new StringLiteral("false"));
    // When:
    final Result stringResult = CoercionUtil.coerceUserList(stringFirst, typeManager);
    final Result boolResult = CoercionUtil.coerceUserList(boolFirst, typeManager);
    // Then:
    assertThat(stringResult.commonType(), is(Optional.of(SqlTypes.STRING)));
    assertThat(stringResult.expressions(), is(ImmutableList.of(new NullLiteral(), new StringLiteral("false"), new StringLiteral("true"))));
    assertThat(boolResult.commonType(), is(Optional.of(SqlTypes.BOOLEAN)));
    assertThat(boolResult.expressions(), is(ImmutableList.of(new NullLiteral(), new BooleanLiteral(true), new BooleanLiteral(false))));
}
Also used : StringLiteral(io.confluent.ksql.execution.expression.tree.StringLiteral) 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) BooleanLiteral(io.confluent.ksql.execution.expression.tree.BooleanLiteral) NullLiteral(io.confluent.ksql.execution.expression.tree.NullLiteral) Result(io.confluent.ksql.execution.util.CoercionUtil.Result) Test(org.junit.Test)

Example 13 with NullLiteral

use of io.confluent.ksql.execution.expression.tree.NullLiteral in project ksql by confluentinc.

the class CoercionUtilTest method shouldHandleOnlyNulls.

@Test
public void shouldHandleOnlyNulls() {
    // Given:
    final ImmutableList<Expression> expressions = ImmutableList.of(new NullLiteral(), new NullLiteral());
    // When:
    final Result result = CoercionUtil.coerceUserList(expressions, typeManager);
    // Then:
    assertThat(result.commonType(), is(Optional.empty()));
    assertThat(result.expressions(), is(ImmutableList.of(new NullLiteral(), 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) NullLiteral(io.confluent.ksql.execution.expression.tree.NullLiteral) Result(io.confluent.ksql.execution.util.CoercionUtil.Result) Test(org.junit.Test)

Example 14 with NullLiteral

use of io.confluent.ksql.execution.expression.tree.NullLiteral in project ksql by confluentinc.

the class PartitionByParamsFactoryTest method shouldNotChangeValueIfPartitioningByNull.

@Test
public void shouldNotChangeValueIfPartitioningByNull() {
    // Given:
    final Mapper<GenericKey> mapper = partitionBy(ImmutableList.of(new NullLiteral())).getMapper();
    final ImmutableList<Object> originals = ImmutableList.copyOf(value.values());
    // When:
    final KeyValue<GenericKey, GenericRow> result = mapper.apply(key, value);
    // Then:
    assertThat(result.value, is(GenericRow.fromList(originals)));
}
Also used : GenericRow(io.confluent.ksql.GenericRow) GenericKey(io.confluent.ksql.GenericKey) NullLiteral(io.confluent.ksql.execution.expression.tree.NullLiteral) Test(org.junit.Test)

Example 15 with NullLiteral

use of io.confluent.ksql.execution.expression.tree.NullLiteral in project ksql by confluentinc.

the class PartitionByParamsFactoryTest method shouldThrowIfPartitioningByMultipleExpressionsIncludingNull.

@Test
public void shouldThrowIfPartitioningByMultipleExpressionsIncludingNull() {
    // Given:
    final List<Expression> partitionBy = ImmutableList.of(new UnqualifiedColumnReferenceExp(COL1), new NullLiteral());
    // Expect / When:
    final Exception e = assertThrows(KsqlException.class, () -> PartitionByParamsFactory.buildSchema(SCHEMA, partitionBy, functionRegistry));
    // Then:
    assertThat(e.getMessage(), containsString("Cannot PARTITION BY multiple columns including NULL"));
}
Also used : ArithmeticBinaryExpression(io.confluent.ksql.execution.expression.tree.ArithmeticBinaryExpression) Expression(io.confluent.ksql.execution.expression.tree.Expression) DereferenceExpression(io.confluent.ksql.execution.expression.tree.DereferenceExpression) ArithmeticUnaryExpression(io.confluent.ksql.execution.expression.tree.ArithmeticUnaryExpression) UnqualifiedColumnReferenceExp(io.confluent.ksql.execution.expression.tree.UnqualifiedColumnReferenceExp) NullLiteral(io.confluent.ksql.execution.expression.tree.NullLiteral) KsqlException(io.confluent.ksql.util.KsqlException) 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