You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@zeppelin.apache.org by zj...@apache.org on 2021/04/06 02:07:15 UTC

[zeppelin] branch branch-0.9 updated: [ZEPPELIN-5307] Ignore the single quote and double quote in sql comment

This is an automated email from the ASF dual-hosted git repository.

zjffdu pushed a commit to branch branch-0.9
in repository https://gitbox.apache.org/repos/asf/zeppelin.git


The following commit(s) were added to refs/heads/branch-0.9 by this push:
     new 00b6524  [ZEPPELIN-5307] Ignore the single quote and double quote in sql comment
00b6524 is described below

commit 00b65246f01b59042bffe6d8d29ebf6ea0cc4ee7
Author: Jeff Zhang <zj...@apache.org>
AuthorDate: Fri Apr 2 16:25:52 2021 +0800

    [ZEPPELIN-5307] Ignore the single quote and double quote in sql comment
    
    ### What is this PR for?
    
    This PR is to fix the bug of SqlSplitter when single/double quote in sql comment. UT is added.
    
    ### What type of PR is it?
    [Bug Fix]
    
    ### Todos
    * [ ] - Task
    
    ### What is the Jira issue?
    * https://issues.apache.org/jira/browse/ZEPPELIN-5307
    
    ### How should this be tested?
    * CI pass
    
    ### Screenshots (if appropriate)
    
    ### Questions:
    * Does the licenses files need update? No
    * Is there breaking changes for older versions? No
    * Does this needs documentation? No
    
    Author: Jeff Zhang <zj...@apache.org>
    
    Closes #4083 from zjffdu/ZEPPELIN-5307 and squashes the following commits:
    
    7a02bd775 [Jeff Zhang] address comment
    b8e6b20f7 [Jeff Zhang] [ZEPPELIN-5307] Ignore the single quote and double quote in sql comment
    
    (cherry picked from commit 71a8c0dffaba1ea7ad72b802170a6a654671b205)
    Signed-off-by: Jeff Zhang <zj...@apache.org>
---
 .../zeppelin/interpreter/util/SqlSplitter.java     |  4 ++--
 .../zeppelin/interpreter/util/SqlSplitterTest.java | 24 ++++++++++++++++++++++
 2 files changed, 26 insertions(+), 2 deletions(-)

diff --git a/zeppelin-interpreter/src/main/java/org/apache/zeppelin/interpreter/util/SqlSplitter.java b/zeppelin-interpreter/src/main/java/org/apache/zeppelin/interpreter/util/SqlSplitter.java
index 1fee950..755ef41 100644
--- a/zeppelin-interpreter/src/main/java/org/apache/zeppelin/interpreter/util/SqlSplitter.java
+++ b/zeppelin-interpreter/src/main/java/org/apache/zeppelin/interpreter/util/SqlSplitter.java
@@ -102,7 +102,7 @@ public class SqlSplitter {
         multiLineComment = false;
       }
 
-      if (character == '\'') {
+      if (character == '\'' && !(singleLineComment || multiLineComment)) {
         if (singleQuoteString) {
           singleQuoteString = false;
         } else if (!doubleQuoteString) {
@@ -110,7 +110,7 @@ public class SqlSplitter {
         }
       }
 
-      if (character == '"') {
+      if (character == '"' && !(singleLineComment || multiLineComment)) {
         if (doubleQuoteString && index > 0) {
           doubleQuoteString = false;
         } else if (!singleQuoteString) {
diff --git a/zeppelin-interpreter/src/test/java/org/apache/zeppelin/interpreter/util/SqlSplitterTest.java b/zeppelin-interpreter/src/test/java/org/apache/zeppelin/interpreter/util/SqlSplitterTest.java
index 00fa5fd..aaf5f59 100644
--- a/zeppelin-interpreter/src/test/java/org/apache/zeppelin/interpreter/util/SqlSplitterTest.java
+++ b/zeppelin-interpreter/src/test/java/org/apache/zeppelin/interpreter/util/SqlSplitterTest.java
@@ -330,4 +330,28 @@ public class SqlSplitterTest {
     assertEquals(1, sqls.size());
     assertEquals("select a \n from table_1", sqls.get(0));
   }
+
+  @Test
+  public void testQuoteInComment() {
+    SqlSplitter sqlSplitter = new SqlSplitter();
+    List<String> sqls = sqlSplitter.splitSql("show tables;-- comment_1'\ndescribe table_1");
+    assertEquals(2, sqls.size());
+    assertEquals("show tables", sqls.get(0));
+    assertEquals("\ndescribe table_1", sqls.get(1));
+
+    sqls = sqlSplitter.splitSql("show tables;-- comment_1\"\ndescribe table_1");
+    assertEquals(2, sqls.size());
+    assertEquals("show tables", sqls.get(0));
+    assertEquals("\ndescribe table_1", sqls.get(1));
+
+    sqls = sqlSplitter.splitSql("show tables;/* comment_1' */\ndescribe table_1");
+    assertEquals(2, sqls.size());
+    assertEquals("show tables", sqls.get(0));
+    assertEquals("\ndescribe table_1", sqls.get(1));
+
+    sqls = sqlSplitter.splitSql("show tables;/* comment_1\" */\ndescribe table_1");
+    assertEquals(2, sqls.size());
+    assertEquals("show tables", sqls.get(0));
+    assertEquals("\ndescribe table_1", sqls.get(1));
+  }
 }