use of io.confluent.ksql.serde.RefinementInfo in project ksql by confluentinc.
the class RewrittenAnalysis method getWindowExpression.
@Override
public Optional<WindowExpression> getWindowExpression() {
final Optional<WindowExpression> windowExpression = original.getWindowExpression();
final Optional<RefinementInfo> refinementInfo = original.getRefinementInfo();
/* Return the original window expression, unless there is no grace period provided during a
suppression, in which case we rewrite the window expression to have a default grace period
of zero.
*/
if (!(windowExpression.isPresent() && !windowExpression.get().getKsqlWindowExpression().getGracePeriod().isPresent() && refinementInfo.isPresent() && refinementInfo.get().getOutputRefinement() == OutputRefinement.FINAL)) {
return original.getWindowExpression();
}
final WindowExpression window = original.getWindowExpression().get();
final KsqlWindowExpression ksqlWindowNew;
final KsqlWindowExpression ksqlWindowOld = window.getKsqlWindowExpression();
final Optional<NodeLocation> location = ksqlWindowOld.getLocation();
final Optional<WindowTimeClause> retention = ksqlWindowOld.getRetention();
if (ksqlWindowOld instanceof HoppingWindowExpression) {
ksqlWindowNew = new HoppingWindowExpression(location, ((HoppingWindowExpression) ksqlWindowOld).getSize(), ((HoppingWindowExpression) ksqlWindowOld).getAdvanceBy(), retention, Optional.of(zeroGracePeriod));
} else if (ksqlWindowOld instanceof TumblingWindowExpression) {
ksqlWindowNew = new TumblingWindowExpression(location, ((TumblingWindowExpression) ksqlWindowOld).getSize(), retention, Optional.of(zeroGracePeriod));
} else if (ksqlWindowOld instanceof SessionWindowExpression) {
ksqlWindowNew = new SessionWindowExpression(location, ((SessionWindowExpression) ksqlWindowOld).getGap(), retention, Optional.of(zeroGracePeriod));
} else {
throw new KsqlException("WINDOW type must be HOPPING, TUMBLING, or SESSION");
}
return Optional.of(new WindowExpression(original.getWindowExpression().get().getWindowName(), ksqlWindowNew));
}
use of io.confluent.ksql.serde.RefinementInfo in project ksql by confluentinc.
the class EngineExecutor method sourceTablePlan.
@SuppressFBWarnings(value = "NP_NULL_PARAM_DEREF_NONVIRTUAL")
private KsqlPlan sourceTablePlan(final ConfiguredStatement<?> statement) {
final CreateTable createTable = (CreateTable) statement.getStatement();
final CreateTableCommand ddlCommand = (CreateTableCommand) engineContext.createDdlCommand(statement.getStatementText(), (ExecutableDdlStatement) statement.getStatement(), config);
final Relation from = new AliasedRelation(new Table(createTable.getName()), createTable.getName());
// Only VALUE or HEADER columns must be selected from the source table. When running a
// pull query, the keys are added if selecting all columns.
final Select select = new Select(createTable.getElements().stream().filter(column -> !column.getConstraints().isKey() && !column.getConstraints().isPrimaryKey()).map(column -> new SingleColumn(new UnqualifiedColumnReferenceExp(column.getName()), Optional.of(column.getName()))).collect(Collectors.toList()));
// Source table need to keep emitting changes so every new record is materialized for
// pull query availability.
final RefinementInfo refinementInfo = RefinementInfo.of(OutputRefinement.CHANGES);
// This is a plan for a `select * from <source-table> emit changes` statement,
// without a sink topic to write the results. The query is just made to materialize the
// source table.
final Query query = new Query(Optional.empty(), select, from, Optional.empty(), Optional.empty(), Optional.empty(), Optional.empty(), Optional.empty(), Optional.of(refinementInfo), false, OptionalInt.empty());
// The source table does not exist in the current metastore, so a temporary metastore that
// contains only the source table is created here. This metastore is used later to create
// ExecutorsPlan.
final MutableMetaStore tempMetastore = new MetaStoreImpl(new InternalFunctionRegistry());
final Formats formats = ddlCommand.getFormats();
tempMetastore.putSource(new KsqlTable<>(statement.getStatementText(), createTable.getName(), ddlCommand.getSchema(), Optional.empty(), false, new KsqlTopic(ddlCommand.getTopicName(), KeyFormat.of(formats.getKeyFormat(), formats.getKeyFeatures(), Optional.empty()), ValueFormat.of(formats.getValueFormat(), formats.getValueFeatures())), true), false);
final ExecutorPlans plans = planQuery(statement, query, Optional.empty(), Optional.empty(), tempMetastore);
final KsqlBareOutputNode outputNode = (KsqlBareOutputNode) plans.logicalPlan.getNode().get();
final QueryPlan queryPlan = new QueryPlan(getSourceNames(outputNode), Optional.empty(), plans.physicalPlan.getPhysicalPlan(), plans.physicalPlan.getQueryId(), getApplicationId(plans.physicalPlan.getQueryId(), getSourceNames(outputNode)));
engineContext.createQueryValidator().validateQuery(config, plans.physicalPlan, engineContext.getQueryRegistry().getAllLiveQueries());
return KsqlPlan.queryPlanCurrent(statement.getStatementText(), Optional.of(ddlCommand), queryPlan);
}
Aggregations