Skip to content

Commit

Permalink
[SPARK-18909][SQL] The error messages in `ExpressionEncoder.toRow/fro…
Browse files Browse the repository at this point in the history
…mRow` are too verbose

## What changes were proposed in this pull request?

In `ExpressionEncoder.toRow` and `fromRow`, we catch the exception and output `treeString` of serializer/deserializer expressions in the error message. However, encoder can be very complex and the serializer/deserializer expressions can be very large trees and blow up the log files(e.g. generate over 500mb logs for this single error message.) As a first attempt, this PR try to use `simpleString` instead.

**BEFORE**

```scala
scala> :paste
// Entering paste mode (ctrl-D to finish)

case class TestCaseClass(value: Int)
import spark.implicits._
Seq(TestCaseClass(1)).toDS().collect()

// Exiting paste mode, now interpreting.

java.lang.RuntimeException: Error while decoding: java.lang.NullPointerException
newInstance(class TestCaseClass)
+- assertnotnull(input[0, int, false], - field (class: "scala.Int", name: "value"), - root class: "TestCaseClass")
   +- input[0, int, false]

  at org.apache.spark.sql.catalyst.encoders.ExpressionEncoder.fromRow(ExpressionEncoder.scala:303)
...
```

**AFTER**

```scala
...
// Exiting paste mode, now interpreting.

java.lang.RuntimeException: Error while decoding: java.lang.NullPointerException
newInstance(class TestCaseClass)
  at org.apache.spark.sql.catalyst.encoders.ExpressionEncoder.fromRow(ExpressionEncoder.scala:303)
...
```

## How was this patch tested?

Manual.

Author: Dongjoon Hyun <[email protected]>

Closes apache#16701 from dongjoon-hyun/SPARK-18909-EXPR-ERROR.
  • Loading branch information
dongjoon-hyun authored and cloud-fan committed Feb 3, 2017
1 parent 20b4ca1 commit 52d4f61
Showing 1 changed file with 2 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,7 @@ case class ExpressionEncoder[T](
} catch {
case e: Exception =>
throw new RuntimeException(
s"Error while encoding: $e\n${serializer.map(_.treeString).mkString("\n")}", e)
s"Error while encoding: $e\n${serializer.map(_.simpleString).mkString("\n")}", e)
}

/**
Expand All @@ -300,7 +300,7 @@ case class ExpressionEncoder[T](
constructProjection(row).get(0, ObjectType(clsTag.runtimeClass)).asInstanceOf[T]
} catch {
case e: Exception =>
throw new RuntimeException(s"Error while decoding: $e\n${deserializer.treeString}", e)
throw new RuntimeException(s"Error while decoding: $e\n${deserializer.simpleString}", e)
}

/**
Expand Down

0 comments on commit 52d4f61

Please sign in to comment.