You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@kyuubi.apache.org by "thomasg19930417 (via GitHub)" <gi...@apache.org> on 2023/02/18 03:07:47 UTC

[GitHub] [kyuubi] thomasg19930417 commented on a diff in pull request #4354: [KYUUBI#4343] Add support initializationSQLs from file

thomasg19930417 commented on code in PR #4354:
URL: https://github.com/apache/kyuubi/pull/4354#discussion_r1110536914


##########
externals/kyuubi-spark-sql-engine/src/main/scala/org/apache/kyuubi/engine/spark/KyuubiSparkUtil.scala:
##########
@@ -52,7 +59,49 @@ object KyuubiSparkUtil extends Logging {
     }
   }
 
+  def getInitializeSql(sparkSession: SparkSession, config: Seq[String]): Seq[String] = {
+
+    def getSqlTextFromFile(path: Option[String]): Seq[String] = {
+      path.map(filePath => {
+        var reader: BufferedReader = null
+        try {
+          info(s"========>load init sql from file: ${filePath}")
+          val engineInitSqlFilePath = new Path(filePath)
+          val hadoopConf = sparkSession.sparkContext.hadoopConfiguration
+          val fs: FileSystem = engineInitSqlFilePath.getFileSystem(hadoopConf)
+          if (fs.exists(engineInitSqlFilePath)) {
+            val sqlInputStream: FSDataInputStream = fs.open(engineInitSqlFilePath)
+            reader = new BufferedReader(new InputStreamReader(sqlInputStream))
+            // Filter out the sql using '--' comment
+            val sqlText = ListBuffer[String]()
+            Stream.continually(reader.readLine())
+              .takeWhile(null != _).filter(item => !item.startsWith("--") && item.length > 0)
+              .map(item => item.replace(";", "")).foreach(item => sqlText.append(item))

Review Comment:
   OK, I will modify it



-- 
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: notifications-unsubscribe@kyuubi.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@kyuubi.apache.org
For additional commands, e-mail: notifications-help@kyuubi.apache.org