[
https://issues.apache.org/jira/browse/CALCITE-4484?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17282889#comment-17282889
]
Julian Hyde commented on CALCITE-4484:
--------------------------------------
Work in progress:
[julianhyde/4484-unique-value|https://github.com/julianhyde/calcite/tree/4484-unique-value].
It turns out that {{UNIQUE_VALUE}} was not necessary for {{WITHIN DISTINCT}}.
We tried {{UNIQUE_VALUE}} but it executed inside an {{Aggregate}} with two
grouping sets \(x) and (x, y), we only needed the value for (x, y), but it
would throw when being computed for \(x). So we used a different strategy based
on {{$THROW_UNLESS(MIN\(x) IS NOT DISTINCT FROM MAX\(x), ...)}}.
> Add UNIQUE_VALUE(x) aggregate function, that throws if x is not unique
> ----------------------------------------------------------------------
>
> Key: CALCITE-4484
> URL: https://issues.apache.org/jira/browse/CALCITE-4484
> Project: Calcite
> Issue Type: Bug
> Reporter: Julian Hyde
> Priority: Major
>
> Add a {{UNIQUE_VALUE\(x)}} aggregate function, that throws if {{x}} is not
> unique.
> {{UNIQUE_VALUE\(x)}} would throw if {{x}} has values [1, 2], or has values
> [1, NULL]; but would not throw if x has values [1, 1, 1] or [] or [NULL,
> NULL]. Like {{ANY_VALUE}} it behaves as if {{RESPECT NULLS}} is specified.
> There are similar functions:
> * {{ANY_VALUE\(x)}} non-deterministically picks a value. (It is present in
> BigQuery, MySQL, Snowflake, MSSQL and perhaps others.)
> * {{SINGLE_VALUE\(x)}} returns the value of x if there is just one value
> (e.g. [1] or [NULL]), NULL if there are no values, throws if there is more
> than one value (e.g. [NULL, NULL] or [1, 1, 1] or [1, 2]). {{SINGLE_VALUE}}
> is in Calcite, no other DBs that I am aware of, not documented, but available
> through SQL. Calcite uses it internally to enforce scalar sub-queries.
> BigQuery has an internal function "{{$ANY_AND_CHECK\(x)}}" that is equivalent
> to {{UNIQUE_VALUE\(x)}}.
--
This message was sent by Atlassian Jira
(v8.3.4#803005)