use of io.confluent.ksql.statement.ConfiguredStatement in project ksql by confluentinc.
the class ExplainExecutor method explainStatement.
private static QueryDescription explainStatement(final ConfiguredStatement<Explain> explain, final KsqlExecutionContext executionContext, final ServiceContext serviceContext) {
final Statement statement = explain.getStatement().getStatement().orElseThrow(() -> new KsqlStatementException("must have either queryID or statement", explain.getStatementText()));
if (!(statement instanceof Query || statement instanceof QueryContainer)) {
throw new KsqlException("The provided statement does not run a ksql query");
}
final PreparedStatement<?> preparedStatement = PreparedStatement.of(explain.getStatementText().substring("EXPLAIN ".length()), statement);
final QueryMetadata metadata;
final KsqlExecutionContext sandbox = executionContext.createSandbox(serviceContext);
if (preparedStatement.getStatement() instanceof Query) {
metadata = sandbox.executeTransientQuery(serviceContext, ConfiguredStatement.of(preparedStatement, explain.getSessionConfig()).cast(), false);
} else {
metadata = sandbox.execute(serviceContext, ConfiguredStatement.of(preparedStatement, explain.getSessionConfig())).getQuery().orElseThrow(() -> new IllegalStateException("The provided statement did not run a ksql query"));
}
return QueryDescriptionFactory.forQueryMetadata(metadata, Collections.emptyMap());
}
use of io.confluent.ksql.statement.ConfiguredStatement in project ksql by confluentinc.
the class ListFunctionsExecutor method execute.
public static StatementExecutorResponse execute(final ConfiguredStatement<ListFunctions> statement, final SessionProperties sessionProperties, final KsqlExecutionContext executionContext, final ServiceContext serviceContext) {
final FunctionRegistry functionRegistry = executionContext.getMetaStore();
final List<SimpleFunctionInfo> all = functionRegistry.listFunctions().stream().map(factory -> new SimpleFunctionInfo(factory.getName().toUpperCase(), FunctionType.SCALAR, factory.getMetadata().getCategory())).collect(Collectors.toList());
functionRegistry.listTableFunctions().stream().map(factory -> new SimpleFunctionInfo(factory.getName().toUpperCase(), FunctionType.TABLE, factory.getMetadata().getCategory())).forEach(all::add);
functionRegistry.listAggregateFunctions().stream().map(factory -> new SimpleFunctionInfo(factory.getName().toUpperCase(), FunctionType.AGGREGATE, factory.getMetadata().getCategory())).forEach(all::add);
return StatementExecutorResponse.handled(Optional.of(new FunctionNameList(statement.getStatementText(), all)));
}
use of io.confluent.ksql.statement.ConfiguredStatement in project ksql by confluentinc.
the class DistributingExecutor method checkAuthorization.
private void checkAuthorization(final ConfiguredStatement<?> configured, final KsqlSecurityContext userSecurityContext, final KsqlExecutionContext serverExecutionContext) {
final Statement statement = configured.getStatement();
final MetaStore metaStore = serverExecutionContext.getMetaStore();
// Check the User will be permitted to execute this statement
authorizationValidator.ifPresent(validator -> validator.checkAuthorization(userSecurityContext, metaStore, statement));
try {
// Check the KSQL service principal will be permitted too
authorizationValidator.ifPresent(validator -> validator.checkAuthorization(new KsqlSecurityContext(Optional.empty(), serverExecutionContext.getServiceContext()), metaStore, statement));
} catch (final Exception e) {
throw new KsqlServerException("The KSQL server is not permitted to execute the command", e);
}
}
use of io.confluent.ksql.statement.ConfiguredStatement in project ksql by confluentinc.
the class TerminateQueryExecutorTest method shouldDefaultToDistributorForTerminateAll.
@Test
public void shouldDefaultToDistributorForTerminateAll() {
// Given:
final ConfiguredStatement<TerminateQuery> terminatePersistent = (ConfiguredStatement<TerminateQuery>) engine.configure("TERMINATE ALL;");
final KsqlEngine engine = mock(KsqlEngine.class);
// When:
final Optional<KsqlEntity> ksqlEntity = CUSTOM_EXECUTORS.terminateQuery().execute(terminatePersistent, mock(SessionProperties.class), engine, this.engine.getServiceContext()).getEntity();
// Then:
assertThat(ksqlEntity, is(Optional.empty()));
}
use of io.confluent.ksql.statement.ConfiguredStatement in project ksql by confluentinc.
the class TerminateQueryExecutorTest method shouldDefaultToDistributorForTerminateCluster.
@Test
public void shouldDefaultToDistributorForTerminateCluster() {
// Given:
final ConfiguredStatement<TerminateQuery> terminatePersistent = (ConfiguredStatement<TerminateQuery>) engine.configure("TERMINATE CLUSTER;");
final KsqlEngine engine = mock(KsqlEngine.class);
// When:
final Optional<KsqlEntity> ksqlEntity = CUSTOM_EXECUTORS.terminateQuery().execute(terminatePersistent, mock(SessionProperties.class), engine, this.engine.getServiceContext()).getEntity();
// Then:
assertThat(ksqlEntity, is(Optional.empty()));
}
Aggregations