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());
}
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.");
}
}
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);
}
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;
}
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);
}
Aggregations