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


##########
core/src/test/java/org/apache/calcite/rel/rel2sql/RelToSqlConverterTest.java:
##########
@@ -2804,6 +2804,69 @@ private SqlDialect nonOrdinalDialect() {
         .withPresto().ok(exptectedPresto);
   }
 
+  /** Test case for
+   * <a 
href="https://issues.apache.org/jira/browse/CALCITE-7042";>[CALCITE-7042]
+   * Trim function does not have idempotency simplification</a>. */
+  @Test void testTrimEliminated() {
+    // eliminate trim test cases as follow:
+    final String query = "SELECT TRIM(both 'a' from TRIM(both 'a' from 
\"brand_name\"))\n"
+        + "from \"foodmart\".\"product\"";
+    final String exptectedPresto = "SELECT TRIM(\"brand_name\", 'a')\n"
+        + "FROM \"foodmart\".\"product\"";
+    sql(query)
+        .withPresto().ok(exptectedPresto);
+
+    final String query1 = "SELECT TRIM(TRIM(\"brand_name\"))\n"
+        + "from \"foodmart\".\"product\"";
+    final String exptectedPresto1 = "SELECT TRIM(\"brand_name\")\n"
+        + "FROM \"foodmart\".\"product\"";
+    sql(query1)
+        .withPresto().ok(exptectedPresto1);
+
+    final String query2 = "SELECT TRIM(LEADING 'a' from TRIM(LEADING 'a' from 
\"brand_name\"))\n"
+        + "from \"foodmart\".\"product\"";
+    final String exptectedPresto2 = "SELECT LTRIM(\"brand_name\", 'a')\n"
+        + "FROM \"foodmart\".\"product\"";
+    sql(query2)
+        .withPresto().ok(exptectedPresto2);
+
+    final String query3 = "SELECT TRIM(TRAILING 'a' from TRIM(TRAILING 'a' 
from \"brand_name\"))\n"
+        + "from \"foodmart\".\"product\"";
+    final String exptectedPresto3 = "SELECT RTRIM(\"brand_name\", 'a')\n"
+        + "FROM \"foodmart\".\"product\"";
+    sql(query3)
+        .withPresto().ok(exptectedPresto3);
+
+    // not eliminate trim test cases as follow:
+    final String query4 = "SELECT TRIM(LEADING 'a' from 
TRIM(\"brand_name\"))\n"
+        + "from \"foodmart\".\"product\"";
+    final String exptectedPresto4 = "SELECT LTRIM(TRIM(\"brand_name\"), 'a')\n"
+        + "FROM \"foodmart\".\"product\"";
+    sql(query4)
+        .withPresto().ok(exptectedPresto4);
+
+    final String query5 = "SELECT TRIM(LEADING 'b' from TRIM(LEADING 'a' from 
\"brand_name\"))\n"
+        + "from \"foodmart\".\"product\"";
+    final String exptectedPresto5 = "SELECT LTRIM(LTRIM(\"brand_name\", 'a'), 
'b')\n"
+        + "FROM \"foodmart\".\"product\"";
+    sql(query5)
+        .withPresto().ok(exptectedPresto5);
+
+    final String query6 = "SELECT TRIM(LEADING 'a' from TRIM(BOTH 'a' from 
\"brand_name\"))\n"
+        + "from \"foodmart\".\"product\"";
+    final String exptectedPresto6 = "SELECT LTRIM(TRIM(\"brand_name\", 'a'), 
'a')\n"
+        + "FROM \"foodmart\".\"product\"";
+    sql(query6)
+        .withPresto().ok(exptectedPresto6);
+
+    final String query7 = "SELECT TRIM(TRIM(BOTH 'a' from \"brand_name\"))\n"

Review Comment:
   @mihaibudiu I had added more test about null illegal test cases, which would 
return NULL as expected. Thanks.



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