Search in sources :

Example 1 with KsqlStructuredDataOutputNode

use of io.confluent.ksql.planner.plan.KsqlStructuredDataOutputNode in project ksql by confluentinc.

the class KsqlResource method describe.

private SourceDescription describe(String name, boolean extended) throws KsqlException {
    StructuredDataSource dataSource = ksqlEngine.getMetaStore().getSource(name);
    if (dataSource == null) {
        throw new KsqlException(String.format("Could not find STREAM/TABLE '%s' in the Metastore", name));
    }
    List<PersistentQueryMetadata> queries = ksqlEngine.getPersistentQueries().values().stream().filter(meta -> ((KsqlStructuredDataOutputNode) meta.getOutputNode()).getKafkaTopicName().equals(dataSource.getKsqlTopic().getTopicName())).collect(Collectors.toList());
    return new SourceDescription(dataSource, extended, dataSource.getKsqlTopic().getKsqlTopicSerDe().getSerDe().name(), "", "", getReadQueryIds(queries), getWriteQueryIds(queries), ksqlEngine.getTopicClient());
}
Also used : CreateTableCommand(io.confluent.ksql.ddl.commands.CreateTableCommand) Query(io.confluent.ksql.parser.tree.Query) CreateTableAsSelect(io.confluent.ksql.parser.tree.CreateTableAsSelect) Interval(org.antlr.v4.runtime.misc.Interval) StreamsList(io.confluent.ksql.rest.entity.StreamsList) Produces(javax.ws.rs.Produces) AbstractStreamCreateStatement(io.confluent.ksql.parser.tree.AbstractStreamCreateStatement) LoggerFactory(org.slf4j.LoggerFactory) Path(javax.ws.rs.Path) TimeoutException(java.util.concurrent.TimeoutException) KsqlEngine(io.confluent.ksql.KsqlEngine) KsqlParser(io.confluent.ksql.parser.KsqlParser) KafkaTopicsList(io.confluent.ksql.rest.entity.KafkaTopicsList) SourceDescription(io.confluent.ksql.rest.entity.SourceDescription) KafkaTopicClient(io.confluent.ksql.util.KafkaTopicClient) MediaType(javax.ws.rs.core.MediaType) KsqlTopic(io.confluent.ksql.metastore.KsqlTopic) CommandId(io.confluent.ksql.rest.server.computation.CommandId) Pair(io.confluent.ksql.util.Pair) Consumes(javax.ws.rs.Consumes) CreateTable(io.confluent.ksql.parser.tree.CreateTable) Explain(io.confluent.ksql.parser.tree.Explain) Map(java.util.Map) RegisterTopic(io.confluent.ksql.parser.tree.RegisterTopic) KsqlStream(io.confluent.ksql.metastore.KsqlStream) QueryId(io.confluent.ksql.query.QueryId) DropTopic(io.confluent.ksql.parser.tree.DropTopic) PersistentQueryMetadata(io.confluent.ksql.util.PersistentQueryMetadata) DdlCommandResult(io.confluent.ksql.ddl.commands.DdlCommandResult) QueryMetadata(io.confluent.ksql.util.QueryMetadata) CommandStatus(io.confluent.ksql.rest.entity.CommandStatus) PropertiesList(io.confluent.ksql.rest.entity.PropertiesList) DropStream(io.confluent.ksql.parser.tree.DropStream) Collection(java.util.Collection) KsqlTable(io.confluent.ksql.metastore.KsqlTable) KafkaConsumerGroupClient(io.confluent.ksql.util.KafkaConsumerGroupClient) Collectors(java.util.stream.Collectors) ErrorMessageEntity(io.confluent.ksql.rest.entity.ErrorMessageEntity) List(java.util.List) Response(javax.ws.rs.core.Response) SetProperty(io.confluent.ksql.parser.tree.SetProperty) TopicDescription(io.confluent.ksql.rest.entity.TopicDescription) KafkaConsumerGroupClientImpl(io.confluent.ksql.util.KafkaConsumerGroupClientImpl) TerminateQuery(io.confluent.ksql.parser.tree.TerminateQuery) DdlCommandExec(io.confluent.ksql.ddl.commands.DdlCommandExec) DdlCommand(io.confluent.ksql.ddl.commands.DdlCommand) KsqlException(io.confluent.ksql.util.KsqlException) Statement(io.confluent.ksql.parser.tree.Statement) KsqlRequest(io.confluent.ksql.rest.entity.KsqlRequest) DdlStatement(io.confluent.ksql.parser.tree.DdlStatement) ListTopics(io.confluent.ksql.parser.tree.ListTopics) KsqlRestApplication(io.confluent.ksql.rest.server.KsqlRestApplication) HashMap(java.util.HashMap) KsqlEntityList(io.confluent.ksql.rest.entity.KsqlEntityList) RegisterTopicCommand(io.confluent.ksql.ddl.commands.RegisterTopicCommand) CreateStreamAsSelect(io.confluent.ksql.parser.tree.CreateStreamAsSelect) ListProperties(io.confluent.ksql.parser.tree.ListProperties) ArrayList(java.util.ArrayList) KsqlEntity(io.confluent.ksql.rest.entity.KsqlEntity) CreateStream(io.confluent.ksql.parser.tree.CreateStream) CharStream(org.antlr.v4.runtime.CharStream) ShowColumns(io.confluent.ksql.parser.tree.ShowColumns) KsqlStructuredDataOutputNode(io.confluent.ksql.planner.plan.KsqlStructuredDataOutputNode) Queries(io.confluent.ksql.rest.entity.Queries) TablesList(io.confluent.ksql.rest.entity.TablesList) StatementExecutor(io.confluent.ksql.rest.server.computation.StatementExecutor) DropSourceCommand(io.confluent.ksql.ddl.commands.DropSourceCommand) ListTables(io.confluent.ksql.parser.tree.ListTables) DropTable(io.confluent.ksql.parser.tree.DropTable) POST(javax.ws.rs.POST) ListStreams(io.confluent.ksql.parser.tree.ListStreams) RunScript(io.confluent.ksql.parser.tree.RunScript) ListQueries(io.confluent.ksql.parser.tree.ListQueries) CommandStatusEntity(io.confluent.ksql.rest.entity.CommandStatusEntity) ListRegisteredTopics(io.confluent.ksql.parser.tree.ListRegisteredTopics) DropTopicCommand(io.confluent.ksql.ddl.commands.DropTopicCommand) CreateStreamCommand(io.confluent.ksql.ddl.commands.CreateStreamCommand) CommandStore(io.confluent.ksql.rest.server.computation.CommandStore) DataSource(io.confluent.ksql.serde.DataSource) TimeUnit(java.util.concurrent.TimeUnit) KsqlTopicsList(io.confluent.ksql.rest.entity.KsqlTopicsList) CreateAsSelect(io.confluent.ksql.parser.tree.CreateAsSelect) StructuredDataSource(io.confluent.ksql.metastore.StructuredDataSource) AvroUtil(io.confluent.ksql.util.AvroUtil) Collections(java.util.Collections) SqlBaseParser(io.confluent.ksql.parser.SqlBaseParser) StructuredDataSource(io.confluent.ksql.metastore.StructuredDataSource) KsqlException(io.confluent.ksql.util.KsqlException) PersistentQueryMetadata(io.confluent.ksql.util.PersistentQueryMetadata) SourceDescription(io.confluent.ksql.rest.entity.SourceDescription)

