fix asof join on nulls

This commit is contained in:
vdimir 2024-07-18 11:31:23 +00:00
parent 7a5e48486f
commit 85714e7d7e
No known key found for this signature in database
GPG Key ID: 6EE4CE2BEDC51862
3 changed files with 88 additions and 7 deletions

View File

@ -257,8 +257,14 @@ JoinKeyRow::JoinKeyRow(const FullMergeJoinCursor & cursor, size_t pos)
new_col->insertFrom(*col, pos);
row.push_back(std::move(new_col));
}
if (const auto * asof_column = cursor.getAsofColumn())
if (const IColumn * asof_column = cursor.getAsofColumn())
{
if (const auto * nullable_asof_column = checkAndGetColumn<ColumnNullable>(asof_column))
{
/// We save matched column, and since NULL do not match anything, we can't use it as a key
chassert(!nullable_asof_column->isNullAt(pos));
asof_column = nullable_asof_column->getNestedColumnPtr().get();
}
auto new_col = asof_column->cloneEmpty();
new_col->insertFrom(*asof_column, pos);
row.push_back(std::move(new_col));
@ -1174,7 +1180,6 @@ IMergingAlgorithm::Status MergeJoinAlgorithm::merge()
if (!cursors[1]->cursor.isValid() && !cursors[1]->fullyCompleted())
return Status(1);
if (auto result = handleAllJoinState())
return std::move(*result);
@ -1183,7 +1188,6 @@ IMergingAlgorithm::Status MergeJoinAlgorithm::merge()
if (cursors[0]->fullyCompleted() || cursors[1]->fullyCompleted())
{
if (!cursors[0]->fullyCompleted() && isLeftOrFull(kind))
return Status(createBlockWithDefaults(0));

View File

@ -1,4 +1,4 @@
- default -
- default / join_use_nulls = 0 -
1 1 0 0
1 2 1 2
1 3 1 2
@ -35,7 +35,7 @@
2 1 2 3
2 2 2 3
1 2 1 2
- full_sorting_merge -
- full_sorting_merge / join_use_nulls = 0 -
1 1 0 0
1 2 1 2
1 3 1 2
@ -72,3 +72,77 @@
2 1 2 3
2 2 2 3
1 2 1 2
- default / join_use_nulls = 1 -
1 1 \N \N
1 2 1 2
1 3 1 2
2 1 \N \N
2 2 \N \N
2 3 2 3
3 1 \N \N
3 2 \N \N
3 3 \N \N
9
1 2 1 2
1 3 1 2
2 3 2 3
-
1 1 1 2
1 2 1 2
1 3 1 4
2 1 2 3
2 2 2 3
2 3 2 3
-
1 1 1 2
1 2 1 2
1 3 1 4
2 1 2 3
2 2 2 3
2 3 2 3
-
1 3 1 2
-
1 1 1 2
1 2 1 4
1 3 1 4
2 1 2 3
2 2 2 3
1 2 1 2
- full_sorting_merge / join_use_nulls = 1 -
1 1 \N \N
1 2 1 2
1 3 1 2
2 1 \N \N
2 2 \N \N
2 3 2 3
3 1 \N \N
3 2 \N \N
3 3 \N \N
9
1 2 1 2
1 3 1 2
2 3 2 3
-
1 1 1 2
1 2 1 2
1 3 1 4
2 1 2 3
2 2 2 3
2 3 2 3
-
1 1 1 2
1 2 1 2
1 3 1 4
2 1 2 3
2 2 2 3
2 3 2 3
-
1 3 1 2
-
1 1 1 2
1 2 1 4
1 3 1 4
2 1 2 3
2 2 2 3
1 2 1 2

View File

@ -7,11 +7,13 @@ CREATE TABLE B(b UInt32, t UInt32) ENGINE = Memory;
INSERT INTO A (a,t) VALUES (1,1),(1,2),(1,3), (2,1),(2,2),(2,3), (3,1),(3,2),(3,3);
INSERT INTO B (b,t) VALUES (1,2),(1,4),(2,3);
{% for join_use_nulls in [0, 1] -%}
{% for join_algorithm in ['default', 'full_sorting_merge'] -%}
SET join_algorithm = '{{ join_algorithm }}';
SELECT '- {{ join_algorithm }} -';
SELECT '- {{ join_algorithm }} / join_use_nulls = {{ join_use_nulls }} -';
set join_use_nulls = {{ join_use_nulls }};
SELECT A.a, A.t, B.b, B.t FROM A ASOF LEFT JOIN B ON A.a == B.b AND A.t >= B.t ORDER BY (A.a, A.t);
SELECT count() FROM A ASOF LEFT JOIN B ON A.a == B.b AND B.t <= A.t;
@ -34,7 +36,8 @@ ASOF INNER JOIN (SELECT * FROM B UNION ALL SELECT 1, 3) AS B ON B.t <= A.t AND A
WHERE B.t != 3 ORDER BY (A.a, A.t)
;
{% endfor %}
{% endfor -%}
{% endfor -%}
DROP TABLE A;
DROP TABLE B;