Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
2dot5
ClickHouse
提交
a4e83a85
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,发现更多精彩内容 >>
提交
a4e83a85
编写于
3月 19, 2019
作者:
N
Nikolai Kochetov
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Added Rollup and Cube transforms.
上级
1293e2d6
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
182 addition
and
13 deletion
+182
-13
dbms/src/Processors/Transforms/CubeTransform.cpp
dbms/src/Processors/Transforms/CubeTransform.cpp
+69
-0
dbms/src/Processors/Transforms/CubeTransform.h
dbms/src/Processors/Transforms/CubeTransform.h
+34
-0
dbms/src/Processors/Transforms/RollupTransform.cpp
dbms/src/Processors/Transforms/RollupTransform.cpp
+58
-4
dbms/src/Processors/Transforms/RollupTransform.h
dbms/src/Processors/Transforms/RollupTransform.h
+21
-9
未找到文件。
dbms/src/Processors/Transforms/CubeTransform.cpp
0 → 100644
浏览文件 @
a4e83a85
#include <Processors/Transforms/CubeTransform.h>
namespace
DB
{
static
Chunk
finalizeChunk
(
Chunk
chunk
)
{
auto
num_rows
=
chunk
.
getNumRows
();
auto
columns
=
chunk
.
detachColumns
();
for
(
auto
&
column
:
columns
)
if
(
auto
*
agg_function
=
typeid_cast
<
const
ColumnAggregateFunction
*>
(
column
.
get
()))
column
=
agg_function
->
convertToValues
();
return
Chunk
(
std
::
move
(
columns
),
num_rows
);
}
CubeTransform
::
CubeTransform
(
Block
header
,
AggregatingTransformParamsPtr
params_
)
:
IInflatingTransform
(
std
::
move
(
header
),
params_
->
getHeader
())
,
params
(
std
::
move
(
params_
))
,
keys
(
params
->
params
.
keys
)
{
if
(
keys
.
size
()
>=
8
*
sizeof
(
mask
))
throw
Exception
(
"Too many keys are used for CubeTransform."
,
ErrorCodes
::
LOGICAL_ERROR
);
}
void
CubeTransform
::
consume
(
Chunk
chunk
)
{
consumed_chunk
=
std
::
move
(
chunk
);
auto
num_rows
=
current_chunk
.
getNumRows
();
mask
=
(
UInt64
(
1
)
<<
keys
.
size
())
-
1
;
current_columns
=
consumed_chunk
.
getColumns
();
current_zero_columns
.
clear
();
current_zero_columns
.
reserve
(
current_columns
.
size
());
for
(
auto
&
column
:
current_columns
)
current_zero_columns
.
emplace_back
(
column
->
cloneEmpty
()
->
cloneResized
(
num_rows
));
}
bool
CubeTransform
::
canGenerate
()
{
return
consumed_chunk
;
}
Chunk
CubeTransform
::
generate
()
{
auto
gen_chunk
=
std
::
move
(
consumed_chunk
);
if
(
mask
)
{
--
mask
;
auto
columns
=
current_columns
;
for
(
size_t
i
=
0
;
i
<
columns
.
size
();
++
i
)
if
(
mask
&
(
UInt64
(
1
)
<<
i
))
columns
[
i
]
=
current_zero_columns
[
i
];
BlocksList
cube_blocks
=
{
getInputPort
().
getHeader
().
cloneWithColumns
(
columns
)
};
auto
cube_block
=
params
->
aggregator
.
mergeBlocks
(
cube_blocks
,
false
);
auto
num_rows
=
cube_block
.
rows
();
consumed_chunk
=
Chunk
(
cube_block
.
getColumns
(),
num_rows
);
}
return
finalizeChunk
(
std
::
move
(
gen_chunk
));
}
}
dbms/src/Processors/Transforms/CubeTransform.h
0 → 100644
浏览文件 @
a4e83a85
#pragma once
#include <Processors/IInflatingTransform.h>
#include <Processors/Transforms/AggregatingTransform.h>
namespace
DB
{
/// Takes blocks after grouping, with non-finalized aggregate functions.
/// Calculates all subsets of columns and aggregates over them.
class
CubeTransform
:
public
IInflatingTransform
{
public:
CubeTransform
(
Block
header
,
AggregatingTransformParamsPtr
params
);
protected:
void
consume
(
Chunk
chunk
)
override
;
bool
canGenerate
()
override
;
Chunk
generate
()
override
;
private:
AggregatingTransformParamsPtr
params
;
ColumnNumbers
keys
;
Chunk
consumed_chunk
;
Columns
current_columns
;
Columns
current_zero_columns
;
UInt64
mask
=
0
;
};
}
dbms/src/Processors/Transforms/RollupTransform.cpp
浏览文件 @
a4e83a85
//
// Created by nik-kochetov on 3/18/19.
//
#include <Processors/Transforms/RollupTransform.h>
#include "RollupTransform.h"
namespace
DB
{
static
Chunk
finalizeChunk
(
Chunk
chunk
)
{
auto
num_rows
=
chunk
.
getNumRows
();
auto
columns
=
chunk
.
detachColumns
();
for
(
auto
&
column
:
columns
)
if
(
auto
*
agg_function
=
typeid_cast
<
const
ColumnAggregateFunction
*>
(
column
.
get
()))
column
=
agg_function
->
convertToValues
();
return
Chunk
(
std
::
move
(
columns
),
num_rows
);
}
RollupTransform
::
RollupTransform
(
Block
header
,
AggregatingTransformParamsPtr
params_
)
:
IInflatingTransform
(
std
::
move
(
header
)
,
params_
->
getHeader
())
,
params
(
std
::
move
(
params_
))
,
keys
(
params
->
params
.
keys
)
{
}
void
RollupTransform
::
consume
(
Chunk
chunk
)
{
consumed_chunk
=
std
::
move
(
chunk
);
last_removed_key
=
consumed_chunk
.
getNumColumns
();
}
bool
RollupTransform
::
canGenerate
()
{
return
consumed_chunk
;
}
Chunk
RollupTransform
::
generate
()
{
auto
gen_chunk
=
std
::
move
(
consumed_chunk
);
if
(
last_removed_key
)
{
--
last_removed_key
;
auto
num_rows
=
gen_chunk
.
getNumRows
();
auto
columns
=
gen_chunk
.
getColumns
();
columns
[
last_removed_key
]
=
columns
[
last_removed_key
]
->
cloneEmpty
()
->
cloneResized
(
num_rows
);
BlocksList
rollup_blocks
=
{
getInputPort
().
getHeader
().
cloneWithColumns
(
columns
)
};
auto
rollup_block
=
params
->
aggregator
.
mergeBlocks
(
rollup_blocks
,
false
);
num_rows
=
rollup_block
.
rows
();
consumed_chunk
=
Chunk
(
rollup_block
.
getColumns
(),
num_rows
);
}
return
finalizeChunk
(
std
::
move
(
gen_chunk
));
}
}
dbms/src/Processors/Transforms/RollupTransform.h
浏览文件 @
a4e83a85
//
// Created by nik-kochetov on 3/18/19.
//
#ifndef CLICKHOUSE_ROLLUPTRANSFORM_H
#define CLICKHOUSE_ROLLUPTRANSFORM_H
#pragma once
#include <Processors/IInflatingTransform.h>
#include <Processors/Transforms/AggregatingTransform.h>
namespace
DB
{
class
RollupTransform
/// Takes blocks after grouping, with non-finalized aggregate functions.
/// Calculates subtotals and grand totals values for a set of columns.
class
RollupTransform
:
public
IInflatingTransform
{
public:
RollupTransform
(
Block
header
,
AggregatingTransformParamsPtr
params
);
};
protected:
void
consume
(
Chunk
chunk
)
override
;
bool
canGenerate
()
override
;
Chunk
generate
()
override
;
private:
AggregatingTransformParamsPtr
params
;
ColumnNumbers
keys
;
Chunk
consumed_chunk
;
size_t
last_removed_key
=
0
;
};
#endif //CLICKHOUSE_ROLLUPTRANSFORM_H
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录