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 cc945f7ff..3a16ee408 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 099b605da..102930b7e 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 ec662ca3e..8136997cd 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 09e32c801..c581f9791 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 6ada31b64..b0fc125e0 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")) }