[CALCITE-7457] VALUES and SELECT produce different validation results for the same expression#4858
Conversation
|
|
||
| /** Test case for | ||
| * <a href="https://issues.apache.org/jira/browse/CALCITE-7457">[CALCITE-7457] | ||
| * Top-level VALUES and SELECT produce different validation results |
There was a problem hiding this comment.
The javadoc should be removed "Top-level"?
|
I have no other comments except for the above minor one, you can feel free to squash and merge. |
| 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.*"); |
There was a problem hiding this comment.
This is a regression, there is not ROW expression in the original program. The user will have difficulties finding the location of this error.
There was a problem hiding this 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:
- Does operand inference
- And then does operand validation
Ironically, VALUES expression (when VALUES is top level node) were the exception.
There was a problem hiding this comment.
Do you know why no checks were run in CI?
I would expect this error using ROW to appear in many more cases.
There was a problem hiding this comment.
Ah, this is because I add LGMT-will-merge-soon after first approve, it run CI one more time but with specific CI tests
There was a problem hiding this comment.
Can you please run all the tests to check that there aren't other tests affected by the ROW message?
There was a problem hiding this comment.
Those all ran before I added the LGTM-will-merge-soon label. Anyway, I made a small tweak based on #4858 (comment). Re-running now
| .columnType("DECIMAL(3, 1)"); | ||
| expr("values 1.0 + NULL") | ||
| .columnType("DECIMAL(2, 1)"); | ||
| .columnType("DECIMAL(3, 1)"); |
There was a problem hiding this comment.
Why should this inferred type be different?
Something is off.
There was a problem hiding this comment.
I explained above, in the SELECT section, why this happens. I'm not saying it's the correct behavior and I would expect that 1.0 + NULL = NULL with type DECIMAL(2,1) (common not null values type) in this case, but currently it works like that
There was a problem hiding this comment.
So you say SELECT 1.0 + NULL already was DECIMAL(3,1), but when used in VALUES the result was different?
There was a problem hiding this comment.
Right, if you open task description - https://issues.apache.org/jira/browse/CALCITE-7457. You can see test case for main branch
… for the same expression
3b86cfa to
2eb8f6d
Compare
|



Jira Link
CALCITE-7457
Changes Proposed
VALUESnow routes throughvalidateQuery, triggeringTableConstructorNamespace.validateImplvalidation (which callsvalidateValuesandinferUnknownTypes). The fix is a validateCall override in SqlValuesOperator.inferUnknownTypesno longer descends into subqueries (node.isA(SqlKind.QUERY)). Each query handles its owninferUnknownTypesduring its own validation.SELECTandVALUESbehaves the same way