SanJSp commented on code in PR #59596:
URL: https://github.com/apache/spark/pull/59596#discussion_r4629658420


##########
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/analysis/ResolveChangelogTable.scala:
##########
@@ -139,30 +139,48 @@ object ResolveChangelogTable extends Rule[LogicalPlan] {
         updatedRel = injectNetChangeComputation(
           updatedRel, rowIdExprs, table.changelogContext.computeUpdates())
       }
-      updatedRel
+      changelogOutput(updatedRel, rel, table.name())
 
     case rel @ StreamingRelationV2(_, _, table: ChangelogTable, _, _, _, _, _, 
_)
         if !table.resolved =>
       val changelog = table.changelog
       val resolvedRel = rel.copy(table = table.copy(resolved = true))
       var updatedRel: LogicalPlan = resolvedRel
-      if (table.requiresCarryoverRemoval || table.requiresUpdateDetection) {
+      val requiresRowLevelPostProcessing =
+        table.requiresCarryoverRemoval || table.requiresUpdateDetection
+      if (requiresRowLevelPostProcessing) {
         updatedRel = addStreamingRowLevelPostProcessing(
           resolvedRel, changelog, table.requiresCarryoverRemoval, 
table.requiresUpdateDetection)
       }
       if (table.requiresNetChangeCollapse) {
-        // Resolve the rowId references against `updatedRel` (the 
post-row-level plan)
-        // rather than the bare `resolvedRel`. The streaming row-level rewrite 
uses
-        // Aggregate + Generate(Inline), neither of which preserves the 
original
-        // attribute ExprIds for the inlined columns; resolving against 
`resolvedRel`
-        // yields stale ExprIds that fail post-analysis attribute resolution. 
The
-        // row-level rewrite preserves the connector's schema (column names) 
on its
-        // output, so name-based resolution against `updatedRel` recovers the 
right
-        // attributes regardless of any preceding wrapping.
+        // The row-level aggregate preserves row identity as scalar helper 
columns. Hidden
+        // metadata is not part of its buffered row payload and cannot be 
resolved afterwards.
+        val rowIdExprs = if (requiresRowLevelPostProcessing) {
+          changelog.rowId().indices.map { idx =>
+            getAttribute(updatedRel, NetChangesHelperColumns.rowIdColumn(idx))
+          }
+        } else {
+          
V2ExpressionUtils.resolveRefs[NamedExpression](changelog.rowId().toSeq, 
updatedRel)
+        }
         updatedRel = addStreamingNetChangeComputation(
-          updatedRel, changelog, table.changelogContext.computeUpdates())
+          updatedRel, rowIdExprs, table.changelogContext.computeUpdates())
       }
-      updatedRel
+      changelogOutput(updatedRel, rel, table.name())

Review Comment:
   Done.
   
   
https://github.com/apache/spark/blob/870133cd2c4ce6b032aab8711ed89b965d8214eb/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/analysis/NameStreamingSources.scala#L112-L122
   
   The existing alias case is preserved, and source names propagate through the 
changelog operators while batch initial-state inputs remain unchanged.



-- 
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]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to