Skip to content

Commit c26379b

Browse files
zsxwingHyukjinKwon
authored andcommitted
[SPARK-27221][SQL] Improve the assert error message in TreeNode.parseToJson
## What changes were proposed in this pull request? When `TreeNode.parseToJson` may throw an assert error without any error message when a TreeNode is not implemented properly, and it's hard to find the bad TreeNode implementation. This PR adds the assert message to improve the error, like what `TreeNode.jsonFields` does. ## How was this patch tested? Jenkins Closes apache#24159 from zsxwing/SPARK-27221. Authored-by: Shixiong Zhu <[email protected]> Signed-off-by: Hyukjin Kwon <[email protected]>
1 parent 2e090ba commit c26379b

File tree

1 file changed

+3
-2
lines changed
  • sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/trees

1 file changed

+3
-2
lines changed

sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/trees/TreeNode.scala

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -630,7 +630,7 @@ abstract class TreeNode[BaseType <: TreeNode[BaseType]] extends Product {
630630
val fieldNames = getConstructorParameterNames(getClass)
631631
val fieldValues = productIterator.toSeq ++ otherCopyArgs
632632
assert(fieldNames.length == fieldValues.length, s"${getClass.getSimpleName} fields: " +
633-
fieldNames.mkString(", ") + s", values: " + fieldValues.map(_.toString).mkString(", "))
633+
fieldNames.mkString(", ") + s", values: " + fieldValues.mkString(", "))
634634

635635
fieldNames.zip(fieldValues).map {
636636
// If the field value is a child, then use an int to encode it, represents the index of
@@ -683,7 +683,8 @@ abstract class TreeNode[BaseType <: TreeNode[BaseType]] extends Product {
683683
try {
684684
val fieldNames = getConstructorParameterNames(p.getClass)
685685
val fieldValues = p.productIterator.toSeq
686-
assert(fieldNames.length == fieldValues.length)
686+
assert(fieldNames.length == fieldValues.length, s"${getClass.getSimpleName} fields: " +
687+
fieldNames.mkString(", ") + s", values: " + fieldValues.mkString(", "))
687688
("product-class" -> JString(p.getClass.getName)) :: fieldNames.zip(fieldValues).map {
688689
case (name, value) => name -> parseToJson(value)
689690
}.toList

0 commit comments

Comments
 (0)