bowenliang123 commented on code in PR #5923:
URL: https://github.com/apache/kyuubi/pull/5923#discussion_r1437420468
##########
externals/kyuubi-spark-sql-engine/src/main/scala/org/apache/kyuubi/engine/spark/operation/ExecuteStatement.scala:
##########
@@ -180,21 +180,24 @@ class ExecuteStatement(
val sessionId = session.handle.identifier.toString
val savePath =
session.sessionManager.getConf.get(OPERATION_RESULT_SAVE_TO_FILE_DIR)
saveFileName = Some(s"$savePath/$engineId/$sessionId/$statementId")
- // Rename all col name to avoid duplicate columns
- val colName = range(0, result.schema.size).map(x => "col" + x)
-
- val codec = if (SPARK_ENGINE_RUNTIME_VERSION >= "3.2") "zstd" else
"zlib"
- // df.write will introduce an extra shuffle for the outermost limit,
and hurt performance
- if (resultMaxRows > 0) {
- result.toDF(colName: _*).limit(resultMaxRows).write
- .option("compression", codec).format("orc").save(saveFileName.get)
- } else {
- result.toDF(colName: _*).write
- .option("compression", codec).format("orc").save(saveFileName.get)
+ val saveFile = saveFileName.get
+ FileUtil.fullyDeleteOnExit(new File(saveFile))
+ val resultDfToSave: DataFrame = {
+ // Rename all col name to avoid duplicate columns
+ val df = resultDF.toDF(result.schema.indices.map(x => s"col_$x"): _*)
+ if (resultMaxRows > 0) {
+ // df.write will introduce an extra shuffle for the outermost
limit,
+ // and hurt performance
+ df.limit(resultMaxRows)
+ } else {
+ df
+ }
}
- info(s"Save result to $saveFileName")
+ val codec = if (SPARK_ENGINE_RUNTIME_VERSION >= "3.2") "zstd" else
"zlib"
+ resultDfToSave.write.option("compression",
codec).format("orc").save(saveFile)
+ info(s"Save result of statement $statementId to $saveFileName.get")
Review Comment:
OK, changed to use the `saveFile` variable directly.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]