spark git commit: [SPARK-13286] [SQL] add the next expression of SQLException as cause

2016-08-23 Thread davies
Repository: spark
Updated Branches:
  refs/heads/branch-2.0 d16f9a0b7 -> 811a2cef0


[SPARK-13286] [SQL] add the next expression of SQLException as cause

Some JDBC driver (for example PostgreSQL) does not use the underlying exception 
as cause, but have another APIs (getNextException) to access that, so it it's 
included in the error logging, making us hard to find the root cause, 
especially in batch mode.

This PR will pull out the next exception and add it as cause (if it's 
different) or suppressed (if there is another different cause).

Can't reproduce this on the default JDBC driver, so did not add a regression 
test.

Author: Davies Liu 

Closes #14722 from davies/keep_cause.

(cherry picked from commit 9afdfc94f49395e69a7959e881c19d787ce00c3e)
Signed-off-by: Davies Liu 


Project: http://git-wip-us.apache.org/repos/asf/spark/repo
Commit: http://git-wip-us.apache.org/repos/asf/spark/commit/811a2cef
Tree: http://git-wip-us.apache.org/repos/asf/spark/tree/811a2cef
Diff: http://git-wip-us.apache.org/repos/asf/spark/diff/811a2cef

Branch: refs/heads/branch-2.0
Commit: 811a2cef03647c5be29fef522c423921c79b1bc3
Parents: d16f9a0
Author: Davies Liu 
Authored: Tue Aug 23 09:45:13 2016 -0700
Committer: Davies Liu 
Committed: Tue Aug 23 09:47:23 2016 -0700

--
 .../sql/execution/datasources/jdbc/JdbcUtils.scala | 13 -
 1 file changed, 12 insertions(+), 1 deletion(-)
--


http://git-wip-us.apache.org/repos/asf/spark/blob/811a2cef/sql/core/src/main/scala/org/apache/spark/sql/execution/datasources/jdbc/JdbcUtils.scala
--
diff --git 
a/sql/core/src/main/scala/org/apache/spark/sql/execution/datasources/jdbc/JdbcUtils.scala
 
b/sql/core/src/main/scala/org/apache/spark/sql/execution/datasources/jdbc/JdbcUtils.scala
index 1328ac7..7a8b825 100644
--- 
a/sql/core/src/main/scala/org/apache/spark/sql/execution/datasources/jdbc/JdbcUtils.scala
+++ 
b/sql/core/src/main/scala/org/apache/spark/sql/execution/datasources/jdbc/JdbcUtils.scala
@@ -17,7 +17,7 @@
 
 package org.apache.spark.sql.execution.datasources.jdbc
 
-import java.sql.{Connection, Driver, DriverManager, PreparedStatement}
+import java.sql.{Connection, Driver, DriverManager, PreparedStatement, 
SQLException}
 import java.util.Properties
 
 import scala.collection.JavaConverters._
@@ -233,6 +233,17 @@ object JdbcUtils extends Logging {
 conn.commit()
   }
   committed = true
+} catch {
+  case e: SQLException =>
+val cause = e.getNextException
+if (e.getCause != cause) {
+  if (e.getCause == null) {
+e.initCause(cause)
+  } else {
+e.addSuppressed(cause)
+  }
+}
+throw e
 } finally {
   if (!committed) {
 // The stage must fail.  We got here through an exception path, so


-
To unsubscribe, e-mail: commits-unsubscr...@spark.apache.org
For additional commands, e-mail: commits-h...@spark.apache.org



spark git commit: [SPARK-13286] [SQL] add the next expression of SQLException as cause

2016-08-23 Thread davies
Repository: spark
Updated Branches:
  refs/heads/master 97d461b75 -> 9afdfc94f


[SPARK-13286] [SQL] add the next expression of SQLException as cause

## What changes were proposed in this pull request?

Some JDBC driver (for example PostgreSQL) does not use the underlying exception 
as cause, but have another APIs (getNextException) to access that, so it it's 
included in the error logging, making us hard to find the root cause, 
especially in batch mode.

This PR will pull out the next exception and add it as cause (if it's 
different) or suppressed (if there is another different cause).

## How was this patch tested?

Can't reproduce this on the default JDBC driver, so did not add a regression 
test.

Author: Davies Liu 

Closes #14722 from davies/keep_cause.


Project: http://git-wip-us.apache.org/repos/asf/spark/repo
Commit: http://git-wip-us.apache.org/repos/asf/spark/commit/9afdfc94
Tree: http://git-wip-us.apache.org/repos/asf/spark/tree/9afdfc94
Diff: http://git-wip-us.apache.org/repos/asf/spark/diff/9afdfc94

Branch: refs/heads/master
Commit: 9afdfc94f49395e69a7959e881c19d787ce00c3e
Parents: 97d461b
Author: Davies Liu 
Authored: Tue Aug 23 09:45:13 2016 -0700
Committer: Davies Liu 
Committed: Tue Aug 23 09:45:13 2016 -0700

--
 .../sql/execution/datasources/jdbc/JdbcUtils.scala   | 15 +--
 1 file changed, 13 insertions(+), 2 deletions(-)
--


http://git-wip-us.apache.org/repos/asf/spark/blob/9afdfc94/sql/core/src/main/scala/org/apache/spark/sql/execution/datasources/jdbc/JdbcUtils.scala
--
diff --git 
a/sql/core/src/main/scala/org/apache/spark/sql/execution/datasources/jdbc/JdbcUtils.scala
 
b/sql/core/src/main/scala/org/apache/spark/sql/execution/datasources/jdbc/JdbcUtils.scala
index a33c26d..cbd5046 100644
--- 
a/sql/core/src/main/scala/org/apache/spark/sql/execution/datasources/jdbc/JdbcUtils.scala
+++ 
b/sql/core/src/main/scala/org/apache/spark/sql/execution/datasources/jdbc/JdbcUtils.scala
@@ -17,7 +17,7 @@
 
 package org.apache.spark.sql.execution.datasources.jdbc
 
-import java.sql.{Connection, Driver, DriverManager, PreparedStatement}
+import java.sql.{Connection, Driver, DriverManager, PreparedStatement, 
SQLException}
 import java.util.Properties
 
 import scala.collection.JavaConverters._
@@ -289,7 +289,7 @@ object JdbcUtils extends Logging {
   }
   val stmt = insertStatement(conn, table, rddSchema, dialect)
   val setters: Array[JDBCValueSetter] = rddSchema.fields.map(_.dataType)
-  .map(makeSetter(conn, dialect, _)).toArray
+.map(makeSetter(conn, dialect, _)).toArray
 
   try {
 var rowCount = 0
@@ -322,6 +322,17 @@ object JdbcUtils extends Logging {
 conn.commit()
   }
   committed = true
+} catch {
+  case e: SQLException =>
+val cause = e.getNextException
+if (e.getCause != cause) {
+  if (e.getCause == null) {
+e.initCause(cause)
+  } else {
+e.addSuppressed(cause)
+  }
+}
+throw e
 } finally {
   if (!committed) {
 // The stage must fail.  We got here through an exception path, so


-
To unsubscribe, e-mail: commits-unsubscr...@spark.apache.org
For additional commands, e-mail: commits-h...@spark.apache.org