mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-11-10 01:25:21 +00:00
fix asof join on nulls
This commit is contained in:
parent
7a5e48486f
commit
85714e7d7e
@ -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));
|
||||
|
||||
|
@ -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
|
||||
|
@ -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;
|
||||
|
Loading…
Reference in New Issue
Block a user