use of io.confluent.ksql.parser.KsqlParser.ParsedStatement in project ksql by confluentinc.
the class RequestValidatorTest method shouldExecuteWithSpecifiedServiceContext.
@Test
public void shouldExecuteWithSpecifiedServiceContext() {
// Given:
final List<ParsedStatement> statements = givenParsed(SOME_STREAM_SQL);
final ServiceContext otherServiceContext = SandboxedServiceContext.create(TestServiceContext.create());
// When:
validator.validate(otherServiceContext, statements, sessionProperties, "sql");
// Then:
verify(distributedStatementValidator).create(argThat(configured(preparedStatement(instanceOf(CreateStream.class)))), same(otherServiceContext), any());
}
use of io.confluent.ksql.parser.KsqlParser.ParsedStatement in project ksql by confluentinc.
the class RequestValidatorTest method shouldThrowExceptionIfValidationFails.
@Test
public void shouldThrowExceptionIfValidationFails() {
// Given:
givenRequestValidator(ImmutableMap.of(CreateStream.class, statementValidator));
doThrow(new KsqlException("Fail")).when(statementValidator).validate(any(), any(), any(), any());
final List<ParsedStatement> statements = givenParsed(SOME_STREAM_SQL);
// When:
final Exception e = assertThrows(KsqlException.class, () -> validator.validate(serviceContext, statements, sessionProperties, "sql"));
// Then:
assertThat(e.getMessage(), containsString("Fail"));
}
use of io.confluent.ksql.parser.KsqlParser.ParsedStatement in project ksql by confluentinc.
the class RequestValidatorTest method shouldThrowIfTooManyPersistentQueries.
@Test
public void shouldThrowIfTooManyPersistentQueries() {
// Given:
when(ksqlConfig.getInt(KsqlConfig.KSQL_ACTIVE_PERSISTENT_QUERY_LIMIT_CONFIG)).thenReturn(1);
givenPersistentQueryCount(2);
final List<ParsedStatement> statements = givenParsed("CREATE STREAM sink AS SELECT * FROM source;" + "CREATE STREAM sink2 as SELECT * FROM sink;");
// When:
final Exception e = assertThrows(KsqlException.class, () -> validator.validate(serviceContext, statements, sessionProperties, "sql"));
// Then:
assertThat(e.getMessage(), containsString("persistent queries to exceed the configured limit"));
}
use of io.confluent.ksql.parser.KsqlParser.ParsedStatement in project ksql by confluentinc.
the class StandaloneExecutor method processesQueryFile.
private void processesQueryFile(final String queries) {
final List<ParsedStatement> preparedStatements = ksqlEngine.parse(queries);
validateStatements(preparedStatements);
final Injector injector = injectorFactory.apply(ksqlEngine, serviceContext);
executeStatements(preparedStatements, new StatementExecutor(serviceContext, ksqlEngine, injector, ksqlConfig));
ksqlEngine.getPersistentQueries().forEach(QueryMetadata::start);
}
use of io.confluent.ksql.parser.KsqlParser.ParsedStatement in project ksql by confluentinc.
the class RequestHandler method execute.
public KsqlEntityList execute(final KsqlSecurityContext securityContext, final List<ParsedStatement> statements, final SessionProperties sessionProperties) {
final KsqlEntityList entities = new KsqlEntityList();
for (final ParsedStatement parsed : statements) {
final PreparedStatement<?> prepared = ksqlEngine.prepare(parsed, (isVariableSubstitutionEnabled(sessionProperties) ? sessionProperties.getSessionVariables() : Collections.emptyMap()));
executeStatement(securityContext, prepared, sessionProperties, entities).ifPresent(entities::add);
}
return entities;
}
Aggregations