Example 2 with KsqlStructuredDataOutputNode

use of io.confluent.ksql.planner.plan.KsqlStructuredDataOutputNode in project ksql by confluentinc.

the class PhysicalPlanBuilder method buildPhysicalPlan.

public QueryMetadata buildPhysicalPlan(final Pair<String, PlanNode> statementPlanPair) throws Exception {
    final SchemaKStream resultStream = statementPlanPair.getRight().buildStream(builder, ksqlConfig, kafkaTopicClient, functionRegistry, overriddenStreamsProperties, schemaRegistryClient);
    final OutputNode outputNode = resultStream.outputNode();
    boolean isBareQuery = outputNode instanceof KsqlBareOutputNode;
    // the corresponding Kafka Streams job
    if (isBareQuery && !(resultStream instanceof QueuedSchemaKStream)) {
        throw new Exception(String.format("Mismatch between logical and physical output; " + "expected a QueuedSchemaKStream based on logical " + "KsqlBareOutputNode, found a %s instead", resultStream.getClass().getCanonicalName()));
    }
    String serviceId = getServiceId();
    String persistanceQueryPrefix = ksqlConfig.get(KsqlConfig.KSQL_PERSISTENT_QUERY_NAME_PREFIX_CONFIG).toString();
    String transientQueryPrefix = ksqlConfig.get(KsqlConfig.KSQL_TRANSIENT_QUERY_NAME_PREFIX_CONFIG).toString();
    if (isBareQuery) {
        return buildPlanForBareQuery((QueuedSchemaKStream) resultStream, (KsqlBareOutputNode) outputNode, serviceId, transientQueryPrefix, statementPlanPair.getLeft());
    } else if (outputNode instanceof KsqlStructuredDataOutputNode) {
        return buildPlanForStructuredOutputNode(statementPlanPair.getLeft(), resultStream, (KsqlStructuredDataOutputNode) outputNode, serviceId, persistanceQueryPrefix, statementPlanPair.getLeft());
    } else {
        throw new KsqlException("Sink data source of type: " + outputNode.getClass() + " is not supported.");
    }
}
Also used : KsqlBareOutputNode(io.confluent.ksql.planner.plan.KsqlBareOutputNode) KsqlStructuredDataOutputNode(io.confluent.ksql.planner.plan.KsqlStructuredDataOutputNode) OutputNode(io.confluent.ksql.planner.plan.OutputNode) KsqlBareOutputNode(io.confluent.ksql.planner.plan.KsqlBareOutputNode) SchemaKStream(io.confluent.ksql.structured.SchemaKStream) QueuedSchemaKStream(io.confluent.ksql.structured.QueuedSchemaKStream) KsqlStructuredDataOutputNode(io.confluent.ksql.planner.plan.KsqlStructuredDataOutputNode) QueuedSchemaKStream(io.confluent.ksql.structured.QueuedSchemaKStream) KsqlException(io.confluent.ksql.util.KsqlException) KsqlException(io.confluent.ksql.util.KsqlException)

