use of io.confluent.ksql.planner.plan.PlanBuildContext in project ksql by confluentinc.
the class SchemaKSourceFactory method buildTable.
private static SchemaKTable<?> buildTable(final PlanBuildContext buildContext, final DataSource dataSource, final Stacker contextStacker) {
final KeyFormat keyFormat = dataSource.getKsqlTopic().getKeyFormat();
if (keyFormat.isWindowed()) {
throw new IllegalArgumentException("windowed");
}
final SourceStep<KTableHolder<GenericKey>> step;
final int pseudoColumnVersionToUse = determinePseudoColumnVersionToUse(buildContext);
// If the old query has a v1 table step, continue to use it.
// See https://github.com/confluentinc/ksql/pull/7990
boolean useOldExecutionStepVersion = false;
if (buildContext.getPlanInfo().isPresent()) {
final Set<ExecutionStep<?>> sourceSteps = buildContext.getPlanInfo().get().getSources();
useOldExecutionStepVersion = sourceSteps.stream().anyMatch(executionStep -> executionStep instanceof TableSourceV1);
}
if (useOldExecutionStepVersion && pseudoColumnVersionToUse != SystemColumns.LEGACY_PSEUDOCOLUMN_VERSION_NUMBER) {
throw new IllegalStateException("TableSourceV2 was released in conjunction with pseudocolumn" + "version 1. Something has gone very wrong");
}
if (buildContext.getKsqlConfig().getBoolean(KsqlConfig.KSQL_ROWPARTITION_ROWOFFSET_ENABLED) && !useOldExecutionStepVersion) {
step = ExecutionStepFactory.tableSource(contextStacker, dataSource.getSchema(), dataSource.getKafkaTopicName(), Formats.from(dataSource.getKsqlTopic()), dataSource.getTimestampColumn(), InternalFormats.of(keyFormat, Formats.from(dataSource.getKsqlTopic()).getValueFormat()), pseudoColumnVersionToUse);
} else {
step = ExecutionStepFactory.tableSourceV1(contextStacker, dataSource.getSchema(), dataSource.getKafkaTopicName(), Formats.from(dataSource.getKsqlTopic()), dataSource.getTimestampColumn(), pseudoColumnVersionToUse);
}
return schemaKTable(buildContext, resolveSchema(buildContext, step, dataSource), dataSource.getKsqlTopic().getKeyFormat(), step);
}
use of io.confluent.ksql.planner.plan.PlanBuildContext in project ksql by confluentinc.
the class PhysicalPlanBuilder method buildPhysicalPlan.
public PhysicalPlan buildPhysicalPlan(final LogicalPlanNode logicalPlanNode, final QueryId queryId, final Optional<PlanInfo> oldPlanInfo) {
final OutputNode outputNode = logicalPlanNode.getNode().orElseThrow(() -> new IllegalArgumentException("Need an output node to build a plan"));
final PlanBuildContext buildContext = PlanBuildContext.of(ksqlConfig, serviceContext, functionRegistry, oldPlanInfo);
final SchemaKStream<?> resultStream = outputNode.buildStream(buildContext);
final LogicalSchema logicalSchema = outputNode.getSchema();
final LogicalSchema physicalSchema = resultStream.getSchema();
if (!logicalSchema.equals(physicalSchema)) {
throw new IllegalStateException("Logical and Physical schemas do not match!" + System.lineSeparator() + "Logical : " + logicalSchema + System.lineSeparator() + "Physical: " + physicalSchema);
}
return new PhysicalPlan(queryId, resultStream.getSourceStep());
}
Aggregations