You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@calcite.apache.org by GitBox <gi...@apache.org> on 2021/01/24 11:32:58 UTC

[GitHub] [calcite] wangjie-fourth commented on a change in pull request #2332: [CALCITE-4474] SqlSimpleParser inner Tokenizer should not recognize the sql of TokenType.ID or some keywords in some case

wangjie-fourth commented on a change in pull request #2332:
URL: https://github.com/apache/calcite/pull/2332#discussion_r563278326



##########
File path: core/src/test/java/org/apache/calcite/sql/test/SqlAdvisorTest.java
##########
@@ -1585,4 +1587,47 @@ private void testSimpleParserQuotedIdImpl() {
     assertSimplify(sql, simplified);
     assertComplete(sql, EXPR_KEYWORDS, Collections.singletonList("TABLE(a)"), DEPT_COLUMNS);
   }
+
+
+  @Test public void testFilterComment() {
+    // SqlSimpleParser.Tokenizer#nextToken() lines 401 - 423
+    // is used to recognize the sql of TokenType.ID or some keywords
+    // if a certain segment of characters is continuously composed of Token,
+    // the function of this code may be wrong
+    // E.g :
+    // (1)select * from a where price> 10.0--comment
+    // 【10.0--comment】should be recognize as TokenType.ID("10.0") and TokenType.COMMENT
+    // but it recognize as TokenType.ID("10.0--comment")
+    // (2)select * from a where column_b='/* this is not comment */'
+    // 【/* this is not comment */】should be recognize as
+    // TokenType.SQID("/* this is not comment */"), but it was not
+
+    final String baseOriginSql = "select * from a ";
+    final String baseResultSql = "SELECT * FROM a ";
+    String originSql;
+
+    // when SqlSimpleParser.Tokenizer#nextToken() method parse sql,
+    // ignore the  "--" after 10.0, this is a comment,
+    // but Tokenizer#nextToken() does not recognize it
+    originSql = baseOriginSql + "where price > 10.0-- this is comment "
+        + System.lineSeparator() + " -- comment ";
+    filterCommentHelper(originSql, baseResultSql + "WHERE price > 10.0");
+
+    originSql = baseOriginSql + "where column_b='/* this is not comment */'";
+    filterCommentHelper(originSql, baseResultSql + "WHERE column_b= '/* this is not comment */'");
+
+    originSql = baseOriginSql + "where column_b='2021 --this is not comment'";
+    filterCommentHelper(originSql, baseResultSql + "WHERE column_b= '2021 --this is not comment'");
+
+    originSql = baseOriginSql + "where column_b='2021--this is not comment'";
+    filterCommentHelper(originSql, baseResultSql + "WHERE column_b= '2021--this is not comment'");
+  }
+
+  private void filterCommentHelper(String originSql, String expectedSql) {

Review comment:
       thanks, it is done




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org