use of io.confluent.ksql.parser.tree.InsertValues in project ksql by confluentinc.
the class InsertValuesExecutor method execute.
// Part of required API.
@SuppressWarnings("unused")
public void execute(final ConfiguredStatement<InsertValues> statement, final SessionProperties sessionProperties, final KsqlExecutionContext executionContext, final ServiceContext serviceContext) {
final InsertValues insertValues = statement.getStatement();
final MetaStore metaStore = executionContext.getMetaStore();
final KsqlConfig config = statement.getSessionConfig().getConfig(true);
final DataSource dataSource = getDataSource(config, metaStore, insertValues);
validateInsert(insertValues.getColumns(), dataSource);
final ProducerRecord<byte[], byte[]> record = buildRecord(statement, metaStore, dataSource, serviceContext);
try {
producer.sendRecord(record, serviceContext, config.getProducerClientConfigProps());
} catch (final TopicAuthorizationException e) {
// TopicAuthorizationException does not give much detailed information about why it failed,
// except which topics are denied. Here we just add the ACL to make the error message
// consistent with other authorization error messages.
final Exception rootCause = new KsqlTopicAuthorizationException(AclOperation.WRITE, e.unauthorizedTopics());
throw new KsqlException(createInsertFailedExceptionMessage(insertValues), rootCause);
} catch (final Exception e) {
throw new KsqlException(createInsertFailedExceptionMessage(insertValues), e);
}
}
use of io.confluent.ksql.parser.tree.InsertValues in project ksql by confluentinc.
the class TestExecutorUtil method execute.
/**
* @param srClient if supplied, then schemas can be inferred from the schema registry.
* @return a list of persistent queries that should be run by the test executor, if a query was
* replaced via a CREATE OR REPLACE statement it will only appear once in the output list
*/
@SuppressWarnings("OptionalGetWithoutIsPresent")
private static List<PersistentQueryAndSources> execute(final KsqlEngine engine, final TestCase testCase, final KsqlConfig ksqlConfig, final ServiceContext serviceContext, final Optional<SchemaRegistryClient> srClient, final StubKafkaService stubKafkaService, final TestExecutionListener listener) {
final Map<QueryId, PersistentQueryAndSources> queries = new LinkedHashMap<>();
int idx = 0;
final Iterator<PlannedStatement> plans = planTestCase(engine, testCase, ksqlConfig, serviceContext, srClient, stubKafkaService);
try {
while (plans.hasNext()) {
++idx;
final PlannedStatement planned = plans.next();
if (planned.insertValues.isPresent()) {
final ConfiguredStatement<InsertValues> insertValues = planned.insertValues.get();
final SessionProperties sessionProperties = new SessionProperties(insertValues.getSessionConfig().getOverrides(), new KsqlHostInfo("host", 50), buildUrl(), false);
StubInsertValuesExecutor.of(stubKafkaService).execute(insertValues, sessionProperties, engine, engine.getServiceContext());
continue;
}
final ConfiguredKsqlPlan plan = planned.plan.orElseThrow(IllegalStateException::new);
listener.acceptPlan(plan);
final ExecuteResultAndSources result = executePlan(engine, plan);
if (!result.getSources().isPresent()) {
continue;
}
final PersistentQueryMetadata query = (PersistentQueryMetadata) result.getExecuteResult().getQuery().get();
listener.acceptQuery(query);
queries.put(query.getQueryId(), new PersistentQueryAndSources(query, result.getSources().get()));
}
return ImmutableList.copyOf(queries.values());
} catch (final KsqlStatementException e) {
if (testCase.expectedException().isPresent() && plans.hasNext()) {
throw new AssertionError("Only the last statement in a negative test should fail. " + "Yet in this case statement " + idx + " failed.", e);
}
throw e;
}
}
use of io.confluent.ksql.parser.tree.InsertValues in project ksql by confluentinc.
the class AssertExecutor method assertValues.
public static void assertValues(final KsqlExecutionContext engine, final KsqlConfig config, final AssertValues assertValues, final TestDriverPipeline driverPipeline) {
final InsertValues values = assertValues.getStatement();
assertContent(engine, config, values, driverPipeline, false);
}
use of io.confluent.ksql.parser.tree.InsertValues in project ksql by confluentinc.
the class AssertExecutor method assertTombstone.
public static void assertTombstone(final KsqlExecutionContext engine, final KsqlConfig config, final AssertTombstone assertTombstone, final TestDriverPipeline driverPipeline) {
final InsertValues values = assertTombstone.getStatement();
assertContent(engine, config, values, driverPipeline, true);
}
use of io.confluent.ksql.parser.tree.InsertValues in project ksql by confluentinc.
the class InsertValuesExecutorTest method shouldThrowOnTopicAuthorizationException.
@Test
public void shouldThrowOnTopicAuthorizationException() {
// Given:
final ConfiguredStatement<InsertValues> statement = givenInsertValues(allAndPseudoColumnNames(SCHEMA), ImmutableList.of(new LongLiteral(1L), new StringLiteral("str"), new StringLiteral("str"), new LongLiteral(2L)));
doThrow(new TopicAuthorizationException(Collections.singleton("t1"))).when(producer).send(any());
// When:
final Exception e = assertThrows(KsqlException.class, () -> executor.execute(statement, mock(SessionProperties.class), engine, serviceContext));
// Then:
assertThat(e.getCause(), (hasMessage(containsString("Authorization denied to Write on topic(s): [t1]"))));
}
Aggregations