Repository navigation
feat(function): tupleElement with default value - #38989
Conversation
| const Strings & getElementNames() const { return names; } | ||
|
|
||
| size_t getPositionByName(const String & name) const; | ||
| bool getPositionByName(const String & name, size_t & index) const; |
There was a problem hiding this comment.
I'd prefer to name this method tryGetPositionByName and make it return std::optional<size>. It's more a c++ way to do this and it's more consistent with other code in our codebase.
|
|
||
| private: | ||
| size_t getElementNum(const ColumnPtr & index_column, const DataTypeTuple & tuple) const | ||
| bool getElementNum(const ColumnPtr & index_column, const DataTypeTuple & tuple, size_t & index, const size_t argument_size) const |
There was a problem hiding this comment.
The same as with getPositionByName.
| ColumnNumbers getArgumentsThatAreAlwaysConstant() const override | ||
| { | ||
| return {1}; | ||
| return {1, 2}; |
There was a problem hiding this comment.
Why not allow to use regular columns as default arguments? It may be useful in some cases and doesn't require any changes in implementation.
| size_t index = 0; | ||
| if (!getElementNum(arguments[1].column, *tuple_type_concrete, index, arguments.size())) | ||
| { | ||
| return arguments[2].column; | ||
| } |
There was a problem hiding this comment.
In case of Array(Tuple)) it may work incorrectly. In that case we should return array with same sizes as other elements have, but now arbitrary value of any type may be returned.
So, in case of Array(Tuple)) we have to check that default value has Array type with the same number of dimension as the original column and check that it has the same offsets in all rows as the original column.
03d791c to
2405525
Compare
|
@CurtizJ The same layout as Dimension Layout
3: [[],[]] (offset: [2])
2: [[[],[]],[[]]] (offset: [2, 3])
1: [[[x, x, x],[x]],[[x]]] (offset: [3, 4, 5]) |
ba603b2 to
b720d77
Compare
|
Yes, you need to check offsets for each dimension. |
CurtizJ
left a comment
There was a problem hiding this comment.
In general LGTM. Please, fix style issue and I'll merge PR.
There was a problem hiding this comment.
By our code style else and else if should be placed on the next line.
ad4dcc5 to
4a276e6
Compare
Signed-off-by: lokax <[email protected]>
Signed-off-by: lokax <[email protected]>
Signed-off-by: lokax <[email protected]>
Signed-off-by: lokax <[email protected]>
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes to CHANGELOG.md):
Add the 3rd parameter to the tupleElement function and return it if tuple doesn't have a member. Only works if the 2nd parameter is of type String.
Closes #38872