Skip to content

Return non-Nullable results from COUNT(DISTINCT)#11593

Merged
alexey-milovidov merged 3 commits intomasterfrom
return-not-nullable-from-count-distinct
Jun 14, 2020
Merged

Return non-Nullable results from COUNT(DISTINCT)#11593
alexey-milovidov merged 3 commits intomasterfrom
return-not-nullable-from-count-distinct

Conversation

@alexey-milovidov
Copy link
Member

@alexey-milovidov alexey-milovidov commented Jun 11, 2020

Changelog category (leave one):

  • Not for changelog.

Superseded by #11661

Return non-Nullable result from COUNT(DISTINCT), and uniq aggregate functions family. If all passed values are NULL, return zero instead. This improves SQL compatibility.

Detailed description / Documentation draft:
If all arguments are NULL literals, we still return NULL.

@blinkov blinkov added the pr-backward-incompatible Pull request with backwards incompatible changes label Jun 11, 2020
else
return std::make_shared<AggregateFunctionNullUnary<false>>(nested_function, arguments, params);
{
if (serialize_flag)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This comment is just to leave a note for further readers.

Interesting that nobody noticed that this breaks the backward compatibility, seems nobody uses aggregate functions over Nullable (it is questionable, but still):

$ docker run yandex/clickhouse-server:20.4 clickhouse local -q "select maxState(toNullable(1))" | xxd
00000000: 0101 0a                                  ...
$ docker run yandex/clickhouse-server:20.5 clickhouse local -q "select maxState(toNullable(1))" | xxd
00000000: 0101 010a                                ....

return adapter;

bool return_type_is_nullable = !nested_function->returnDefaultWhenOnlyNull() && nested_function->getReturnType()->canBeInsideNullable();
bool serialize_flag = return_type_is_nullable || nested_function->returnDefaultWhenOnlyNull();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

By the way, @alexey-milovidov why the NULL flag is written if returnDefaultWhenOnlyNull == true?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It was probably left for backward compatibility.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

no-docs-needed pr-backward-incompatible Pull request with backwards incompatible changes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants