vlsi commented on a change in pull request #2332:
URL: https://github.com/apache/calcite/pull/2332#discussion_r563098592
##########
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
+
+ SqlSimpleParser simpleParser =
+ new SqlSimpleParser("_suggest_", SqlParser.Config.DEFAULT);
+
+ final String baseOriginSql = "select * from a ";
+ final String baseResultSql = "SELECT * FROM a ";
+ String originSql;
+ String actualSql;
+
+ // 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 \n"
+ + " -- comment ";
+ actualSql = simpleParser.simplifySql(originSql);
+ assertThat(actualSql, equalTo(baseResultSql + "WHERE price > 10.0"));
+
+ originSql = baseOriginSql + "where column_b='/* this is not comment */'";
+ actualSql = simpleParser.simplifySql(originSql);
+ assertThat(actualSql, equalTo(baseResultSql + "WHERE column_b= '/* this is
not comment */'"));
Review comment:
Please factor this out to a helper method that would take `originSql`,
and `expectedSql`.
Then the method should add `originSql`into the assertion message.
----------------------------------------------------------------
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:
[email protected]