dssysolyatin commented on code in PR #4858:
URL: https://github.com/apache/calcite/pull/4858#discussion_r3068126100


##########
core/src/test/java/org/apache/calcite/test/SqlValidatorTest.java:
##########
@@ -8104,15 +8144,28 @@ void testGroupExpressionEquivalenceParams() {
         + "   overlaps (date '1-2-3', date '1-2-3')^\n"
         + "or false")
         .fails("(?s).*Cannot apply 'OVERLAPS' to arguments of type .*");
-    // row with 3 arguments as right argument to overlaps
+    // row with 3 arguments as right argument to overlaps.
+    // validateValues checks ROW structure before OVERLAPS validates,
+    // producing "Unequal number of entries in ROW expressions".
+    // SELECT produces the same error.
+    sql("select true or"
+        + " (date '1-2-3', date '1-2-3')"
+        + " overlaps ^(date '1-2-3', date '1-2-3', date '1-2-3')^"
+        + " or false from (values (0)) as t(x)")
+        .fails("(?s).*Unequal number of entries in ROW expressions.*");
     expr("true\n"
-        + "or ^(date '1-2-3', date '1-2-3')\n"
-        + "  overlaps (date '1-2-3', date '1-2-3', date '1-2-3')^\n"
+        + "or (date '1-2-3', date '1-2-3')\n"
+        + "  overlaps ^(date '1-2-3', date '1-2-3', date '1-2-3')^\n"
         + "or false")
-        .fails("(?s).*Cannot apply 'OVERLAPS' to arguments of type .*");
-    expr("^period (date '1-2-3', date '1-2-3')\n"
-        + "   overlaps (date '1-2-3', date '1-2-3', date '1-2-3')^")
-        .fails("(?s).*Cannot apply 'OVERLAPS' to arguments of type .*");
+        .fails("(?s).*Unequal number of entries in ROW expressions.*");

Review Comment:
   You are correct that the original query does not contain a ROW. However, 
during parsing, the OVERLAPS arguments are wrapped inside a ROW prior to any 
validation
   
   Currently, VALUES follows the proper execution order:
       a. Operand inference
       b. Operand validation
   
   Operand inference throws an exception, but it probably should not. It  
should probably simply leave the types unfilled. Operand validation would then 
fail with something like
   
   ```
   Cannot apply 'OVERLAPS' to arguments of type '<RECORDTYPE(DATE EXPR$0, DATE 
EXPR$1)> OVERLAPS <RECORDTYPE(DATE EXPR$0, DATE EXPR$1, DATE EXPR$2)>'. 
Supported form(s): '(<DT>, <DT>) OVERLAPS (<DT>, <DT>)'
   '(<DT>, <DT>) OVERLAPS (<DT>, <INTERVAL>)'
   '(<DT>, <INTERVAL>) OVERLAPS (<DT>, <DT>)'
   '(<DT>, <INTERVAL>) OVERLAPS (<DT>, <INTERVAL>)'
   ```
   
   Regarding the regression, I'm not sure it is regression, since SELECT 
already had the same behavior. Also `SELECT * FROM 
VALUES()/INSERT/UPDATE/DELETE` behave the same as they call `validateValues` 
which first:
     1. Does operand inference
     2. And then does operand validation
   
   Ironically, `VALUES` expression (when `VALUES` is top level node) were the 
exception.



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