Search in sources :

Example 26 with InsertValues

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

Example 27 with InsertValues

use of io.confluent.ksql.parser.tree.InsertValues in project ksql by confluentinc.

the class InsertValuesExecutorTest method shouldThrowIfColumnDoesNotExistInSchema.

@Test
public void shouldThrowIfColumnDoesNotExistInSchema() {
    // Given:
    givenSourceStreamWithSchema(SINGLE_VALUE_COLUMN_SCHEMA, SerdeFeatures.of(), SerdeFeatures.of());
    final ConfiguredStatement<InsertValues> statement = givenInsertValues(ImmutableList.of(K0, ColumnName.of("NONEXISTENT")), ImmutableList.of(new StringLiteral("foo"), new StringLiteral("bar")));
    // When:
    final Exception e = assertThrows(KsqlException.class, () -> executor.execute(statement, mock(SessionProperties.class), engine, serviceContext));
    // Then:
    assertThat(e.getCause(), (hasMessage(containsString("Column name `NONEXISTENT` does not exist."))));
}
Also used : StringLiteral(io.confluent.ksql.execution.expression.tree.StringLiteral) 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 InsertValues

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

use of io.confluent.ksql.parser.tree.InsertValues in project ksql by confluentinc.

the class InsertValuesExecutorTest method shouldThrowIfNotEnoughValuesSuppliedWithNoSchema.

@Test
public void shouldThrowIfNotEnoughValuesSuppliedWithNoSchema() {
    // Given:
    final ConfiguredStatement<InsertValues> statement = givenInsertValues(ImmutableList.of(), ImmutableList.of(new LongLiteral(1L)));
    // When:
    final Exception e = assertThrows(KsqlException.class, () -> executor.execute(statement, mock(SessionProperties.class), engine, serviceContext));
    // Then:
    assertThat(e.getCause(), (hasMessage(containsString("Expected a value for each column"))));
}
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 30 with InsertValues

use of io.confluent.ksql.parser.tree.InsertValues in project ksql by confluentinc.

the class InsertValuesExecutorTest method shouldThrowWhenInsertValuesOnReservedInternalTopic.

@Test
public void shouldThrowWhenInsertValuesOnReservedInternalTopic() {
    // Given
    givenDataSourceWithSchema("_confluent-ksql-default__command-topic", 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: _confluent-ksql-default__command-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