Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
2dot5
ClickHouse
提交
2a5b4b3b
C
ClickHouse
项目概览
2dot5
/
ClickHouse
通知
3
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
C
ClickHouse
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
2a5b4b3b
编写于
3月 27, 2019
作者:
C
chertus
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fix ANY JOIN nulls in right key (ALL JOIN is still affected)
上级
e92dcd47
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
72 addition
and
31 deletion
+72
-31
dbms/src/Interpreters/Join.cpp
dbms/src/Interpreters/Join.cpp
+43
-23
dbms/tests/queries/0_stateless/00848_join_use_nulls_segfault.reference
...eries/0_stateless/00848_join_use_nulls_segfault.reference
+8
-8
dbms/tests/queries/0_stateless/00852_any_join_nulls.reference
.../tests/queries/0_stateless/00852_any_join_nulls.reference
+2
-0
dbms/tests/queries/0_stateless/00852_any_join_nulls.sql
dbms/tests/queries/0_stateless/00852_any_join_nulls.sql
+19
-0
未找到文件。
dbms/src/Interpreters/Join.cpp
浏览文件 @
2a5b4b3b
...
...
@@ -47,6 +47,39 @@ static std::unordered_map<String, DataTypePtr> requiredRightKeys(const Names & k
return
required
;
}
static
void
convertColumnToNullable
(
ColumnWithTypeAndName
&
column
)
{
if
(
column
.
type
->
isNullable
())
return
;
column
.
type
=
makeNullable
(
column
.
type
);
if
(
column
.
column
)
column
.
column
=
makeNullable
(
column
.
column
);
}
/// Converts column to nullable if needed. No backward convertion.
static
ColumnWithTypeAndName
correctNullability
(
ColumnWithTypeAndName
&&
column
,
bool
nullable
)
{
if
(
nullable
)
convertColumnToNullable
(
column
);
return
std
::
move
(
column
);
}
static
ColumnWithTypeAndName
correctNullability
(
ColumnWithTypeAndName
&&
column
,
bool
nullable
,
const
ColumnUInt8
&
negative_null_map
)
{
if
(
nullable
)
{
convertColumnToNullable
(
column
);
if
(
negative_null_map
.
size
())
{
MutableColumnPtr
mutable_column
=
(
*
std
::
move
(
column
.
column
)).
mutate
();
static_cast
<
ColumnNullable
&>
(
*
mutable_column
).
applyNegatedNullMap
(
negative_null_map
);
column
.
column
=
std
::
move
(
mutable_column
);
}
}
return
std
::
move
(
column
);
}
Join
::
Join
(
const
Names
&
key_names_right_
,
bool
use_nulls_
,
const
SizeLimits
&
limits
,
ASTTableJoin
::
Kind
kind_
,
ASTTableJoin
::
Strictness
strictness_
,
bool
any_take_last_row_
)
...
...
@@ -213,26 +246,6 @@ size_t Join::getTotalByteCount() const
return
res
;
}
static
void
convertColumnToNullable
(
ColumnWithTypeAndName
&
column
)
{
if
(
column
.
type
->
isNullable
())
return
;
column
.
type
=
makeNullable
(
column
.
type
);
if
(
column
.
column
)
column
.
column
=
makeNullable
(
column
.
column
);
}
/// Converts column to nullable if needed. No backward convertion.
ColumnWithTypeAndName
correctNullability
(
ColumnWithTypeAndName
&&
column
,
bool
nullable
)
{
if
(
nullable
)
convertColumnToNullable
(
column
);
return
std
::
move
(
column
);
}
void
Join
::
setSampleBlock
(
const
Block
&
block
)
{
std
::
unique_lock
lock
(
rwlock
);
...
...
@@ -721,7 +734,7 @@ void Join::joinBlockImpl(
std
::
unique_ptr
<
IColumn
::
Offsets
>
offsets_to_replicate
;
IColumn
::
Filter
filter
=
switchJoinRightColumns
<
KIND
,
STRICTNESS
>
(
IColumn
::
Filter
row_
filter
=
switchJoinRightColumns
<
KIND
,
STRICTNESS
>
(
type
,
maps_
,
block
.
rows
(),
key_columns
,
key_sizes
,
added
,
null_map
,
offsets_to_replicate
);
for
(
size_t
i
=
0
;
i
<
added
.
size
();
++
i
)
...
...
@@ -733,6 +746,12 @@ void Join::joinBlockImpl(
if
constexpr
(
STRICTNESS
==
ASTTableJoin
::
Strictness
::
Any
)
{
/// Some trash to represent IColumn::Filter as ColumnUInt8 needed for ColumnNullable::applyNullMap()
auto
null_map_filter_ptr
=
ColumnUInt8
::
create
();
ColumnUInt8
&
null_map_filter
=
static_cast
<
ColumnUInt8
&>
(
*
null_map_filter_ptr
);
null_map_filter
.
getData
().
swap
(
row_filter
);
const
IColumn
::
Filter
&
filter
=
null_map_filter
.
getData
();
constexpr
bool
inner_or_right
=
static_in_v
<
KIND
,
ASTTableJoin
::
Kind
::
Inner
,
ASTTableJoin
::
Kind
::
Right
>
;
if
constexpr
(
inner_or_right
)
{
...
...
@@ -779,7 +798,7 @@ void Join::joinBlockImpl(
}
bool
is_nullable
=
use_nulls
||
it
->
second
->
isNullable
();
block
.
insert
(
correctNullability
({
std
::
move
(
mut_column
),
col
.
type
,
right_name
},
is_nullable
));
block
.
insert
(
correctNullability
({
std
::
move
(
mut_column
),
col
.
type
,
right_name
},
is_nullable
,
null_map_filter
));
}
}
}
...
...
@@ -808,7 +827,7 @@ void Join::joinBlockImpl(
{
if
(
size_t
to_insert
=
(
*
offsets_to_replicate
)[
row
]
-
last_offset
)
{
if
(
!
filter
[
row
])
if
(
!
row_
filter
[
row
])
mut_column
->
insertDefault
();
else
for
(
size_t
dup
=
0
;
dup
<
to_insert
;
++
dup
)
...
...
@@ -818,6 +837,7 @@ void Join::joinBlockImpl(
last_offset
=
(
*
offsets_to_replicate
)[
row
];
}
/// TODO: null_map_filter
bool
is_nullable
=
(
use_nulls
&&
left_or_full
)
||
it
->
second
->
isNullable
();
block
.
insert
(
correctNullability
({
std
::
move
(
mut_column
),
col
.
type
,
right_name
},
is_nullable
));
}
...
...
dbms/tests/queries/0_stateless/00848_join_use_nulls_segfault.reference
浏览文件 @
2a5b4b3b
on
l \N String Nullable(String)
l \N String Nullable(String)
l
\N
\N String Nullable(String)
l
\N
\N String Nullable(String)
r \N String Nullable(String)
\N r \N Nullable(String) Nullable(String)
l \N String Nullable(String)
l \N String Nullable(String)
r \N String Nullable(String)
\N r \N Nullable(String) Nullable(String)
0
\N
\N
\N
0 \N
using
l \N String Nullable(String)
...
...
@@ -18,18 +18,18 @@ l \N String Nullable(String)
l \N String Nullable(String)
\N String Nullable(String)
\N \N Nullable(String) Nullable(String)
0
\N
\N
\N
0 \N
on + join_use_nulls
l \N TODO Nullable(String)
l \N TODO Nullable(String)
l
\N
\N TODO Nullable(String)
l
\N
\N TODO Nullable(String)
r \N TODO Nullable(String)
\N r \N Nullable(String) Nullable(String)
l \N TODO Nullable(String)
l \N TODO Nullable(String)
r \N TODO Nullable(String)
\N r \N Nullable(String) Nullable(String)
0
\N
\N
\N
0 \N
using + join_use_nulls
l \N TODO Nullable(String)
...
...
@@ -40,5 +40,5 @@ l \N TODO Nullable(String)
l \N TODO Nullable(String)
\N TODO Nullable(String)
\N \N Nullable(String) Nullable(String)
0
\N
\N
\N
0 \N
dbms/tests/queries/0_stateless/00852_any_join_nulls.reference
0 → 100644
浏览文件 @
2a5b4b3b
1 0
\N 1
dbms/tests/queries/0_stateless/00852_any_join_nulls.sql
0 → 100644
浏览文件 @
2a5b4b3b
USE
test
;
DROP
TABLE
IF
EXISTS
table1
;
DROP
TABLE
IF
EXISTS
table2
;
CREATE
TABLE
table1
(
id
String
)
ENGINE
=
Log
;
CREATE
TABLE
table2
(
parent_id
String
)
ENGINE
=
Log
;
insert
into
table1
values
(
'1'
);
SELECT
table2
.
parent_id
=
''
,
isNull
(
table2
.
parent_id
)
FROM
table1
ANY
LEFT
JOIN
table2
ON
table1
.
id
=
table2
.
parent_id
;
SET
join_use_nulls
=
1
;
SELECT
table2
.
parent_id
=
''
,
isNull
(
table2
.
parent_id
)
FROM
table1
ANY
LEFT
JOIN
table2
ON
table1
.
id
=
table2
.
parent_id
;
DROP
TABLE
test
.
table1
;
DROP
TABLE
test
.
table2
;
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录