MartijnVisser commented on code in PR #30173:
URL: https://github.com/apache/flink/pull/30173#discussion_r4782215569
##########
flink-table/flink-table-planner/src/main/java/org/apache/flink/table/planner/plan/optimize/ChangelogNormalizeRequirementResolver.java:
##########
@@ -87,10 +83,18 @@ public static boolean isRequired(
return true;
}
+ // ChangelogNormalize changes the metadata of deletes only: it
replaces each delete with the
+ // last stored row, which carries the metadata of the last upsert.
This matters only to a
+ // consumer of full deletes. Any other consumer relies only on the key
of a delete, whose
+ // metadata describes the delete itself (see DeleteKind#DELETE_BY_KEY).
+ if (requiredDeleteKind != DeleteKind.FULL_DELETE) {
Review Comment:
I think plans without a PTF change too: an upsert-to-upsert pipeline with
key-only deletes and a metadata column loses its ChangelogNormalize, so deletes
carry the tombstone's metadata instead of the last row's. Is that intended?
##########
flink-table/flink-table-planner/src/main/scala/org/apache/flink/table/planner/plan/optimize/program/FlinkChangelogModeInferenceProgram.scala:
##########
@@ -1674,8 +1679,108 @@ class FlinkChangelogModeInferenceProgram extends
FlinkOptimizeProgram[StreamOpti
}
/**
- * Removes the ChangelogNormalize and the exchange that only exists for
it. A filter condition
- * pushed into the ChangelogNormalize is kept as a Calc, so it still
filters the rows.
+ * Provides the input of a function that ignores retractions (see
+ * [[StaticArgumentTrait.IGNORE_RETRACTIONS]]).
+ *
+ * Such a function never needs UPDATE_BEFORE or DELETE rows, so a
+ * [[StreamPhysicalChangelogFilter]] that keeps only INSERT and
UPDATE_AFTER rows drops them in
+ * front of it. This drop is placed as low as possible, so that the
operators between it and the
+ * function also see only INSERT and UPDATE_AFTER rows:
+ * {{{
+ * Source -> ChangelogFilter -> Union -> Calc -> PTF
+ * Source -> ChangelogNormalize -> Join -> ChangelogFilter -> Calc -> PTF
+ * }}}
+ *
+ * The drop moves below operators that handle each row on its own (see
[[canPushDropBelow]]) and
+ * stops at the first other operator:
+ * - A source gets the drop on top of it.
+ * - A ChangelogNormalize is replaced by the drop, unless it deduplicates
+ * (table.exec.source.cdc-events-duplicate). A filter pushed into it
stays as a Calc above
+ * the drop.
+ * - A DropUpdateBefore is replaced by the drop.
+ * - A stateful operator, like a join or an aggregate, keeps its own
requirements on its
+ * inputs, and the drop goes on top of it.
+ *
+ * This saves the state of a ChangelogNormalize in front of the function,
and the input needs no
+ * upsert key. Filters on non-key columns, metadata columns and key-only
deletes don't need a
+ * ChangelogNormalize either.
+ */
+ private def dropRetractions(rel: StreamPhysicalRel):
Option[StreamPhysicalRel] = rel match {
+ case stateless if canPushDropBelow(stateless) =>
+ val newChildren =
+ stateless.getInputs.map(child =>
dropRetractions(child.asInstanceOf[StreamPhysicalRel]))
+ val allChildrenConverted = newChildren.forall(_.isDefined)
+ if (allChildrenConverted) {
+ Some(copyWithoutRetractions(stateless, newChildren.flatten.toList))
+ } else {
+ None
+ }
+
+ case normalize: StreamPhysicalChangelogNormalize if
!deduplicatesChanges(normalize) =>
Review Comment:
Without the ChangelogNormalize, an upsert repeating the last row of its key
now reaches the function, so `TO_CHANGELOG` with only inserts and updates in
`op_mapping` emits more rows than on master. Is that intended?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]