Skip to content

Commit

Permalink
[SPARK-37800][SQL] TreeNode.argString incorrectly formats arguments o…
Browse files Browse the repository at this point in the history
…f type Set[_]

### What changes were proposed in this pull request?

Fixing [SPARK-37800: TreeNode.argString incorrectly formats arguments of type Set\[_\]](https://issues.apache.org/jira/browse/SPARK-37800).

### Why are the changes needed?

On May 21, 2021, 746d80d by maropu introduced this bug.

### Does this PR introduce _any_ user-facing change?

No.

### How was this patch tested?

New test added to `TreeNodeSuite`.

Closes apache#35084 from ssimeonov/ss_spark37800.

Authored-by: Simeon Simeonov <sim@fastignite.com>
Signed-off-by: Wenchen Fan <wenchen@databricks.com>
(cherry picked from commit a8addd4)
Signed-off-by: Wenchen Fan <wenchen@databricks.com>
  • Loading branch information
ssimeonov authored and root committed Feb 22, 2022
1 parent 080da58 commit 1d45b9a
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -787,7 +787,7 @@ abstract class TreeNode[BaseType <: TreeNode[BaseType]] extends Product with Tre
truncatedString(seq.map(formatArg(_, maxFields)), "[", ", ", "]", maxFields)
case set: Set[_] =>
// Sort elements for deterministic behaviours
truncatedString(set.toSeq.map(formatArg(_, maxFields).sorted), "{", ", ", "}", maxFields)
truncatedString(set.toSeq.map(formatArg(_, maxFields)).sorted, "{", ", ", "}", maxFields)
case array: Array[_] =>
truncatedString(array.map(formatArg(_, maxFields)), "[", ", ", "]", maxFields)
case other =>
Expand All @@ -802,15 +802,9 @@ abstract class TreeNode[BaseType <: TreeNode[BaseType]] extends Product with Tre
case tn: TreeNode[_] => tn.simpleString(maxFields) :: Nil
case seq: Seq[Any] if seq.toSet.subsetOf(allChildren.asInstanceOf[Set[Any]]) => Nil
case iter: Iterable[_] if iter.isEmpty => Nil
case seq: Seq[_] =>
truncatedString(seq.map(formatArg(_, maxFields)), "[", ", ", "]", maxFields) :: Nil
case set: Set[_] =>
// Sort elements for deterministic behaviours
val sortedSeq = set.toSeq.map(formatArg(_, maxFields).sorted)
truncatedString(sortedSeq, "{", ", ", "}", maxFields) :: Nil
case array: Array[_] if array.isEmpty => Nil
case array: Array[_] =>
truncatedString(array.map(formatArg(_, maxFields)), "[", ", ", "]", maxFields) :: Nil
case xs @ (_: Seq[_] | _: Set[_] | _: Array[_]) =>
formatArg(xs, maxFields) :: Nil
case null => Nil
case None => Nil
case Some(null) => Nil
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -810,4 +810,12 @@ class TreeNodeSuite extends SparkFunSuite with SQLHelper {
fail("TreeNode.nodeName should not throw malformed class name error")
}
}

test("SPARK-37800: TreeNode.argString incorrectly formats arguments of type Set[_]") {
case class Node(set: Set[String], nested: Seq[Set[Int]]) extends LogicalPlan with LeafNode {
val output: Seq[Attribute] = Nil
}
val node = Node(Set("second", "first"), Seq(Set(3, 1), Set(2, 1)))
assert(node.argString(10) == "{first, second}, [{1, 3}, {1, 2}]")
}
}

0 comments on commit 1d45b9a

Please sign in to comment.