Search in sources :

Example 16 with StructuredDataSource

use of io.confluent.ksql.metastore.StructuredDataSource in project ksql by confluentinc.

the class QueryAnalyzerTest method shouldCreateAnalysisForSimpleQuery.

@Test
public void shouldCreateAnalysisForSimpleQuery() {
    final List<Statement> statements = ksqlParser.buildAst("select orderid from orders;", metaStore);
    final Analysis analysis = queryAnalyzer.analyze("sqlExpression", (Query) statements.get(0));
    final Pair<StructuredDataSource, String> fromDataSource = analysis.getFromDataSource(0);
    assertThat(analysis.getSelectExpressions(), equalTo(Collections.singletonList(new DereferenceExpression(new QualifiedNameReference(QualifiedName.of("ORDERS")), "ORDERID"))));
    assertThat(analysis.getFromDataSources().size(), equalTo(1));
    assertThat(fromDataSource.left, instanceOf(KsqlStream.class));
    assertThat(fromDataSource.right, equalTo("ORDERS"));
}
Also used : StructuredDataSource(io.confluent.ksql.metastore.StructuredDataSource) KsqlStream(io.confluent.ksql.metastore.KsqlStream) DereferenceExpression(io.confluent.ksql.parser.tree.DereferenceExpression) Statement(io.confluent.ksql.parser.tree.Statement) QualifiedNameReference(io.confluent.ksql.parser.tree.QualifiedNameReference) Test(org.junit.Test)

Example 17 with StructuredDataSource

use of io.confluent.ksql.metastore.StructuredDataSource in project ksql by confluentinc.

the class PhysicalPlanBuilder method buildPlanForStructuredOutputNode.

private QueryMetadata buildPlanForStructuredOutputNode(String sqlExpression, final SchemaKStream schemaKStream, final KsqlStructuredDataOutputNode outputNode, final String serviceId, final String persistanceQueryPrefix, final String statement) {
    if (metaStore.getTopic(outputNode.getKafkaTopicName()) == null) {
        metaStore.putTopic(outputNode.getKsqlTopic());
    }
    StructuredDataSource sinkDataSource;
    if (schemaKStream instanceof SchemaKTable) {
        SchemaKTable schemaKTable = (SchemaKTable) schemaKStream;
        sinkDataSource = new KsqlTable(sqlExpression, outputNode.getId().toString(), outputNode.getSchema(), schemaKStream.getKeyField(), outputNode.getTimestampField(), outputNode.getKsqlTopic(), outputNode.getId().toString() + ksqlConfig.get(KsqlConfig.KSQL_TABLE_STATESTORE_NAME_SUFFIX_CONFIG), schemaKTable.isWindowed());
    } else {
        sinkDataSource = new KsqlStream(sqlExpression, outputNode.getId().toString(), outputNode.getSchema(), schemaKStream.getKeyField(), outputNode.getTimestampField(), outputNode.getKsqlTopic());
    }
    if (updateMetastore) {
        metaStore.putSource(sinkDataSource.cloneWithTimeKeyColumns());
    }
    final QueryId queryId = sinkDataSource.getPersistentQueryId();
    final String applicationId = serviceId + persistanceQueryPrefix + queryId;
    KafkaStreams streams = buildStreams(builder, applicationId, ksqlConfig, overriddenStreamsProperties);
    Topology topology = builder.build();
    return new PersistentQueryMetadata(statement, streams, outputNode, schemaKStream.getExecutionPlan(""), queryId, (schemaKStream instanceof SchemaKTable) ? DataSource.DataSourceType.KTABLE : DataSource.DataSourceType.KSTREAM, applicationId, kafkaTopicClient, outputNode.getSchema(), sinkDataSource.getKsqlTopic(), topology);
}
Also used : SchemaKTable(io.confluent.ksql.structured.SchemaKTable) StructuredDataSource(io.confluent.ksql.metastore.StructuredDataSource) KsqlStream(io.confluent.ksql.metastore.KsqlStream) KafkaStreams(org.apache.kafka.streams.KafkaStreams) KsqlTable(io.confluent.ksql.metastore.KsqlTable) QueryId(io.confluent.ksql.query.QueryId) Topology(org.apache.kafka.streams.Topology) PersistentQueryMetadata(io.confluent.ksql.util.PersistentQueryMetadata)

Aggregations

StructuredDataSource (io.confluent.ksql.metastore.StructuredDataSource)17 KsqlStream (io.confluent.ksql.metastore.KsqlStream)8 KsqlException (io.confluent.ksql.util.KsqlException)7 AliasedRelation (io.confluent.ksql.parser.tree.AliasedRelation)4 Table (io.confluent.ksql.parser.tree.Table)4 KsqlTable (io.confluent.ksql.metastore.KsqlTable)3 KsqlTopic (io.confluent.ksql.metastore.KsqlTopic)3 StructuredDataSourceNode (io.confluent.ksql.planner.plan.StructuredDataSourceNode)3 Test (org.junit.Test)3 CreateTable (io.confluent.ksql.parser.tree.CreateTable)2 DropTable (io.confluent.ksql.parser.tree.DropTable)2 SelectItem (io.confluent.ksql.parser.tree.SelectItem)2 SingleColumn (io.confluent.ksql.parser.tree.SingleColumn)2 PlanNode (io.confluent.ksql.planner.plan.PlanNode)2 PlanNodeId (io.confluent.ksql.planner.plan.PlanNodeId)2 SchemaKTable (io.confluent.ksql.structured.SchemaKTable)2 Pair (io.confluent.ksql.util.Pair)2 ArrayList (java.util.ArrayList)2 Topology (org.apache.kafka.streams.Topology)2 MockSchemaRegistryClient (io.confluent.kafka.schemaregistry.client.MockSchemaRegistryClient)1