Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
2dot5
ClickHouse
提交
94287f31
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,发现更多精彩内容 >>
提交
94287f31
编写于
9月 20, 2018
作者:
A
alesapin
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Finally fixed
上级
c13ffed0
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
31 addition
and
26 deletion
+31
-26
dbms/src/DataStreams/AddingDefaultBlockOutputStream.cpp
dbms/src/DataStreams/AddingDefaultBlockOutputStream.cpp
+20
-19
dbms/src/DataStreams/AddingDefaultBlockOutputStream.h
dbms/src/DataStreams/AddingDefaultBlockOutputStream.h
+10
-6
dbms/src/Interpreters/InterpreterInsertQuery.cpp
dbms/src/Interpreters/InterpreterInsertQuery.cpp
+1
-1
未找到文件。
dbms/src/DataStreams/AddingDefaultBlockOutputStream.cpp
浏览文件 @
94287f31
...
...
@@ -13,18 +13,25 @@ namespace DB
void
AddingDefaultBlockOutputStream
::
write
(
const
Block
&
block
)
{
Block
res
=
block
;
Block
res
;
/// We take given columns from input block
/// and missed columns without default value (default and meterialized will be computed later)
for
(
const
auto
&
column
:
output_block
)
if
(
block
.
has
(
column
.
name
))
res
.
insert
(
block
.
getByName
(
column
.
name
));
else
if
(
!
column_defaults
.
count
(
column
.
name
))
res
.
insert
(
column
);
/// Adds not specified default values.
size_t
rows
=
res
.
rows
();
size_t
rows
=
block
.
rows
();
/// For missing columns of nested structure, you need to create not a column of empty arrays, but a column of arrays of correct lengths.
/// First, remember the offset columns for all arrays in the block.
std
::
map
<
String
,
ColumnPtr
>
offset_columns
;
for
(
size_t
i
=
0
,
size
=
res
.
columns
();
i
<
size
;
++
i
)
for
(
size_t
i
=
0
,
size
=
block
.
columns
();
i
<
size
;
++
i
)
{
const
auto
&
elem
=
res
.
getByPosition
(
i
);
const
auto
&
elem
=
block
.
getByPosition
(
i
);
if
(
const
ColumnArray
*
array
=
typeid_cast
<
const
ColumnArray
*>
(
&*
elem
.
column
))
{
...
...
@@ -37,39 +44,33 @@ void AddingDefaultBlockOutputStream::write(const Block & block)
}
}
size_t
i
=
0
;
for
(
auto
col
=
required_columns
.
begin
();
col
!=
required_columns
.
end
();
++
col
,
++
i
)
/// In this loop we feel missed columns
for
(
auto
&
column
:
res
)
{
if
(
res
.
has
(
col
->
name
)
||
column_defaults
.
count
(
col
->
name
))
if
(
block
.
has
(
column
.
name
))
continue
;
ColumnWithTypeAndName
column_to_add
;
column_to_add
.
name
=
col
->
name
;
column_to_add
.
type
=
col
->
type
;
String
offsets_name
=
Nested
::
extractTableName
(
column_to_add
.
name
);
String
offsets_name
=
Nested
::
extractTableName
(
column
.
name
);
if
(
offset_columns
.
count
(
offsets_name
))
{
ColumnPtr
offsets_column
=
offset_columns
[
offsets_name
];
DataTypePtr
nested_type
=
typeid_cast
<
const
DataTypeArray
&>
(
*
column
_to_add
.
type
).
getNestedType
();
DataTypePtr
nested_type
=
typeid_cast
<
const
DataTypeArray
&>
(
*
column
.
type
).
getNestedType
();
UInt64
nested_rows
=
rows
?
get
<
UInt64
>
((
*
offsets_column
)[
rows
-
1
])
:
0
;
ColumnPtr
nested_column
=
nested_type
->
createColumnConstWithDefaultValue
(
nested_rows
)
->
convertToFullColumnIfConst
();
column
_to_add
.
column
=
ColumnArray
::
create
(
nested_column
,
offsets_column
);
column
.
column
=
ColumnArray
::
create
(
nested_column
,
offsets_column
);
}
else
{
/** It is necessary to turn a constant column into a full column, since in part of blocks (from other parts),
* it can be full (or the interpreter may decide that it is constant everywhere).
*/
column
_to_add
.
column
=
column_to_add
.
type
->
createColumnConstWithDefaultValue
(
rows
)
->
convertToFullColumnIfConst
();
column
.
column
=
column
.
type
->
createColumnConstWithDefaultValue
(
rows
)
->
convertToFullColumnIfConst
();
}
res
.
insert
(
i
,
std
::
move
(
column_to_add
));
}
/// Computes explicitly specified values (in column_defaults) by default.
evaluateMissingDefaults
(
res
,
required_columns
,
column_defaults
,
context
);
/// Computes explicitly specified values (in column_defaults) by default
and materialized columns
.
evaluateMissingDefaults
(
res
,
output_block
.
getNamesAndTypesList
()
,
column_defaults
,
context
);
output
->
write
(
res
);
}
...
...
dbms/src/DataStreams/AddingDefaultBlockOutputStream.h
浏览文件 @
94287f31
...
...
@@ -10,8 +10,11 @@ namespace DB
{
/** Adds missing columns to the block with default values.
* These columns are materialized (not constants).
/** This stream adds three types of columns into block
* 1. Columns, that are missed inside request, but present in table without defaults (missed columns)
* 2. Columns, that are missed inside request, but present in table with defaults (columns with default values)
* 3. Columns that materialized from other columns (materialized columns)
* All three types of columns are materialized (not constants).
*/
class
AddingDefaultBlockOutputStream
:
public
IBlockOutputStream
{
...
...
@@ -19,10 +22,10 @@ public:
AddingDefaultBlockOutputStream
(
const
BlockOutputStreamPtr
&
output_
,
const
Block
&
header_
,
NamesAndTypesList
required_columns
_
,
const
Block
&
output_block
_
,
const
ColumnDefaults
&
column_defaults_
,
const
Context
&
context_
)
:
output
(
output_
),
header
(
header_
),
required_columns
(
required_columns
_
),
:
output
(
output_
),
header
(
header_
),
output_block
(
output_block
_
),
column_defaults
(
column_defaults_
),
context
(
context_
)
{
}
...
...
@@ -37,8 +40,9 @@ public:
private:
BlockOutputStreamPtr
output
;
Block
header
;
NamesAndTypesList
required_columns
;
const
Block
header
;
/// Blocks after this stream should have this structure
const
Block
output_block
;
const
ColumnDefaults
column_defaults
;
const
Context
&
context
;
};
...
...
dbms/src/Interpreters/InterpreterInsertQuery.cpp
浏览文件 @
94287f31
...
...
@@ -112,7 +112,7 @@ BlockIO InterpreterInsertQuery::execute()
/// Actually we don't know structure of input blocks from query/table,
/// because some clients break insertion protocol (columns != header)
out
=
std
::
make_shared
<
AddingDefaultBlockOutputStream
>
(
out
,
getSampleBlock
(
query
,
table
),
table
->
get
Columns
().
getAllPhysical
(),
table
->
getColumns
().
defaults
,
context
);
out
,
getSampleBlock
(
query
,
table
),
table
->
get
SampleBlock
(),
table
->
getColumns
().
defaults
,
context
);
auto
out_wrapper
=
std
::
make_shared
<
CountingBlockOutputStream
>
(
out
);
out_wrapper
->
setProcessListElement
(
context
.
getProcessListElement
());
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录