Search in sources :

Example 96 with StringLiteral

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

the class InsertValuesExecutorTest method shouldThrowOnTopicAuthorizationException.

@Test
public void shouldThrowOnTopicAuthorizationException() {
    // Given:
    final ConfiguredStatement<InsertValues> statement = givenInsertValues(allAndPseudoColumnNames(SCHEMA), ImmutableList.of(new LongLiteral(1L), new StringLiteral("str"), new StringLiteral("str"), new LongLiteral(2L)));
    doThrow(new TopicAuthorizationException(Collections.singleton("t1"))).when(producer).send(any());
    // When:
    final Exception e = assertThrows(KsqlException.class, () -> executor.execute(statement, mock(SessionProperties.class), engine, serviceContext));
    // Then:
    assertThat(e.getCause(), (hasMessage(containsString("Authorization denied to Write on topic(s): [t1]"))));
}
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) TopicAuthorizationException(org.apache.kafka.common.errors.TopicAuthorizationException) 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 97 with StringLiteral

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

the class InsertValuesExecutorTest method shouldThrowWhenInsertingValuesOnSourceTable.

@Test
public void shouldThrowWhenInsertingValuesOnSourceTable() {
    // Given:
    givenDataSourceWithSchema("source_table_1", SCHEMA, SerdeFeatures.of(), SerdeFeatures.of(), true, 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 table: 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 98 with StringLiteral

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

the class InsertValuesExecutorTest method shouldBuildCorrectSerde.

@Test
public void shouldBuildCorrectSerde() {
    // Given:
    final ConfiguredStatement<InsertValues> statement = givenInsertValues(valueColumnNames(SCHEMA), ImmutableList.of(new StringLiteral("str"), new LongLiteral(2L)));
    // When:
    executor.execute(statement, mock(SessionProperties.class), engine, serviceContext);
    // Then:
    verify(keySerdeFactory).create(FormatInfo.of(FormatFactory.KAFKA.name()), PersistenceSchema.from(SCHEMA.key(), SerdeFeatures.of()), new KsqlConfig(ImmutableMap.of()), srClientFactory, "", NoopProcessingLogContext.INSTANCE, Optional.empty());
    verify(valueSerdeFactory).create(FormatInfo.of(FormatFactory.JSON.name()), PersistenceSchema.from(SCHEMA.value(), SerdeFeatures.of()), new KsqlConfig(ImmutableMap.of()), srClientFactory, "", NoopProcessingLogContext.INSTANCE, Optional.empty());
}
Also used : SessionProperties(io.confluent.ksql.rest.SessionProperties) 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) Test(org.junit.Test)

Example 99 with StringLiteral

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

the class InsertValuesExecutorTest method shouldThrowOnTablesWithNoKeyFieldAndNoRowKeyProvided.

@Test
public void shouldThrowOnTablesWithNoKeyFieldAndNoRowKeyProvided() {
    // Given:
    givenSourceTableWithSchema(SerdeFeatures.of(), SerdeFeatures.of());
    final ConfiguredStatement<InsertValues> statement = givenInsertValues(ImmutableList.of(COL0, COL1), ImmutableList.of(new StringLiteral("str"), 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 : 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 100 with StringLiteral

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

the class InsertValuesExecutorTest method shouldThrowOnProducerSendError.

@Test
public void shouldThrowOnProducerSendError() throws ExecutionException, InterruptedException {
    // Given:
    final ConfiguredStatement<InsertValues> statement = givenInsertValues(allAndPseudoColumnNames(SCHEMA), ImmutableList.of(new LongLiteral(1L), new StringLiteral("str"), new StringLiteral("str"), new LongLiteral(2L)));
    final Future<?> failure = mock(Future.class);
    when(failure.get()).thenThrow(ExecutionException.class);
    doReturn(failure).when(producer).send(any());
    // 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 "));
}
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) 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

StringLiteral (io.confluent.ksql.execution.expression.tree.StringLiteral)204 Test (org.junit.Test)199 Expression (io.confluent.ksql.execution.expression.tree.Expression)95 CreateStructExpression (io.confluent.ksql.execution.expression.tree.CreateStructExpression)70 ComparisonExpression (io.confluent.ksql.execution.expression.tree.ComparisonExpression)66 KsqlException (io.confluent.ksql.util.KsqlException)64 CreateArrayExpression (io.confluent.ksql.execution.expression.tree.CreateArrayExpression)63 CreateMapExpression (io.confluent.ksql.execution.expression.tree.CreateMapExpression)63 IntegerLiteral (io.confluent.ksql.execution.expression.tree.IntegerLiteral)63 InListExpression (io.confluent.ksql.execution.expression.tree.InListExpression)61 ArithmeticBinaryExpression (io.confluent.ksql.execution.expression.tree.ArithmeticBinaryExpression)53 SearchedCaseExpression (io.confluent.ksql.execution.expression.tree.SearchedCaseExpression)51 SubscriptExpression (io.confluent.ksql.execution.expression.tree.SubscriptExpression)49 ArithmeticUnaryExpression (io.confluent.ksql.execution.expression.tree.ArithmeticUnaryExpression)43 DereferenceExpression (io.confluent.ksql.execution.expression.tree.DereferenceExpression)36 LongLiteral (io.confluent.ksql.execution.expression.tree.LongLiteral)35 SimpleCaseExpression (io.confluent.ksql.execution.expression.tree.SimpleCaseExpression)34 LogicalBinaryExpression (io.confluent.ksql.execution.expression.tree.LogicalBinaryExpression)31 BooleanLiteral (io.confluent.ksql.execution.expression.tree.BooleanLiteral)28 Matchers.containsString (org.hamcrest.Matchers.containsString)27