lsm1 commented on code in PR #5591:
URL: https://github.com/apache/kyuubi/pull/5591#discussion_r1388071558


##########
externals/kyuubi-spark-sql-engine/src/main/scala/org/apache/kyuubi/engine/spark/operation/ExecuteStatement.scala:
##########
@@ -159,6 +160,25 @@ class ExecuteStatement(
         override def iterator: Iterator[Any] = 
incrementalCollectResult(resultDF)
       })
     } else {
+      val sparkSave = 
spark.conf.getOption(OPERATION_RESULT_SAVE_TO_FILE.key).map(_.toBoolean)
+        
.getOrElse(session.sessionManager.getConf.get(OPERATION_RESULT_SAVE_TO_FILE))
+      lazy val threshold =
+        
session.sessionManager.getConf.get(OPERATION_RESULT_SAVE_TO_FILE_THRESHOLD)
+      if (hasResultSet && sparkSave && shouldSaveResultToHdfs(resultMaxRows, 
threshold, result)) {
+        val sessionId = session.handle.identifier.toString
+        val savePath = 
session.sessionManager.getConf.get(OPERATION_RESULT_SAVE_TO_FILE_PATH)
+        val fileName = s"$savePath/$engineId/$sessionId/$statementId"
+        val colName = range(0, result.schema.size).map(x => "col" + x)
+        if (resultMaxRows > 0) {
+          result.toDF(colName: _*).limit(resultMaxRows).write

Review Comment:
   If the result has duplicate columns, we can not write it to file, so we 
rename all col name to avoid this case
   ```
   spark.sql("select 1 as a,2 as a").write("/filepath")
   
   org.apache.spark.sql.AnalysisException: Found duplicate column(s) when 
inserting into hdfs
   ```



-- 
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]

Reply via email to