This is an automated email from the ASF dual-hosted git repository.
peacewong pushed a commit to branch dev-1.1.0-datasource
in repository https://gitbox.apache.org/repos/asf/incubator-linkis.git
The following commit(s) were added to refs/heads/dev-1.1.0-datasource by this
push:
new 9641def fix:apache#1358 (#1469)
9641def is described below
commit 9641defa5aa6e15e5b6a2aac760f930943d31a2a
Author: jianwei2 <[email protected]>
AuthorDate: Thu Feb 17 20:16:35 2022 +0800
fix:apache#1358 (#1469)
The following statement passes the test:
select * from xx where xx like '%abc;def%';
select * from xx where xx like '%abc;d"ef%';select * from xx where xx like
'%a;d"ef%';
select * from xx where xx like '%abc;d\;ef%'
Co-authored-by: weijian1 <[email protected]>
---
.../governance/common/paser/CodeParser.scala | 40 +++++++++-------------
1 file changed, 16 insertions(+), 24 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 ff637d7..d8662a1 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
@@ -196,11 +196,16 @@ class SQLCodeParser extends SingleCodeParser with Logging
{
val defaultLimit: Int = GovernanceCommonConf.ENGINE_DEFAULT_LIMIT.getValue
- private def findRealSemicolonIndex(tempCode: String):Array[Int] = {
- val realTempCode = if (!tempCode.endsWith(""";""")) tempCode + ";" else
tempCode
+ private def findRealSemicolonIndex(tempCode: String): Array[Int] = {
+ var realTempCode = if (!tempCode.endsWith(""";""")) tempCode + ";" else
tempCode
+ // replace \" or \' to AA(only as placeholders ) .
+ realTempCode = realTempCode.replace("""\"""", "AA").replace("""\'""", "AA")
+ val re = """(['"])(?:(?!\1).)*?\1""".r
val array = new ArrayBuffer[Int]()
- for(i <- 0 until realTempCode.length - 1){
- if ('\\' != realTempCode.charAt(i) && ';' == realTempCode.charAt(i + 1))
array += ( i + 1)
+ val uglyIndices = re.findAllMatchIn(realTempCode).map(m => (m.start,
m.end)).toList
+ for (i <- 0 until realTempCode.length) {
+ if (';' == realTempCode.charAt(i) && uglyIndices.forall(se => i < se._1
|| i >= se._2))
+ array += i
}
array.toArray
}
@@ -210,26 +215,13 @@ class SQLCodeParser extends SingleCodeParser with Logging
{
def appendStatement(sqlStatement: String): Unit = {
codeBuffer.append(sqlStatement)
}
- if (StringUtils.contains(code, specialSeparator)) {
- val indices = findRealSemicolonIndex(code)
- var oldIndex = 0
- indices.foreach{
- index => val singleCode = code.substring(oldIndex, index)
- oldIndex = index + 1
- if(StringUtils.isNotBlank(singleCode)) appendStatement(singleCode)
- }
- } else if (StringUtils.contains(code, separator)) {
- StringUtils.split(code, ";").foreach{
- case s if StringUtils.isBlank(s) =>
- case s if isSelectCmdNoLimit(s) => appendStatement(s);
- case s => appendStatement(s);
- }
- } else {
- code match {
- case s if StringUtils.isBlank(s) =>
- case s if isSelectCmdNoLimit(s) => appendStatement(s);
- case s => appendStatement(s);
- }
+ val indices = findRealSemicolonIndex(code)
+ var oldIndex = 0
+ indices.foreach {
+ index =>
+ val singleCode = code.substring(oldIndex, index)
+ oldIndex = index + 1
+ if (StringUtils.isNotBlank(singleCode)) appendStatement(singleCode)
}
codeBuffer.toArray
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]