Example 3 with KsqlStructuredDataOutputNode

use of io.confluent.ksql.planner.plan.KsqlStructuredDataOutputNode in project ksql by confluentinc.

the class KsqlResource method getStatementExecutionPlan.

private SourceDescription getStatementExecutionPlan(String queryId, Statement statement, String statementText, Map<String, Object> properties) throws KsqlException {
    if (queryId != null) {
        PersistentQueryMetadata metadata = ksqlEngine.getPersistentQueries().get(new QueryId(queryId));
        if (metadata == null) {
            throw new KsqlException(("Query with id:" + queryId + " does not exist, use SHOW QUERIES to view the full set of " + "queries."));
        }
        KsqlStructuredDataOutputNode outputNode = (KsqlStructuredDataOutputNode) metadata.getOutputNode();
        return new SourceDescription(outputNode, metadata.getStatementString(), metadata.getStatementString(), metadata.getTopologyDescription(), metadata.getExecutionPlan(), ksqlEngine.getTopicClient());
    }
    DdlCommandTask ddlCommandTask = ddlCommandTasks.get(statement.getClass());
    if (ddlCommandTask != null) {
        try {
            String executionPlan = ddlCommandTask.execute(statement, statementText, properties);
            return new SourceDescription("", "User-Evaluation", Collections.EMPTY_LIST, Collections.EMPTY_LIST, Collections.EMPTY_LIST, "QUERY", "", "", "", "", true, "", "", "", executionPlan, 0, 0);
        } catch (KsqlException ksqlException) {
            throw ksqlException;
        } catch (Throwable t) {
            throw new KsqlException("Cannot RUN execution plan for this statement, " + statement, t);
        }
    }
    throw new KsqlException("Cannot FIND execution plan for this statement:" + statement);
}
Also used : QueryId(io.confluent.ksql.query.QueryId) KsqlStructuredDataOutputNode(io.confluent.ksql.planner.plan.KsqlStructuredDataOutputNode) KsqlException(io.confluent.ksql.util.KsqlException) PersistentQueryMetadata(io.confluent.ksql.util.PersistentQueryMetadata) SourceDescription(io.confluent.ksql.rest.entity.SourceDescription)

Example 4 with KsqlStructuredDataOutputNode

use of io.confluent.ksql.planner.plan.KsqlStructuredDataOutputNode in project ksql by confluentinc.

the class QueryEngine method buildQueryLogicalPlan.

