[ 
https://issues.apache.org/jira/browse/CALCITE-7678?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=18099803#comment-18099803
 ] 

Mihai Budiu commented on CALCITE-7678:
--------------------------------------

This is actually a minefield: SQL dialects do not agree on how ROW value 
equality is defined: some use three-valued logic for all ROW fields (NULL = 
NULL evaluates to NULL/UNKNOWN) and some use Boolean logic, i.e., IS NOT 
DISTINCT FROM (NULL = NULL evaluates to TRUE), and some simply forbid ROW 
equality.

Notice that equality is used in operations such as JOIN, DISTINCT, GROUP BY, 
UNION, IN, ANY. (Some of these use equality, some use IS NOT DISTINCT FROM, 
which seems to be the same in all dialects.)

This is generally an important question for all derived types, not just ROW, it 
applies to ARRAY, MAP, MULTISET, and ROW. The SQL standard mandates that 
ARRAY[NULL] = ARRAY[NULL]  evaluates to NULL, but in Calcite it evaluates to 
TRUE.

If you try to mix the standard semantics for ROWs and the Calcite semantics for 
ARRAY you get into very strange combinations, like a ROW ARRAY or a ROW with an 
ARRAY fields.

In a perfect world these behaviors would be guided by conformance flags.  So I 
am not entirely sure what the right solution is. (But the current 
implementation is neither of these.)

> Runtime equality for ROW values produces incorrect results
> ----------------------------------------------------------
>
>                 Key: CALCITE-7678
>                 URL: https://issues.apache.org/jira/browse/CALCITE-7678
>             Project: Calcite
>          Issue Type: Bug
>          Components: core
>    Affects Versions: 1.42.0
>            Reporter: Mihai Budiu
>            Priority: Minor
>
> GROUP BY, DISTINCT, JOIN, UNION, etc by ROW-typed values produces incorrect 
> results, because ROWs are compiled to Object[] and are compared by reference 
> instead of being compared by value.



--
This message was sent by Atlassian Jira
(v8.20.10#820010)

Reply via email to