Added function accurateCastOrNull, allow different types inside IN subquery#16724
Conversation
src/Functions/FunctionsConversion.h
Outdated
There was a problem hiding this comment.
@alexey-milovidov not sure how to properly implement it for types without numeric limits, do we have some places where similar functionality implemented ? Thanks.
There was a problem hiding this comment.
The most simple is to implement numeric limits for bigints.
e8c11fe to
cddff6b
Compare
src/Core/Settings.cpp
Outdated
There was a problem hiding this comment.
@alexey-milovidov latest clang warning
Documents/ClickhouseBrowse/src/Core/Settings.cpp:20:1: error: stack frame size of 81128 bytes in lambda expression [-Werror,-Wframe-larger-than=]
IMPLEMENT_SETTINGS_TRAITS(SettingsTraits, LIST_OF_SETTINGS)
^
Documents/ClickhouseBrowse/src/Core/BaseSettings.h:817:46: note: expanded from macro 'IMPLEMENT_SETTINGS_TRAITS'
static const Accessor the_instance = [] \
Documents/ClickhouseBrowse/build$ clang++-11 --version
Ubuntu clang version 11.0.1-++20201103062930+ef4ffcafbb2-1~exp1~20201103053545.129
There was a problem hiding this comment.
Ok. Frame size limit is currently just a precaution.
b39d199 to
ed54023
Compare
|
@alexey-milovidov make test implementation of allowing different types inside in subquery. Please check 01600_select_in_different_types.sql and Set.cpp for a reference. |
There was a problem hiding this comment.
It's more aligned with the behaviour of standard SQL where weak typing is used.
We don't like weak typing :) But we tend to make our SQL more compatible with standard (through some settings or without). If this behaviour is "for free", let's keep it without introducing any settings.
There was a problem hiding this comment.
@alexey-milovidov It is for free for cases where we insert data in set from subselect, but when we make set from collection during AST visiting, we use convertFieldToType and it will throw exception if types does not match.
Example: SELECT '1' IN (1); will throw exception.
It does not make a lot of changes to update this behaviour. Should we fix it ?
There was a problem hiding this comment.
It looks inconsistent but let's keep it as is for now.
src/Core/AccurateComparison.h
Outdated
There was a problem hiding this comment.
What if we convert Float64's inf to Float32's inf or vice versa?
There was a problem hiding this comment.
There was a problem hiding this comment.
Will investigate floating point types conversion, seems like there is are a bunch of problems.
There was a problem hiding this comment.
Related to infinite conversions we can add special case above in addition to isNan.
There was a problem hiding this comment.
BTW, loss of precision due to Float64 -> Float32 conversion is Ok. For example,
toFloat32(0.1) IN (SELECT 0.1) should work.
There was a problem hiding this comment.
So, we can assume all the range of [Float32_lowest, Float32_max] in Float64 to be representable in Float32.
There was a problem hiding this comment.
(actually I'm not 100% sure about it)
There was a problem hiding this comment.
Updated. As discussed does not create specialization for case like toFloat32(0.1) IN (SELECT 0.1).
src/Core/AccurateComparison.h
Outdated
There was a problem hiding this comment.
Also what's about the case of conersion 1.5 to integer type (should return false)?
PS. Exact equality is Ok, so 1.000...1 also not equals to 1.
There was a problem hiding this comment.
Agreed equalsOp is required.
src/Interpreters/Set.cpp
Outdated
There was a problem hiding this comment.
BTW we also have obscure setting transform_null_in.
We can disable conversions (and resort to strict type checking) when it's enabled.
There was a problem hiding this comment.
Updated as we discussed, adding additional function accurateCast.
src/Interpreters/Set.cpp
Outdated
91f35e9 to
4bba2d3
Compare
deb60ce to
efe0525
Compare
1. Added accurateCast function. 2. Use accurateCast in Set during execute. 3. Added accurateCast tests. 4. Updated select_in_different_types tests.
efe0525 to
17b43ca
Compare
I hereby agree to the terms of the CLA available at: https://yandex.ru/legal/cla/?lang=en
Mentioned in #10290.
Mentioned in #10266.
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes to CHANGELOG.md):
Added function
accurateCastOrNull. This closes #10290. Add type conversions inx IN (subquery)expressions. This closes #10266.