This is an automated email from the ASF dual-hosted git repository.

chengpan pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-kyuubi.git


The following commit(s) were added to refs/heads/master by this push:
     new c080283  [KYUUBI #1080] Move stringifyException to Utils
c080283 is described below

commit c0802836719e24c4e53b6e208f9925f4415d3d21
Author: timothy65535 <[email protected]>
AuthorDate: Sun Sep 12 22:43:27 2021 +0800

    [KYUUBI #1080] Move stringifyException to Utils
    
    <!--
    Thanks for sending a pull request!
    
    Here are some tips for you:
      1. If this is your first time, please read our contributor guidelines: 
https://kyuubi.readthedocs.io/en/latest/community/contributions.html
      2. If the PR is related to an issue in 
https://github.com/apache/incubator-kyuubi/issues, add '[KYUUBI #XXXX]' in your 
PR title, e.g., '[KYUUBI #XXXX] Your PR title ...'.
      3. If the PR is unfinished, add '[WIP]' in your PR title, e.g., 
'[WIP][KYUUBI #XXXX] Your PR title ...'.
    -->
    
    ### _Why are the changes needed?_
    <!--
    Please clarify why the changes are needed. For instance,
      1. If you add a feature, you can talk about the use case of it.
      2. If you fix a bug, you can clarify why it is a bug.
    -->
    
    Move stringifyException from KyuubiSQLException to Utils, make it more 
general.
    
    ### _How was this patch tested?_
    - [ ] Add some test cases that check the changes thoroughly including 
negative and positive cases if possible
    
    - [ ] Add screenshots for manual tests if appropriate
    
    - [ ] [Run 
test](https://kyuubi.readthedocs.io/en/latest/develop_tools/testing.html#running-tests)
 locally before make a pull request
    
    Closes #1081 from timothy65535/ky-1080.
    
    Closes #1080
    
    ce3015d5 [timothy65535] [KYUUBI #1080] Move stringifyException to Utils
    
    Authored-by: timothy65535 <[email protected]>
    Signed-off-by: Cheng Pan <[email protected]>
---
 .../kyuubi/engine/spark/operation/SparkOperation.scala      |  4 ++--
 .../org/apache/spark/kyuubi/SparkSQLEngineListener.scala    |  3 +--
 .../main/scala/org/apache/kyuubi/KyuubiSQLException.scala   | 11 ++---------
 kyuubi-common/src/main/scala/org/apache/kyuubi/Utils.scala  | 13 ++++++++++++-
 .../operation/KyuubiOperationPerConnectionSuite.scala       |  5 +++--
 5 files changed, 20 insertions(+), 16 deletions(-)

diff --git 
a/externals/kyuubi-spark-sql-engine/src/main/scala/org/apache/kyuubi/engine/spark/operation/SparkOperation.scala
 
b/externals/kyuubi-spark-sql-engine/src/main/scala/org/apache/kyuubi/engine/spark/operation/SparkOperation.scala
index cc945f7..3a16ee4 100644
--- 
a/externals/kyuubi-spark-sql-engine/src/main/scala/org/apache/kyuubi/engine/spark/operation/SparkOperation.scala
+++ 
b/externals/kyuubi-spark-sql-engine/src/main/scala/org/apache/kyuubi/engine/spark/operation/SparkOperation.scala
@@ -25,7 +25,7 @@ import org.apache.hive.service.rpc.thrift.{TRowSet, 
TTableSchema}
 import org.apache.spark.sql.{Row, SparkSession}
 import org.apache.spark.sql.types.StructType
 
-import org.apache.kyuubi.KyuubiSQLException
+import org.apache.kyuubi.{KyuubiSQLException, Utils}
 import org.apache.kyuubi.engine.spark.FetchIterator
 import org.apache.kyuubi.engine.spark.operation.SparkOperation.TIMEZONE_KEY
 import org.apache.kyuubi.operation.{AbstractOperation, OperationState}
@@ -85,7 +85,7 @@ abstract class SparkOperation(spark: SparkSession, opType: 
OperationType, sessio
     case e: Throwable =>
       if (cancel && !spark.sparkContext.isStopped) 
spark.sparkContext.cancelJobGroup(statementId)
       state.synchronized {
-        val errMsg = KyuubiSQLException.stringifyException(e)
+        val errMsg = Utils.stringifyException(e)
         if (state == OperationState.TIMEOUT) {
           val ke = KyuubiSQLException(s"Timeout operating $opType: $errMsg")
           setOperationException(ke)
diff --git 
a/externals/kyuubi-spark-sql-engine/src/main/scala/org/apache/spark/kyuubi/SparkSQLEngineListener.scala
 
b/externals/kyuubi-spark-sql-engine/src/main/scala/org/apache/spark/kyuubi/SparkSQLEngineListener.scala
index 099b605..102930b 100644
--- 
a/externals/kyuubi-spark-sql-engine/src/main/scala/org/apache/spark/kyuubi/SparkSQLEngineListener.scala
+++ 
b/externals/kyuubi-spark-sql-engine/src/main/scala/org/apache/spark/kyuubi/SparkSQLEngineListener.scala
@@ -27,8 +27,8 @@ import org.apache.spark.SparkException
 import org.apache.spark.scheduler._
 
 import org.apache.kyuubi.KyuubiSparkUtils.KYUUBI_STATEMENT_ID_KEY
-import org.apache.kyuubi.KyuubiSQLException
 import org.apache.kyuubi.Logging
+import org.apache.kyuubi.Utils.stringifyException
 import org.apache.kyuubi.config.KyuubiConf._
 import org.apache.kyuubi.engine.spark.monitor.KyuubiStatementMonitor
 import org.apache.kyuubi.engine.spark.monitor.entity.KyuubiJobInfo
@@ -41,7 +41,6 @@ import org.apache.kyuubi.service.{Serverable, ServiceState}
  * @param server the corresponding engine
  */
 class SparkSQLEngineListener(server: Serverable) extends SparkListener with 
Logging {
-  import KyuubiSQLException.stringifyException
 
   // the conf of server is null before initialized, use lazy val here
   private lazy val deregisterExceptions: Seq[String] =
diff --git 
a/kyuubi-common/src/main/scala/org/apache/kyuubi/KyuubiSQLException.scala 
b/kyuubi-common/src/main/scala/org/apache/kyuubi/KyuubiSQLException.scala
index ec662ca..8136997 100644
--- a/kyuubi-common/src/main/scala/org/apache/kyuubi/KyuubiSQLException.scala
+++ b/kyuubi-common/src/main/scala/org/apache/kyuubi/KyuubiSQLException.scala
@@ -17,7 +17,6 @@
 
 package org.apache.kyuubi
 
-import java.io.{PrintWriter, StringWriter}
 import java.lang.reflect.{InvocationTargetException, 
UndeclaredThrowableException}
 import java.sql.SQLException
 
@@ -26,6 +25,8 @@ import scala.collection.JavaConverters._
 
 import org.apache.hive.service.rpc.thrift.{TStatus, TStatusCode}
 
+import org.apache.kyuubi.Utils.stringifyException
+
 /**
  * @param reason     a description of the exception
  * @param sqlState   an XOPEN or SQL:2003 code identifying the exception
@@ -175,14 +176,6 @@ object KyuubiSQLException {
     ex
   }
 
-  def stringifyException(e: Throwable): String = {
-    val stm = new StringWriter
-    val wrt = new PrintWriter(stm)
-    e.printStackTrace(wrt)
-    wrt.close()
-    stm.toString
-  }
-
   @tailrec
   def findCause(t: Throwable): Throwable = t match {
     case e @ (_: UndeclaredThrowableException | _: InvocationTargetException)
diff --git a/kyuubi-common/src/main/scala/org/apache/kyuubi/Utils.scala 
b/kyuubi-common/src/main/scala/org/apache/kyuubi/Utils.scala
index 09e32c8..c581f97 100644
--- a/kyuubi-common/src/main/scala/org/apache/kyuubi/Utils.scala
+++ b/kyuubi-common/src/main/scala/org/apache/kyuubi/Utils.scala
@@ -17,7 +17,7 @@
 
 package org.apache.kyuubi
 
-import java.io.{File, InputStreamReader, IOException}
+import java.io.{File, InputStreamReader, IOException, PrintWriter, 
StringWriter}
 import java.net.{Inet4Address, InetAddress, NetworkInterface}
 import java.nio.charset.StandardCharsets
 import java.nio.file.{Files, Path, Paths}
@@ -229,4 +229,15 @@ object Utils extends Logging {
   def getDateFromTimestamp(time: Long): String = {
     DateFormatUtils.format(time, "yyyyMMdd", TimeZone.getDefault)
   }
+
+  /**
+   * Make a string representation of the exception.
+   */
+  def stringifyException(e: Throwable): String = {
+    val stm = new StringWriter
+    val wrt = new PrintWriter(stm)
+    e.printStackTrace(wrt)
+    wrt.close()
+    stm.toString
+  }
 }
diff --git 
a/kyuubi-server/src/test/scala/org/apache/kyuubi/operation/KyuubiOperationPerConnectionSuite.scala
 
b/kyuubi-server/src/test/scala/org/apache/kyuubi/operation/KyuubiOperationPerConnectionSuite.scala
index 6ada31b..b0fc125 100644
--- 
a/kyuubi-server/src/test/scala/org/apache/kyuubi/operation/KyuubiOperationPerConnectionSuite.scala
+++ 
b/kyuubi-server/src/test/scala/org/apache/kyuubi/operation/KyuubiOperationPerConnectionSuite.scala
@@ -22,7 +22,8 @@ import java.sql.SQLException
 import org.apache.hive.service.rpc.thrift.{TExecuteStatementReq, 
TGetOperationStatusReq, TOperationState, TStatusCode}
 import org.scalatest.time.SpanSugar.convertIntToGrainOfTime
 
-import org.apache.kyuubi.{KyuubiSQLException, WithKyuubiServer}
+import org.apache.kyuubi.Utils
+import org.apache.kyuubi.WithKyuubiServer
 import org.apache.kyuubi.config.KyuubiConf
 
 /**
@@ -60,7 +61,7 @@ class KyuubiOperationPerConnectionSuite extends 
WithKyuubiServer with JDBCTestUt
         withJdbcStatement() { statement => // no-op
         }
       }
-      val verboseMessage = KyuubiSQLException.stringifyException(exception)
+      val verboseMessage = Utils.stringifyException(exception)
       assert(verboseMessage.contains("Failed to detect the root cause"))
       assert(verboseMessage.contains("The last line log"))
     }

Reply via email to