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

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


The following commit(s) were added to refs/heads/master by this push:
     new e0e2ca5  [ZEPPELIN-5299] Comment at end of query causes query to be 
ignored
e0e2ca5 is described below

commit e0e2ca5f8087d8f47a9fba4bfe736b53a565cb11
Author: Jeff Zhang <zjf...@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 <zjf...@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
---
 .../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));
+  }
 }

Reply via email to