You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@linkis.apache.org by pe...@apache.org on 2022/04/27 11:47:39 UTC
[incubator-linkis] branch dev-1.1.1 updated: [Feature-2043] Rollback #1925, the SQL comment clearing logic in SQLCodeParser is duplicated with the SQL comment uninterceptor function (#2046)
This is an automated email from the ASF dual-hosted git repository.
peacewong pushed a commit to branch dev-1.1.1
in repository https://gitbox.apache.org/repos/asf/incubator-linkis.git
The following commit(s) were added to refs/heads/dev-1.1.1 by this push:
new 4adb0a70e [Feature-2043] Rollback #1925, the SQL comment clearing logic in SQLCodeParser is duplicated with the SQL comment uninterceptor function (#2046)
4adb0a70e is described below
commit 4adb0a70e47c9fa6d2241ff588a309a99171aa9e
Author: weixiao <le...@gmail.com>
AuthorDate: Wed Apr 27 19:47:32 2022 +0800
[Feature-2043] Rollback #1925, the SQL comment clearing logic in SQLCodeParser is duplicated with the SQL comment uninterceptor function (#2046)
* Rollback #1925, the SQL comment clearing logic in SQLCodeParser is duplicated with the SQL comment uninterceptor function.
* [Feature-2043] Cancel useless tests.
Co-authored-by: leo_jie <we...@aliyun.com>
---
.../governance/common/paser/CodeParser.scala | 14 ++--------
.../common/paser/SQLCodeParserTest.scala | 30 +++++-----------------
2 files changed, 9 insertions(+), 35 deletions(-)
diff --git a/linkis-computation-governance/linkis-computation-governance-common/src/main/scala/org/apache/linkis/governance/common/paser/CodeParser.scala b/linkis-computation-governance/linkis-computation-governance-common/src/main/scala/org/apache/linkis/governance/common/paser/CodeParser.scala
index 2e8a59386..037f84edd 100644
--- a/linkis-computation-governance/linkis-computation-governance-common/src/main/scala/org/apache/linkis/governance/common/paser/CodeParser.scala
+++ b/linkis-computation-governance/linkis-computation-governance-common/src/main/scala/org/apache/linkis/governance/common/paser/CodeParser.scala
@@ -216,31 +216,21 @@ class SQLCodeParser extends SingleCodeParser with Logging {
if (StringUtils.isBlank(code)) {
return codeBuffer.toArray
}
- val codeAfterClearComment = clearSqlComment(code)
def appendStatement(sqlStatement: String): Unit = {
codeBuffer.append(sqlStatement)
}
- val indices = findRealSemicolonIndex(codeAfterClearComment)
+ val indices = findRealSemicolonIndex(code)
var oldIndex = 0
indices.foreach {
index =>
- val singleCode = codeAfterClearComment.substring(oldIndex, index)
+ val singleCode = code.substring(oldIndex, index)
oldIndex = index + 1
if (StringUtils.isNotBlank(singleCode)) appendStatement(singleCode)
}
codeBuffer.toArray
}
- def clearSqlComment(code: String): String = {
- if (StringUtils.isBlank(code)) {
- return ""
- }
- val p = Pattern.compile("(?ms)('(?:''|[^'])*')|--.*?$|/\\*.*?\\*/")
- val sql = p.matcher(code).replaceAll("$1")
- sql.trim
- }
-
def isSelectCmdNoLimit(cmd: String): Boolean = {
var code = cmd.trim
if (!cmd.split("\\s+")(0).equalsIgnoreCase("select")) return false
diff --git a/linkis-computation-governance/linkis-computation-governance-common/src/test/scala/org/apache/linkis/governance/common/paser/SQLCodeParserTest.scala b/linkis-computation-governance/linkis-computation-governance-common/src/test/scala/org/apache/linkis/governance/common/paser/SQLCodeParserTest.scala
index 2ffe2f694..b38afe5db 100644
--- a/linkis-computation-governance/linkis-computation-governance-common/src/test/scala/org/apache/linkis/governance/common/paser/SQLCodeParserTest.scala
+++ b/linkis-computation-governance/linkis-computation-governance-common/src/test/scala/org/apache/linkis/governance/common/paser/SQLCodeParserTest.scala
@@ -20,37 +20,21 @@ package org.apache.linkis.governance.common.paser
import org.junit.jupiter.api.{DisplayName, Test}
import org.junit.jupiter.api.Assertions.assertTrue
-import java.util.regex.Pattern
-
class SQLCodeParserTest {
@Test
- @DisplayName("testParseSql")
- def testParseSql(): Unit = {
+ @DisplayName("testParseSqlWithSemicolon")
+ def testParseSqlWithSemicolon(): Unit = {
val parser = new SQLCodeParser
val sqlString: String =
"""
- |-- select device_id, client_id, stats_uv_day,
- |-- stats_uv_week,
- |-- stats_uv_month
- |-- from kbase.test1 limit 10;
- |-- select device_id,
- |-- stats_uv
- |-- from kbase.test1 limit 10;
- |select *
- |-- 这是一条注释
- |from test.test_table3
- |limit 10;
- |select * from test.leo_test
- |-- 这是注释;
- |/** 这也是注释 **/
- |limit 10
+ |select * from test.table1;
+ |select
+ | *
+ | from test.table2 where name like ';_'
|""".stripMargin
- // sqlString = "select * from test.leo_test"
- val p = Pattern.compile("(?ms)('(?:''|[^'])*')|--.*?$|/\\*.*?\\*/")
- // val p = Pattern.compile("(?ms)('(?:''|[^'])*')|--.*?$|//.*?$|/\\*.*?\\*/|#.*?$|")
- // val result = p.matcher(sqlString).replaceAll("$1")
val strings = parser.parse(sqlString)
assertTrue(strings.length == 2)
}
+
}
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@linkis.apache.org
For additional commands, e-mail: commits-help@linkis.apache.org