private PlanNode buildQueryLogicalPlan(String sqlExpression, final Query query, final MetaStore tempMetaStore) {
    final QueryAnalyzer queryAnalyzer = new QueryAnalyzer(tempMetaStore, ksqlEngine.getFunctionRegistry());
    final Analysis analysis = queryAnalyzer.analyze(sqlExpression, query);
    final AggregateAnalysis aggAnalysis = queryAnalyzer.analyzeAggregate(query, analysis);
    final PlanNode logicalPlan = new LogicalPlanner(analysis, aggAnalysis, ksqlEngine.getFunctionRegistry()).buildPlan();
    if (logicalPlan instanceof KsqlStructuredDataOutputNode) {
        KsqlStructuredDataOutputNode ksqlStructuredDataOutputNode = (KsqlStructuredDataOutputNode) logicalPlan;
        StructuredDataSource structuredDataSource = new KsqlStream(sqlExpression, ksqlStructuredDataOutputNode.getId().toString(), ksqlStructuredDataOutputNode.getSchema(), ksqlStructuredDataOutputNode.getKeyField(), ksqlStructuredDataOutputNode.getTimestampField() == null ? ksqlStructuredDataOutputNode.getTheSourceNode().getTimestampField() : ksqlStructuredDataOutputNode.getTimestampField(), ksqlStructuredDataOutputNode.getKsqlTopic());
        tempMetaStore.putTopic(ksqlStructuredDataOutputNode.getKsqlTopic());
        tempMetaStore.putSource(structuredDataSource.cloneWithTimeKeyColumns());
    }
    return logicalPlan;
}
Also used : StructuredDataSource(io.confluent.ksql.metastore.StructuredDataSource) KsqlStream(io.confluent.ksql.metastore.KsqlStream) PlanNode(io.confluent.ksql.planner.plan.PlanNode) LogicalPlanner(io.confluent.ksql.planner.LogicalPlanner) Analysis(io.confluent.ksql.analyzer.Analysis) AggregateAnalysis(io.confluent.ksql.analyzer.AggregateAnalysis) QueryAnalyzer(io.confluent.ksql.analyzer.QueryAnalyzer) AggregateAnalysis(io.confluent.ksql.analyzer.AggregateAnalysis) KsqlStructuredDataOutputNode(io.confluent.ksql.planner.plan.KsqlStructuredDataOutputNode)

Example 5 with KsqlStructuredDataOutputNode

use of io.confluent.ksql.planner.plan.KsqlStructuredDataOutputNode in project ksql by confluentinc.

the class KsqlResource method showQueries.

// Only shows queries running on the current machine, not across the entire cluster
private Queries showQueries(String statementText) {
    List<Queries.RunningQuery> runningQueries = new ArrayList<>();
    for (PersistentQueryMetadata persistentQueryMetadata : ksqlEngine.getPersistentQueries().values()) {
        KsqlStructuredDataOutputNode ksqlStructuredDataOutputNode = (KsqlStructuredDataOutputNode) persistentQueryMetadata.getOutputNode();
        runningQueries.add(new Queries.RunningQuery(persistentQueryMetadata.getStatementString(), ksqlStructuredDataOutputNode.getKafkaTopicName(), persistentQueryMetadata.getId()));
    }
    return new Queries(statementText, runningQueries);
}
Also used : Queries(io.confluent.ksql.rest.entity.Queries) ListQueries(io.confluent.ksql.parser.tree.ListQueries) ArrayList(java.util.ArrayList) KsqlStructuredDataOutputNode(io.confluent.ksql.planner.plan.KsqlStructuredDataOutputNode) PersistentQueryMetadata(io.confluent.ksql.util.PersistentQueryMetadata)

Aggregations

KsqlStructuredDataOutputNode (io.confluent.ksql.planner.plan.KsqlStructuredDataOutputNode)5 KsqlException (io.confluent.ksql.util.KsqlException)3 PersistentQueryMetadata (io.confluent.ksql.util.PersistentQueryMetadata)3 KsqlStream (io.confluent.ksql.metastore.KsqlStream)2 StructuredDataSource (io.confluent.ksql.metastore.StructuredDataSource)2 ListQueries (io.confluent.ksql.parser.tree.ListQueries)2 QueryId (io.confluent.ksql.query.QueryId)2 SourceDescription (io.confluent.ksql.rest.entity.SourceDescription)2 KsqlEngine (io.confluent.ksql.KsqlEngine)1 AggregateAnalysis (io.confluent.ksql.analyzer.AggregateAnalysis)1 Analysis (io.confluent.ksql.analyzer.Analysis)1 QueryAnalyzer (io.confluent.ksql.analyzer.QueryAnalyzer)1 CreateStreamCommand (io.confluent.ksql.ddl.commands.CreateStreamCommand)1 CreateTableCommand (io.confluent.ksql.ddl.commands.CreateTableCommand)1 DdlCommand (io.confluent.ksql.ddl.commands.DdlCommand)1 DdlCommandExec (io.confluent.ksql.ddl.commands.DdlCommandExec)1 DdlCommandResult (io.confluent.ksql.ddl.commands.DdlCommandResult)1 DropSourceCommand (io.confluent.ksql.ddl.commands.DropSourceCommand)1 DropTopicCommand (io.confluent.ksql.ddl.commands.DropTopicCommand)1 RegisterTopicCommand (io.confluent.ksql.ddl.commands.RegisterTopicCommand)1