Github user cloud-fan commented on a diff in the pull request:
https://github.com/apache/spark/pull/22320#discussion_r214644907
--- Diff:
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))
+ }
+ }
+
--- End diff --
or make it a util function
---
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]