Search in sources :

Example 16 with PreparedStatement

use of io.confluent.ksql.parser.KsqlParser.PreparedStatement in project ksql by confluentinc.

the class DistributingExecutorTest method shouldThrowExceptionWhenInsertIntoUnknownStream.

@Test
public void shouldThrowExceptionWhenInsertIntoUnknownStream() {
    // Given
    final PreparedStatement<Statement> preparedStatement = PreparedStatement.of("", new InsertInto(SourceName.of("s1"), mock(Query.class)));
    final ConfiguredStatement<Statement> configured = ConfiguredStatement.of(preparedStatement, SessionConfig.of(KSQL_CONFIG, ImmutableMap.of()));
    doReturn(null).when(metaStore).getSource(SourceName.of("s1"));
    // When:
    final Exception e = assertThrows(KsqlException.class, () -> distributor.execute(configured, executionContext, mock(KsqlSecurityContext.class)));
    // Then:
    assertThat(e.getMessage(), containsString("Cannot insert into an unknown stream/table: `s1`"));
}
Also used : ConfiguredStatement(io.confluent.ksql.statement.ConfiguredStatement) Statement(io.confluent.ksql.parser.tree.Statement) PreparedStatement(io.confluent.ksql.parser.KsqlParser.PreparedStatement) InsertInto(io.confluent.ksql.parser.tree.InsertInto) KsqlTopicAuthorizationException(io.confluent.ksql.exception.KsqlTopicAuthorizationException) ProducerFencedException(org.apache.kafka.common.errors.ProducerFencedException) KsqlRestException(io.confluent.ksql.rest.server.resources.KsqlRestException) KsqlException(io.confluent.ksql.util.KsqlException) TimeoutException(org.apache.kafka.common.errors.TimeoutException) KsqlServerException(io.confluent.ksql.util.KsqlServerException) Test(org.junit.Test)

Example 17 with PreparedStatement

use of io.confluent.ksql.parser.KsqlParser.PreparedStatement in project ksql by confluentinc.

the class DistributingExecutorTest method shouldThrowExceptionWhenInsertIntoSourceWithHeaders.

@Test
public void shouldThrowExceptionWhenInsertIntoSourceWithHeaders() {
    // Given
    final PreparedStatement<Statement> preparedStatement = PreparedStatement.of("", new InsertInto(SourceName.of("s1"), mock(Query.class)));
    final ConfiguredStatement<Statement> configured = ConfiguredStatement.of(preparedStatement, SessionConfig.of(KSQL_CONFIG, ImmutableMap.of()));
    final DataSource dataSource = mock(DataSource.class);
    final LogicalSchema schema = mock(LogicalSchema.class);
    doReturn(dataSource).when(metaStore).getSource(SourceName.of("s1"));
    doReturn(schema).when(dataSource).getSchema();
    doReturn(ImmutableList.of(ColumnName.of("a"))).when(schema).headers();
    when(dataSource.getKafkaTopicName()).thenReturn("topic");
    // When:
    final Exception e = assertThrows(KsqlException.class, () -> distributor.execute(configured, executionContext, mock(KsqlSecurityContext.class)));
    // Then:
    assertThat(e.getMessage(), is("Cannot insert into s1 because it has header columns"));
}
Also used : ConfiguredStatement(io.confluent.ksql.statement.ConfiguredStatement) Statement(io.confluent.ksql.parser.tree.Statement) PreparedStatement(io.confluent.ksql.parser.KsqlParser.PreparedStatement) InsertInto(io.confluent.ksql.parser.tree.InsertInto) LogicalSchema(io.confluent.ksql.schema.ksql.LogicalSchema) KsqlTopicAuthorizationException(io.confluent.ksql.exception.KsqlTopicAuthorizationException) ProducerFencedException(org.apache.kafka.common.errors.ProducerFencedException) KsqlRestException(io.confluent.ksql.rest.server.resources.KsqlRestException) KsqlException(io.confluent.ksql.util.KsqlException) TimeoutException(org.apache.kafka.common.errors.TimeoutException) KsqlServerException(io.confluent.ksql.util.KsqlServerException) DataSource(io.confluent.ksql.metastore.model.DataSource) Test(org.junit.Test)

Example 18 with PreparedStatement

use of io.confluent.ksql.parser.KsqlParser.PreparedStatement in project ksql by confluentinc.

the class DistributingExecutorTest method shouldThrowExceptionIfUserServiceContextIsDeniedAuthorization.

@Test
public void shouldThrowExceptionIfUserServiceContextIsDeniedAuthorization() {
    // Given:
    final KsqlSecurityContext userSecurityContext = new KsqlSecurityContext(Optional.empty(), mock(ServiceContext.class));
    final PreparedStatement<Statement> preparedStatement = PreparedStatement.of("", new ListProperties(Optional.empty()));
    final ConfiguredStatement<Statement> configured = ConfiguredStatement.of(preparedStatement, SessionConfig.of(KSQL_CONFIG, ImmutableMap.of()));
    doThrow(KsqlTopicAuthorizationException.class).when(authorizationValidator).checkAuthorization(eq(userSecurityContext), any(), eq(configured.getStatement()));
    // When:
    assertThrows(KsqlTopicAuthorizationException.class, () -> distributor.execute(configured, executionContext, userSecurityContext));
}
Also used : ListProperties(io.confluent.ksql.parser.tree.ListProperties) KsqlSecurityContext(io.confluent.ksql.security.KsqlSecurityContext) ServiceContext(io.confluent.ksql.services.ServiceContext) TestServiceContext(io.confluent.ksql.services.TestServiceContext) SandboxedServiceContext(io.confluent.ksql.services.SandboxedServiceContext) ConfiguredStatement(io.confluent.ksql.statement.ConfiguredStatement) Statement(io.confluent.ksql.parser.tree.Statement) PreparedStatement(io.confluent.ksql.parser.KsqlParser.PreparedStatement) Test(org.junit.Test)

Example 19 with PreparedStatement

use of io.confluent.ksql.parser.KsqlParser.PreparedStatement in project ksql by confluentinc.

the class DistributingExecutorTest method shouldNotEnqueueRedundantIfNotExists.

@Test
public void shouldNotEnqueueRedundantIfNotExists() {
    // Given:
    final PreparedStatement<Statement> preparedStatement = PreparedStatement.of("", new CreateStream(SourceName.of("TEST"), TableElements.of(), false, true, CreateSourceProperties.from(ImmutableMap.of(CommonCreateConfigs.KAFKA_TOPIC_NAME_PROPERTY, new StringLiteral("topic"), CommonCreateConfigs.VALUE_FORMAT_PROPERTY, new StringLiteral("json"))), false));
    final ConfiguredStatement<Statement> configured = ConfiguredStatement.of(preparedStatement, SessionConfig.of(KSQL_CONFIG, ImmutableMap.of()));
    final DataSource dataSource = mock(DataSource.class);
    doReturn(dataSource).when(metaStore).getSource(SourceName.of("TEST"));
    // When:
    final StatementExecutorResponse response = distributor.execute(configured, executionContext, securityContext);
    // Then:
    assertThat("Should be present", response.getEntity().isPresent());
    assertThat(((WarningEntity) response.getEntity().get()).getMessage(), containsString(""));
}
Also used : StringLiteral(io.confluent.ksql.execution.expression.tree.StringLiteral) ConfiguredStatement(io.confluent.ksql.statement.ConfiguredStatement) Statement(io.confluent.ksql.parser.tree.Statement) PreparedStatement(io.confluent.ksql.parser.KsqlParser.PreparedStatement) CreateStream(io.confluent.ksql.parser.tree.CreateStream) StatementExecutorResponse(io.confluent.ksql.rest.server.execution.StatementExecutorResponse) DataSource(io.confluent.ksql.metastore.model.DataSource) Test(org.junit.Test)

Example 20 with PreparedStatement

use of io.confluent.ksql.parser.KsqlParser.PreparedStatement in project ksql by confluentinc.

the class DistributingExecutorTest method shouldThrowFailureIfCannotInferSchema.

@Test
public void shouldThrowFailureIfCannotInferSchema() {
    // Given:
    final PreparedStatement<Statement> preparedStatement = PreparedStatement.of("", new ListProperties(Optional.empty()));
    final ConfiguredStatement<Statement> configured = ConfiguredStatement.of(preparedStatement, SessionConfig.of(KSQL_CONFIG, ImmutableMap.of()));
    when(schemaInjector.inject(any())).thenThrow(new KsqlException("Could not infer!"));
    // When:
    final Exception e = assertThrows(KsqlException.class, () -> distributor.execute(configured, executionContext, securityContext));
    // Then:
    assertThat(e.getMessage(), containsString("Could not infer!"));
}
Also used : ListProperties(io.confluent.ksql.parser.tree.ListProperties) ConfiguredStatement(io.confluent.ksql.statement.ConfiguredStatement) Statement(io.confluent.ksql.parser.tree.Statement) PreparedStatement(io.confluent.ksql.parser.KsqlParser.PreparedStatement) KsqlException(io.confluent.ksql.util.KsqlException) KsqlTopicAuthorizationException(io.confluent.ksql.exception.KsqlTopicAuthorizationException) ProducerFencedException(org.apache.kafka.common.errors.ProducerFencedException) KsqlRestException(io.confluent.ksql.rest.server.resources.KsqlRestException) KsqlException(io.confluent.ksql.util.KsqlException) TimeoutException(org.apache.kafka.common.errors.TimeoutException) KsqlServerException(io.confluent.ksql.util.KsqlServerException) Test(org.junit.Test)

Aggregations

PreparedStatement (io.confluent.ksql.parser.KsqlParser.PreparedStatement)32 ConfiguredStatement (io.confluent.ksql.statement.ConfiguredStatement)21 Test (org.junit.Test)20 Statement (io.confluent.ksql.parser.tree.Statement)18 KsqlException (io.confluent.ksql.util.KsqlException)15 Query (io.confluent.ksql.parser.tree.Query)9 Matchers.containsString (org.hamcrest.Matchers.containsString)8 KsqlTopicAuthorizationException (io.confluent.ksql.exception.KsqlTopicAuthorizationException)7 ParsedStatement (io.confluent.ksql.parser.KsqlParser.ParsedStatement)7 InsertInto (io.confluent.ksql.parser.tree.InsertInto)7 KsqlRestException (io.confluent.ksql.rest.server.resources.KsqlRestException)7 ServiceContext (io.confluent.ksql.services.ServiceContext)7 KsqlConfig (io.confluent.ksql.util.KsqlConfig)7 Optional (java.util.Optional)7 KsqlExecutionContext (io.confluent.ksql.KsqlExecutionContext)6 SessionConfig (io.confluent.ksql.config.SessionConfig)6 DataSource (io.confluent.ksql.metastore.model.DataSource)6 KsqlServerException (io.confluent.ksql.util.KsqlServerException)6 KsqlStatementException (io.confluent.ksql.util.KsqlStatementException)6 List (java.util.List)6