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/07 05:42:06 UTC

[zeppelin] branch branch-0.9 updated: [ZEPPELIN-5299] Comment at end of query causes query to be ignored

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 9b3b0fa  [ZEPPELIN-5299] Comment at end of query causes query to be ignored
9b3b0fa is described below

commit 9b3b0fae9d5a87d9c7afb25c2e1ab7abb7b7e09c
Author: Jeff Zhang <zj...@apache.org>
AuthorDate: Fri Mar 26 13:50:25 2021 +0800

    [ZEPPELIN-5299] Comment at end of query causes query to be ignored
    
    ### What is this PR for?
    
    This is to fix the corner case that when the comment is at the end of query, the query will be skipped due to bug in SqlSplitter.
    This PR fix the bug in SqlSplitter and also add UT
    
    ### What type of PR is it?
    [Bug Fix ]
    
    ### Todos
    * [ ] - Task
    
    ### What is the Jira issue?
    * https://issues.apache.org/jira/browse/ZEPPELIN-5299
    
    ### How should this be tested?
    * UT is added
    
    ### 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 #4081 from zjffdu/ZEPPELIN-5299 and squashes the following commits:
    
    8a376b98b [Jeff Zhang] [ZEPPELIN-5299] Comment at end of query causes query to be ignored
    
    (cherry picked from commit e0e2ca5f8087d8f47a9fba4bfe736b53a565cb11)
    Signed-off-by: Jeff Zhang <zj...@apache.org>
---
 .../org/apache/zeppelin/interpreter/util/SqlSplitter.java |  4 ++++
 .../apache/zeppelin/interpreter/util/SqlSplitterTest.java | 15 +++++++++++++++
 2 files changed, 19 insertions(+)

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 755ef41..3ba4f52 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
@@ -93,6 +93,10 @@ public class SqlSplitter {
       if (singleLineComment && (character == '\n')) {
         singleLineComment = false;
         query.append(character);
+        if (index == (text.length() - 1) && !query.toString().trim().isEmpty()) {
+          // add query when it is the end of sql.
+          queries.add(query.toString());
+        }
         continue;
       }
 
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 aaf5f59..03cfef4 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
@@ -354,4 +354,19 @@ public class SqlSplitterTest {
     assertEquals("show tables", sqls.get(0));
     assertEquals("\ndescribe table_1", sqls.get(1));
   }
+
+  @Test
+  public void testCommentAtEnd() {
+    String sql = "\n" +
+            "select\n" +
+            "  'one'\n" +
+            "  , 'two' -- comment\n";
+    SqlSplitter sqlSplitter = new SqlSplitter();
+    List<String> sqls = sqlSplitter.splitSql(sql);
+    assertEquals(1, sqls.size());
+    assertEquals("\n" +
+            "select\n" +
+            "  'one'\n" +
+            "  , 'two' \n", sqls.get(0));
+  }
 }