You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@calcite.apache.org by "Julian Hyde (Jira)" <ji...@apache.org> on 2021/06/29 17:58:00 UTC
[jira] [Comment Edited] (CALCITE-4486) UNIQUE predicate
[ https://issues.apache.org/jira/browse/CALCITE-4486?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17371544#comment-17371544 ]
Julian Hyde edited comment on CALCITE-4486 at 6/29/21, 5:57 PM:
----------------------------------------------------------------
[~nobigo], It would be great if you solved this. Please assign it to yourself.
The parsing and validation are probably straightforward. I haven't thought much about the implementation, but we'd want to do it via rewrites as opposed to new relational operators.
Consider adding a method {{RexNode unique()}} method to {{RelBuilder}}. (There ought to be other methods for creating sub-queries, such as {{RexNode exists()}}, {{RexNode inQuery()}}, {{RexNode subQuery()}}, but there are not, so maybe creating all of these methods could be a separate JIRA case.)
If a uniqueness constraint indicates that the relation is already unique, {{UNIQUE}} should turn into {{TRUE}} at SQL-to-Rel time.
Be careful of NULL values. It is not safe to translate{code}UNIQUE (SELECT c FROM t){code} to {code}EXISTS (SELECT c FROM t GROUP BY c HAVING COUNT(*) > 1){code}because the latter will count NULL values.
was (Author: julianhyde):
[~nobigo], It would be great if you solved this. Please assign it to yourself.
> UNIQUE predicate
> ----------------
>
> Key: CALCITE-4486
> URL: https://issues.apache.org/jira/browse/CALCITE-4486
> Project: Calcite
> Issue Type: Bug
> Reporter: Julian Hyde
> Priority: Major
>
> Implement the UNIQUE predicate, as specified by the SQL standard.
> Example:
> {code:java}
> UNIQUE (SELECT publishedIn FROM Book
> WHERE authorId = 3)
> NOT UNIQUE (SELECT publishedIn FROM BOOK
> WHERE authorId = 3)
> {code}
> {{UNIQUE}} returns {{FALSE}} if the query returns two or more rows that do not include NULL values and are equal. Like {{EXISTS}}, it never returns {{UNKNOWN}}.
> More details at [JOOQ|https://www.jooq.org/doc/3.0/manual/sql-building/conditional-expressions/unique-predicate/].
--
This message was sent by Atlassian Jira
(v8.3.4#803005)