LukaZdravic commented on code in PR #59267:
URL: https://github.com/apache/spark/pull/59267#discussion_r4285489880


##########
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/analysis/resolver/AsOfJoinResolver.scala:
##########
@@ -124,11 +132,62 @@ class AsOfJoinResolver(
         )
         cteRegistry.currentScope.tryPutWithCTE(
           unresolvedOperator = unresolvedAsOfJoin,
-          resolvedOperator = resolvedJoin
+          resolvedOperator = resolvedJoinWithOriginalOutput
         )
     }
   }
 
+  /**
+   * If the join uses a hidden column, wraps it in a [[Project]] that also 
keeps the hidden columns.
+   */
+  private def retainOriginalOutputIfHiddenColumnIsReferenced(
+      unresolvedAsOfJoin: AsOfJoin,
+      resolvedJoin: AsOfJoin,
+      leftNameScope: NameScope,
+      rightNameScope: NameScope): LogicalPlan = {
+    val originalOutput = AsOfJoin.computeOutput(
+      joinType = resolvedJoin.joinType,
+      leftOutput = leftNameScope.output,
+      rightOutput = rightNameScope.output
+    )
+    val originalOutputSet = AttributeSet(originalOutput)
+
+    if (resolvedJoin.references.subsetOf(originalOutputSet)) {
+      resolvedJoin
+    } else {
+      val qualifiedAccessOnlyColumns = AsOfJoin.computeOutput(
+        joinType = resolvedJoin.joinType,
+        leftOutput = leftNameScope.hiddenOutput.filter(_.qualifiedAccessOnly),
+        rightOutput = rightNameScope.hiddenOutput.filter(_.qualifiedAccessOnly)
+      )
+
+      operatorResolutionContextStack.current.baseOperator = Some(resolvedJoin)
+      Project(
+        withQualifiedAccessOnlyColumns(

Review Comment:
   It's better fixed in follow-up PR as it's a general problem on spark. Ticket 
: https://issues.apache.org/jira/browse/SPARK-60263. Thanks for reporting!



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