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);
}
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);
}
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"));
}
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"));
}
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)));
}
Aggregations