Search in sources :

Example 31 with ParsedStatement

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());
}
Also used : ServiceContext(io.confluent.ksql.services.ServiceContext) TestServiceContext(io.confluent.ksql.services.TestServiceContext) SandboxedServiceContext(io.confluent.ksql.services.SandboxedServiceContext) ParsedStatement(io.confluent.ksql.parser.KsqlParser.ParsedStatement) Test(org.junit.Test)

Example 32 with ParsedStatement

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"));
}
Also used : CreateStream(io.confluent.ksql.parser.tree.CreateStream) ParsedStatement(io.confluent.ksql.parser.KsqlParser.ParsedStatement) KsqlException(io.confluent.ksql.util.KsqlException) KsqlException(io.confluent.ksql.util.KsqlException) KsqlStatementException(io.confluent.ksql.util.KsqlStatementException) Test(org.junit.Test)

Example 33 with ParsedStatement

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"));
}
Also used : ParsedStatement(io.confluent.ksql.parser.KsqlParser.ParsedStatement) KsqlException(io.confluent.ksql.util.KsqlException) KsqlStatementException(io.confluent.ksql.util.KsqlStatementException) Test(org.junit.Test)

Example 34 with ParsedStatement

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);
}
Also used : PersistentQueryMetadata(io.confluent.ksql.util.PersistentQueryMetadata) QueryMetadata(io.confluent.ksql.util.QueryMetadata) Injector(io.confluent.ksql.statement.Injector) ParsedStatement(io.confluent.ksql.parser.KsqlParser.ParsedStatement)

Example 35 with ParsedStatement

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;
}
Also used : KsqlEntityList(io.confluent.ksql.rest.entity.KsqlEntityList) ParsedStatement(io.confluent.ksql.parser.KsqlParser.ParsedStatement)

Aggregations

ParsedStatement (io.confluent.ksql.parser.KsqlParser.ParsedStatement)37 Test (org.junit.Test)22 KsqlStatementException (io.confluent.ksql.util.KsqlStatementException)15 KsqlException (io.confluent.ksql.util.KsqlException)10 CreateStream (io.confluent.ksql.parser.tree.CreateStream)7 ExecuteResult (io.confluent.ksql.KsqlExecutionContext.ExecuteResult)6 KsqlEntityList (io.confluent.ksql.rest.entity.KsqlEntityList)6 Optional (java.util.Optional)6 DefaultKsqlParser (io.confluent.ksql.parser.DefaultKsqlParser)5 PreparedStatement (io.confluent.ksql.parser.KsqlParser.PreparedStatement)5 ConfiguredStatement (io.confluent.ksql.statement.ConfiguredStatement)5 Injector (io.confluent.ksql.statement.Injector)5 KsqlConfig (io.confluent.ksql.util.KsqlConfig)5 QueryMetadata (io.confluent.ksql.util.QueryMetadata)5 IOException (java.io.IOException)5 HashMap (java.util.HashMap)5 KsqlExecutionContext (io.confluent.ksql.KsqlExecutionContext)4 KsqlEntity (io.confluent.ksql.rest.entity.KsqlEntity)4 ServiceContext (io.confluent.ksql.services.ServiceContext)4 PersistentQueryMetadata (io.confluent.ksql.util.PersistentQueryMetadata)4