Search in sources :

Example 26 with LongLiteral

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

the class InsertValuesExecutorTest method shouldThrowWhenInsertingValuesOnSourceStream.

@Test
public void shouldThrowWhenInsertingValuesOnSourceStream() {
    // Given:
    givenDataSourceWithSchema("source_stream_1", SCHEMA, SerdeFeatures.of(), SerdeFeatures.of(), false, true);
    final KsqlConfig ksqlConfig = new KsqlConfig(ImmutableMap.of());
    final ConfiguredStatement<InsertValues> statement = ConfiguredStatement.of(PreparedStatement.of("", new InsertValues(SourceName.of("TOPIC"), allAndPseudoColumnNames(SCHEMA), ImmutableList.of(new LongLiteral(1L), new StringLiteral("str"), new StringLiteral("str"), new LongLiteral(2L)))), SessionConfig.of(ksqlConfig, ImmutableMap.of()));
    // When:
    final Exception e = assertThrows(KsqlException.class, () -> executor.execute(statement, mock(SessionProperties.class), engine, serviceContext));
    // Then:
    assertThat(e.getMessage(), containsString("Cannot insert values into read-only stream: TOPIC"));
}
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) KsqlConfig(io.confluent.ksql.util.KsqlConfig) 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 27 with LongLiteral

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

the class InsertValuesExecutorTest method shouldThrowOnTablesWithKeyFieldAndNullKeyFieldValueProvided.

@Test
public void shouldThrowOnTablesWithKeyFieldAndNullKeyFieldValueProvided() {
    // Given:
    givenSourceTableWithSchema(SerdeFeatures.of(), SerdeFeatures.of());
    final ConfiguredStatement<InsertValues> statement = givenInsertValues(ImmutableList.of(COL1), ImmutableList.of(new LongLiteral(2L)));
    // When:
    final Exception e = assertThrows(KsqlException.class, () -> executor.execute(statement, mock(SessionProperties.class), engine, serviceContext));
    // Then:
    assertThat(e.getMessage(), containsString("Failed to insert values into 'TOPIC'. Value for primary key column(s) k0 is required for tables"));
}
Also used : LongLiteral(io.confluent.ksql.execution.expression.tree.LongLiteral) InsertValues(io.confluent.ksql.parser.tree.InsertValues) 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 28 with LongLiteral

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

the class InsertValuesExecutorTest method shouldThrowWhenInsertValuesOnProcessingLogTopic.

@Test
public void shouldThrowWhenInsertValuesOnProcessingLogTopic() {
    // Given
    givenDataSourceWithSchema("default_ksql_processing_log", SCHEMA, SerdeFeatures.of(), SerdeFeatures.of(), false, false);
    final KsqlConfig ksqlConfig = new KsqlConfig(ImmutableMap.of());
    final ConfiguredStatement<InsertValues> statement = ConfiguredStatement.of(PreparedStatement.of("", new InsertValues(SourceName.of("TOPIC"), allAndPseudoColumnNames(SCHEMA), ImmutableList.of(new LongLiteral(1L), new StringLiteral("str"), new StringLiteral("str"), new LongLiteral(2L)))), SessionConfig.of(ksqlConfig, ImmutableMap.of()));
    // When:
    final Exception e = assertThrows(KsqlException.class, () -> executor.execute(statement, mock(SessionProperties.class), engine, serviceContext));
    // Then:
    assertThat(e.getMessage(), containsString("Cannot insert values into read-only topic: default_ksql_processing_log"));
}
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) KsqlConfig(io.confluent.ksql.util.KsqlConfig) 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 29 with LongLiteral

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

the class InsertValuesExecutorTest method shouldThrowOnSerializingValueError.

@Test
public void shouldThrowOnSerializingValueError() {
    // Given:
    final ConfiguredStatement<InsertValues> statement = givenInsertValues(allAndPseudoColumnNames(SCHEMA), ImmutableList.of(new LongLiteral(1L), new StringLiteral("str"), new StringLiteral("str"), new LongLiteral(2L)));
    when(valueSerializer.serialize(any(), any())).thenThrow(new SerializationException("Jibberish!"));
    // When:
    final Exception e = assertThrows(KsqlException.class, () -> executor.execute(statement, mock(SessionProperties.class), engine, serviceContext));
    // Then:
    assertThat(e.getCause(), (hasMessage(containsString("Could not serialize value"))));
}
Also used : SerializationException(org.apache.kafka.common.errors.SerializationException) StringLiteral(io.confluent.ksql.execution.expression.tree.StringLiteral) LongLiteral(io.confluent.ksql.execution.expression.tree.LongLiteral) InsertValues(io.confluent.ksql.parser.tree.InsertValues) 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 30 with LongLiteral

use of io.confluent.ksql.execution.expression.tree.LongLiteral 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))));
}
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) LongLiteral(io.confluent.ksql.execution.expression.tree.LongLiteral) IntegerLiteral(io.confluent.ksql.execution.expression.tree.IntegerLiteral) Result(io.confluent.ksql.execution.util.CoercionUtil.Result) Test(org.junit.Test)

Aggregations

LongLiteral (io.confluent.ksql.execution.expression.tree.LongLiteral)53 Test (org.junit.Test)49 StringLiteral (io.confluent.ksql.execution.expression.tree.StringLiteral)35 KsqlException (io.confluent.ksql.util.KsqlException)21 InsertValues (io.confluent.ksql.parser.tree.InsertValues)20 RestClientException (io.confluent.kafka.schemaregistry.client.rest.exceptions.RestClientException)17 ExecutionException (java.util.concurrent.ExecutionException)17 SerializationException (org.apache.kafka.common.errors.SerializationException)17 TopicAuthorizationException (org.apache.kafka.common.errors.TopicAuthorizationException)17 Expression (io.confluent.ksql.execution.expression.tree.Expression)16 IntegerLiteral (io.confluent.ksql.execution.expression.tree.IntegerLiteral)15 CreateArrayExpression (io.confluent.ksql.execution.expression.tree.CreateArrayExpression)12 CreateMapExpression (io.confluent.ksql.execution.expression.tree.CreateMapExpression)12 CreateStructExpression (io.confluent.ksql.execution.expression.tree.CreateStructExpression)12 ComparisonExpression (io.confluent.ksql.execution.expression.tree.ComparisonExpression)10 DoubleLiteral (io.confluent.ksql.execution.expression.tree.DoubleLiteral)10 DecimalLiteral (io.confluent.ksql.execution.expression.tree.DecimalLiteral)9 SearchedCaseExpression (io.confluent.ksql.execution.expression.tree.SearchedCaseExpression)9 BigDecimal (java.math.BigDecimal)9 ArithmeticBinaryExpression (io.confluent.ksql.execution.expression.tree.ArithmeticBinaryExpression)7