Merge pull request #61249 from mkmkme/mkmkme/fix-has-function

Fix `has()` function with `Nullable` column
This commit is contained in:
Yarik Briukhovetskyi 2024-03-13 13:16:40 +01:00 committed by GitHub
commit 24d6dcb96b
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 60 additions and 2 deletions

View File

@ -1007,8 +1007,13 @@ private:
if (!(*null_map)[row])
continue;
}
else if (!applyVisitor(FieldVisitorAccurateEquals(), arr[i], value))
else
{
if (null_map && (*null_map)[row])
continue;
if (!applyVisitor(FieldVisitorAccurateEquals(), arr[i], value))
continue;
}
ConcreteAction::apply(data[row], i);

View File

@ -0,0 +1,14 @@
Nullable(UInt64), non-null array
1 1
\N 0
Non-nullable UInt64, nullable array
0 0
1 1
2 1
Nullable(UInt64), nullable array
0 0
\N 1
1 1
All NULLs
0 0
\N 1

View File

@ -0,0 +1,39 @@
DROP TABLE IF EXISTS 00662_has_nullable;
SELECT 'Nullable(UInt64), non-null array';
CREATE TABLE 00662_has_nullable(a Nullable(UInt64)) ENGINE = Memory;
INSERT INTO 00662_has_nullable VALUES (1), (Null);
SELECT a, has([0, 1], a) FROM 00662_has_nullable;
DROP TABLE 00662_has_nullable;
--------------------------------------------------------------------------------
SELECT 'Non-nullable UInt64, nullable array';
CREATE TABLE 00662_has_nullable(a UInt64) ENGINE = Memory;
INSERT INTO 00662_has_nullable VALUES (0), (1), (2);
SELECT a, has([NULL, 1, 2], a) FROM 00662_has_nullable;
DROP TABLE 00662_has_nullable;
--------------------------------------------------------------------------------
SELECT 'Nullable(UInt64), nullable array';
CREATE TABLE 00662_has_nullable(a Nullable(UInt64)) ENGINE = Memory;
INSERT INTO 00662_has_nullable VALUES (0), (Null), (1);
SELECT a, has([NULL, 1, 2], a) FROM 00662_has_nullable;
DROP TABLE 00662_has_nullable;
--------------------------------------------------------------------------------
SELECT 'All NULLs';
CREATE TABLE 00662_has_nullable(a Nullable(UInt64)) ENGINE = Memory;
INSERT INTO 00662_has_nullable VALUES (0), (Null);
SELECT a, has([NULL, NULL], a) FROM 00662_has_nullable;
DROP TABLE 00662_has_nullable;