Search in sources :

Example 6 with InsertValues

use of io.confluent.ksql.parser.tree.InsertValues 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 7 with InsertValues

use of io.confluent.ksql.parser.tree.InsertValues 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 8 with InsertValues

use of io.confluent.ksql.parser.tree.InsertValues 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 9 with InsertValues

use of io.confluent.ksql.parser.tree.InsertValues 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)

Example 10 with InsertValues

use of io.confluent.ksql.parser.tree.InsertValues 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)

Aggregations

InsertValues (io.confluent.ksql.parser.tree.InsertValues)32 Test (org.junit.Test)25 KsqlException (io.confluent.ksql.util.KsqlException)24 RestClientException (io.confluent.kafka.schemaregistry.client.rest.exceptions.RestClientException)22 ExecutionException (java.util.concurrent.ExecutionException)22 TopicAuthorizationException (org.apache.kafka.common.errors.TopicAuthorizationException)22 StringLiteral (io.confluent.ksql.execution.expression.tree.StringLiteral)21 LongLiteral (io.confluent.ksql.execution.expression.tree.LongLiteral)20 SerializationException (org.apache.kafka.common.errors.SerializationException)20 KsqlConfig (io.confluent.ksql.util.KsqlConfig)8 SessionProperties (io.confluent.ksql.rest.SessionProperties)5 SchemaMetadata (io.confluent.kafka.schemaregistry.client.SchemaMetadata)4 GenericRecordFactory (io.confluent.ksql.engine.generic.GenericRecordFactory)3 KsqlGenericRecord (io.confluent.ksql.engine.generic.KsqlGenericRecord)3 NullLiteral (io.confluent.ksql.execution.expression.tree.NullLiteral)3 DataSource (io.confluent.ksql.metastore.model.DataSource)3 KsqlSchemaAuthorizationException (io.confluent.ksql.exception.KsqlSchemaAuthorizationException)2 KsqlTopicAuthorizationException (io.confluent.ksql.exception.KsqlTopicAuthorizationException)2 DoubleLiteral (io.confluent.ksql.execution.expression.tree.DoubleLiteral)2 KsqlStatementException (io.confluent.ksql.util.KsqlStatementException)2