Github user maropu commented on a diff in the pull request:
https://github.com/apache/spark/pull/22320#discussion_r214630233
--- 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 --
If #22311 merged, we don't need this function anymore? If so, IMHO it'd be
better to fix this issue in the `FileFormatWriter` side as a workaround?
---
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]