[ 
https://issues.apache.org/jira/browse/KYLIN-3620?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16661810#comment-16661810
 ] 

ASF GitHub Bot commented on KYLIN-3620:
---------------------------------------

shaofengshi closed pull request #302: KYLIN-3620 resolve "--" is treated as 
comment marker between singe qu…
URL: https://github.com/apache/kylin/pull/302
 
 
   

This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:

As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):

diff --git a/query/src/main/java/org/apache/kylin/query/util/QueryUtil.java 
b/query/src/main/java/org/apache/kylin/query/util/QueryUtil.java
index 1e7498b511..5aad5e0e26 100644
--- a/query/src/main/java/org/apache/kylin/query/util/QueryUtil.java
+++ b/query/src/main/java/org/apache/kylin/query/util/QueryUtil.java
@@ -184,7 +184,7 @@ public static boolean isSelectStatement(String sql) {
 
     public static String removeCommentInSql(String sql1) {
         // match two patterns, one is "-- comment", the other is "/* comment 
*/"
-        final String[] commentPatterns = new String[] { "--[^\r\n]*", 
"/\\*[\\s\\S]*?\\*/" };
+        final String[] commentPatterns = new String[]{"--(?!.*\\*/).*?[\r\n]", 
"/\\*(.|\r|\n)*?\\*/"};
 
         for (int i = 0; i < commentPatterns.length; i++) {
             sql1 = sql1.replaceAll(commentPatterns[i], "");
diff --git a/query/src/test/java/org/apache/kylin/query/util/QueryUtilTest.java 
b/query/src/test/java/org/apache/kylin/query/util/QueryUtilTest.java
index bf6f8363be..0b04e6d306 100644
--- a/query/src/test/java/org/apache/kylin/query/util/QueryUtilTest.java
+++ b/query/src/test/java/org/apache/kylin/query/util/QueryUtilTest.java
@@ -169,10 +169,10 @@ public void testForceLimit() {
     public void testRemoveCommentInSql() {
 
         String originSql = "select count(*) from test_kylin_fact where price > 
10.0";
+        String originSql2 = "select count(*) from test_kylin_fact where 
TEST_COLUMN != 'not--a comment'";
 
         {
             String sqlWithComment = "-- comment \n" + originSql;
-
             Assert.assertEquals(originSql, 
QueryUtil.removeCommentInSql(sqlWithComment));
         }
 
@@ -223,9 +223,57 @@ public void testRemoveCommentInSql() {
         }
 
         {
-            String sqlWithComment = "/* comment1 * \ncomment2 */ -- comment 
3\n" + originSql + "-- comment 5";
+            String sqlWithComment = "/* comment1 * \ncomment2 */ -- comment 
3\n" + originSql + "-- comment 5\n";
             Assert.assertEquals(originSql, 
QueryUtil.removeCommentInSql(sqlWithComment));
         }
+
+        {
+            String sqlWithComment2 = "/* comment1 * \ncomment2 */ -- comment 
5\n" + originSql2 + "/* comment3 / comment4 */";
+            Assert.assertEquals(originSql2, 
QueryUtil.removeCommentInSql(sqlWithComment2));
+        }
+
+        {
+            String sqlWithComment2 = "/* comment1 * comment2 */ /* comment3 / 
comment4 */ -- comment 5\n" + originSql2;
+            Assert.assertEquals(originSql2, 
QueryUtil.removeCommentInSql(sqlWithComment2));
+        }
+
+        {
+            String sqlWithComment2 = "/* comment1 * comment2 */ " + originSql2;
+            Assert.assertEquals(originSql2, 
QueryUtil.removeCommentInSql(sqlWithComment2));
+        }
+
+        {
+            String sqlWithComment2 = "/* comment1/comment2 */ " + originSql2;
+            Assert.assertEquals(originSql2, 
QueryUtil.removeCommentInSql(sqlWithComment2));
+        }
+
+        {
+            String sqlWithComment2 = "-- \n -- comment \n" + originSql2;
+            Assert.assertEquals(originSql2, 
QueryUtil.removeCommentInSql(sqlWithComment2));
+        }
+
+        {
+            String sqlWithComment2 = "-- comment \n" + originSql2;
+            Assert.assertEquals(originSql2, 
QueryUtil.removeCommentInSql(sqlWithComment2));
+        }
+
+        {
+            String sqlWithComment2 = "-- comment \n -- comment\n" + originSql2;
+            Assert.assertEquals(originSql2, 
QueryUtil.removeCommentInSql(sqlWithComment2));
+        }
+
+        String content = "        --  One-line comment and /**range\n" +
+                "/*\n" +
+                "Multi-line comment\r\n" +
+                "--  Multi-line comment*/\n" +
+                "select price as " +
+                "/*\n" +
+                "Multi-line comment\r\n" +
+                "--  Multi-line comment*/\n" +
+                "revenue from /*One-line comment-- One-line comment*/ 
v_lineitem;";
+        String expectedContent = "select price as revenue from  v_lineitem;";
+        String trimmedContent = 
QueryUtil.removeCommentInSql(content).replaceAll("\n", "").trim();
+        Assert.assertEquals(trimmedContent, expectedContent);
     }
 
     @Test


 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
[email protected]


> "--" should not be a comment marker use between single quotes in SQL
> --------------------------------------------------------------------
>
>                 Key: KYLIN-3620
>                 URL: https://issues.apache.org/jira/browse/KYLIN-3620
>             Project: Kylin
>          Issue Type: Bug
>          Components: Query Engine
>    Affects Versions: v2.4.1
>            Reporter: Scott Fan
>            Assignee: Lijun Cao
>            Priority: Major
>             Fix For: v2.6.0
>
>
> Hi,
> When I exec a SQL like below, there was an error.
> SELECT * FROM TABLEA WHERE NAME='Jason--Arthur'
> Seems like KYLIN use  the – as a comment marker.
> It should not be that between single quotes, I think.
>   
>  Even I send a REST POST contains SQL like that, or do an ODBC query, there 
> was an error too.
> You may tell me that I can use a \ as escape, but I can't change the SQL 
> generated by BI tools like tableau.  
> Thanks
>   



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)

Reply via email to