xyiswinner commented on code in PR #22320:
URL: https://github.com/apache/spark/pull/22320#discussion_r1814408497


##########
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/plans/QueryPlan.scala:
##########
@@ -38,6 +38,20 @@ abstract class QueryPlan[PlanType <: QueryPlan[PlanType]] 
extends TreeNode[PlanT
    */
   def outputSet: AttributeSet = AttributeSet(output)
 
+  /**
+   * Returns output attributes with provided names.
+   * The length of provided names should be the same of the length of 
[[output]].
+   */
+  def outputWithNames(names: Seq[String]): Seq[Attribute] = {
+    // Save the output attributes to a variable to avoid duplicated function 
calls.
+    val outputAttributes = output
+    assert(outputAttributes.length == names.length,
+      "The length of provided names doesn't match the length of output 
attributes.")
+    outputAttributes.zipWithIndex.map { case (element, index) =>
+      element.withName(names(index))

Review Comment:
   In what situations would `outputAttributes.length != names.length` 
happen,would u  give me an example



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