xuzifu666 commented on code in PR #4331:
URL: https://github.com/apache/calcite/pull/4331#discussion_r2061953499


##########
core/src/test/java/org/apache/calcite/rel/rel2sql/RelToSqlConverterTest.java:
##########
@@ -8268,22 +8268,27 @@ private void checkLiteral2(String expression, String 
expected) {
     sql(query2).ok(expected2);
   }
 
+  /** Test case for
+   * <a 
href="https://issues.apache.org/jira/browse/CALCITE-6982";>[CALCITE-6982]
+   * Removes cast from string also support with IS_NULL/IS_NOT_NULL</a>. */
   @Test void testCastInStringIntegerComparison() {
     final String query = "select \"employee_id\" "
         + "from \"foodmart\".\"employee\" "
-        + "where 10 = cast('10' as int) and \"birth_date\" = cast('1914-02-02' 
as date) or "
+        + "where 10 is distinct from cast('10' as int) and 10 = cast('10' as 
int) and \"birth_date\" = cast('1914-02-02' as date) or "

Review Comment:
   Hi, @NobiGo @mihaibudiu I had do more research about it in these days.
   
   Currently whether there is this pr or not, this sql(which would remove cast 
from string):
   ```
   select "employee_id" from "foodmart"."employee" where 10 = cast('10' as int)
   ```
   would convert to 
   ```
   SELECT "employee_id" FROM "foodmart"."employee" WHERE 10='10'
   ```
   because default calcite dialect would remove cast from string which we can 
refer to SqlDialect##supportsImplicitTypeCoercion,
   
   if operand is character type in cast would be string directly.
   
   **this pr is aim to remove unnecessary cast**, such as:
   ```
   select "employee_id" from "foodmart"."employee" where 10 is distinct from 
cast('10' as int)
   ```
   before the pr would convert to:
   ```
   SELECT \"employee_id\"\nFROM \"foodmart\".\"employee\"\nWHERE (10 IS NOT 
NULL OR CAST('10' AS INTEGER) IS NOT NULL) AND 10 = '10' IS NOT TRUE
   ```
   **we can find that all filter had remove cast from string except IS NULL/ IS 
NOT NULL.**
   this should be converted to:
   ```
   SELECT "employee_id" FROM "foodmart"."employee" WHERE (10 IS NOT NULL OR 
'10' IS NOT NULL) AND 10 = '10' IS NOT TRUE
   ```
   at the same time, if some special dialect such as postgresql, would not more 
cast if supportsImplicitTypeCoercion not permit type is Numberic, 
   this case also added to the new test case, it would be:
   ```
   SELECT "employee_id" WHERE (10 IS NOT NULL OR CAST('10' AS INTEGER) IS NOT 
NULL) AND 10 = CAST('10' AS INTEGER) IS NOT TRUE.
   ```
   
   Summarize that the pr is aim to resolve remove cast from string not thorough 
in IS NULL/IS NOT NULL condition.
   
   
   



-- 
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.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to