Skip to content

Fix logical assert in tupleElement() with default values - #51534

Merged
alexey-milovidov merged 3 commits into
ClickHouse:many-fixes-2from
rschu1ze:bug-51525
Jun 29, 2023
Merged

alexey-milovidov merged 3 commits into
ClickHouse:many-fixes-2from
rschu1ze:bug-51525

Conversation

@rschu1ze

@rschu1ze rschu1ze commented Jun 28, 2023 •

Copy link
Copy Markdown
Member

Closes #51525

(same as #51535 but against many-fixes-2)

This PR does two things (besides an extra commit with cosmetics):

  1. tupleElement() now returns the default value if the index argument is out-of-bounds and a default value is given (it previously threw an exception). This aligns the documented and expected behavior with the actual behavior. Note that we continue to throw an exception if the index argument is out-of-bounds and no default value is given.
  2. tupleElement() now allows default values of arbitrary type, fixing Fuzzer: Logical error in tupleElement() #51525 as a side effect. This logical error happened in a sanity check which made sure that an input value of Array type has the same size (element count) as the (Array) default value. There was some discussion about this in the original PR but I don't really understand why this restriction is necessary. On the one hand, lifting it simplifies the code + will allow useful statements like SELECT tupleElement([(1, 2), (3, 4)], 'no column name', 'invalid column'), on the other hand, operators tuple.index, tuple.name, array.index and array.name are not affected anyways as they don't use default values.

Changelog category (leave one):

  • Bug Fix (user-visible misbehavior in an official stable release)

Changelog entry (a user-readable short description of the changes that goes to CHANGELOG.md):

Fix a logical assert in "tupleElement()" with default values

@alexey-milovidov

Copy link
Copy Markdown
Member

Should it throw an exception if the index is out of bounds and there is no argument with a default value?
I think it should, because the tuple's dimensions are static.

@rschu1ze

Copy link
Copy Markdown
Member Author

If the index is out-of-bounds and no default arg is provided, we continue to throw an exception. This PR only fixes the situation that the index is out-of-bounds and a default arg is given. I clarified the PR message.

@alexey-milovidov
alexey-milovidov merged commit 9930fd4 into ClickHouse:many-fixes-2 Jun 29, 2023
@rschu1ze rschu1ze added the pr-backward-incompatible Pull request with backwards incompatible changes label Jun 29, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

pr-backward-incompatible Pull request with backwards incompatible changes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants