Search in sources :

Example 1 with InsertInto

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

the class StandaloneExecutorTest method shouldRunInsertIntoStatements.

@Test
public void shouldRunInsertIntoStatements() {
    // Given:
    final PreparedStatement<?> insertInto = PreparedStatement.of("InsertInto", new InsertInto(SOME_NAME, query));
    final ConfiguredStatement<?> configured = ConfiguredStatement.of(insertInto, SessionConfig.of(ksqlConfig, emptyMap()));
    givenQueryFileParsesTo(insertInto);
    when(sandBox.execute(sandBoxServiceContext, configured)).thenReturn(ExecuteResult.of(persistentQuery));
    // When:
    standaloneExecutor.startAsync();
    // Then:
    verify(ksqlEngine).execute(serviceContext, configured);
}
Also used : InsertInto(io.confluent.ksql.parser.tree.InsertInto) Test(org.junit.Test)

Example 2 with InsertInto

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

the class StatementRewriterTest method shouldRewriteInsertIntoUsingPlugin.

@Test
public void shouldRewriteInsertIntoUsingPlugin() {
    // Given:
    final InsertInto ii = mock(InsertInto.class);
    final InsertInto pluginResult = mock(InsertInto.class);
    when(ii.accept(any(), any())).thenCallRealMethod();
    // When/Then:
    shouldUsePluginToRewrite(ii, pluginResult);
}
Also used : InsertInto(io.confluent.ksql.parser.tree.InsertInto) Test(org.junit.Test)

Example 3 with InsertInto

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

the class DistributingExecutorTest method shouldThrowExceptionWhenInsertIntoReadOnlyTopic.

@Test
public void shouldThrowExceptionWhenInsertIntoReadOnlyTopic() {
    // 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);
    doReturn(dataSource).when(metaStore).getSource(SourceName.of("s1"));
    when(dataSource.getKafkaTopicName()).thenReturn("_confluent-ksql-default__command-topic");
    // When:
    final Exception e = assertThrows(KsqlException.class, () -> distributor.execute(configured, executionContext, mock(KsqlSecurityContext.class)));
    // Then:
    assertThat(e.getMessage(), containsString("Cannot insert into read-only topic: " + "_confluent-ksql-default__command-topic"));
}
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) DataSource(io.confluent.ksql.metastore.model.DataSource) Test(org.junit.Test)

Example 4 with InsertInto

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

the class DistributingExecutorTest method shouldThrowExceptionWhenInsertIntoProcessingLogTopic.

@Test
public void shouldThrowExceptionWhenInsertIntoProcessingLogTopic() {
    // 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);
    doReturn(dataSource).when(metaStore).getSource(SourceName.of("s1"));
    when(dataSource.getKafkaTopicName()).thenReturn("default_ksql_processing_log");
    // When:
    final Exception e = assertThrows(KsqlException.class, () -> distributor.execute(configured, executionContext, mock(KsqlSecurityContext.class)));
    // Then:
    assertThat(e.getMessage(), containsString("Cannot insert into read-only topic: " + "default_ksql_processing_log"));
}
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) DataSource(io.confluent.ksql.metastore.model.DataSource) Test(org.junit.Test)

Example 5 with InsertInto

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

the class StatementRewriterTest method shouldRewriteInsertIntoWithPartitionBy.

@Test
public void shouldRewriteInsertIntoWithPartitionBy() {
    // Given:
    final InsertInto ii = new InsertInto(location, sourceName, query, insertIntoProperties);
    when(mockRewriter.apply(query, context)).thenReturn(rewrittenQuery);
    when(expressionRewriter.apply(expression, context)).thenReturn(rewrittenExpression);
    // When:
    final AstNode rewritten = rewriter.rewrite(ii, context);
    // Then:
    assertThat(rewritten, equalTo(new InsertInto(location, sourceName, rewrittenQuery, insertIntoProperties)));
}
Also used : InsertInto(io.confluent.ksql.parser.tree.InsertInto) AstNode(io.confluent.ksql.parser.tree.AstNode) Test(org.junit.Test)

Aggregations

InsertInto (io.confluent.ksql.parser.tree.InsertInto)12 Test (org.junit.Test)9 PreparedStatement (io.confluent.ksql.parser.KsqlParser.PreparedStatement)7 Statement (io.confluent.ksql.parser.tree.Statement)6 KsqlException (io.confluent.ksql.util.KsqlException)6 KsqlRestException (io.confluent.ksql.rest.server.resources.KsqlRestException)5 ConfiguredStatement (io.confluent.ksql.statement.ConfiguredStatement)5 KsqlServerException (io.confluent.ksql.util.KsqlServerException)5 ProducerFencedException (org.apache.kafka.common.errors.ProducerFencedException)5 TimeoutException (org.apache.kafka.common.errors.TimeoutException)5 KsqlTopicAuthorizationException (io.confluent.ksql.exception.KsqlTopicAuthorizationException)4 DataSource (io.confluent.ksql.metastore.model.DataSource)3 TerminateQuery (io.confluent.ksql.parser.tree.TerminateQuery)3 AstNode (io.confluent.ksql.parser.tree.AstNode)2 CreateAsSelect (io.confluent.ksql.parser.tree.CreateAsSelect)2 CommandStatus (io.confluent.ksql.rest.entity.CommandStatus)2 ComparisonExpression (io.confluent.ksql.execution.expression.tree.ComparisonExpression)1 ParsedStatement (io.confluent.ksql.parser.KsqlParser.ParsedStatement)1 AlterSystemProperty (io.confluent.ksql.parser.tree.AlterSystemProperty)1 ExecutableDdlStatement (io.confluent.ksql.parser.tree.ExecutableDdlStatement)1