Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
2dot5
ClickHouse
提交
95b43aa5
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,发现更多精彩内容 >>
未验证
提交
95b43aa5
编写于
12月 28, 2019
作者:
A
alexey-milovidov
提交者:
GitHub
12月 28, 2019
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #8446 from ClickHouse/agg-throw
Added aggregate function `aggThrow`
上级
9d651526
24cc1017
变更
10
隐藏空白更改
内联
并排
Showing
10 changed file
with
140 addition
and
5 deletion
+140
-5
dbms/src/AggregateFunctions/AggregateFunctionAggThrow.cpp
dbms/src/AggregateFunctions/AggregateFunctionAggThrow.cpp
+119
-0
dbms/src/AggregateFunctions/AggregateFunctionResample.h
dbms/src/AggregateFunctions/AggregateFunctionResample.h
+12
-1
dbms/src/AggregateFunctions/FactoryHelpers.h
dbms/src/AggregateFunctions/FactoryHelpers.h
+2
-2
dbms/src/AggregateFunctions/IAggregateFunction.h
dbms/src/AggregateFunctions/IAggregateFunction.h
+1
-1
dbms/src/AggregateFunctions/registerAggregateFunctions.cpp
dbms/src/AggregateFunctions/registerAggregateFunctions.cpp
+1
-0
dbms/src/AggregateFunctions/registerAggregateFunctions.h
dbms/src/AggregateFunctions/registerAggregateFunctions.h
+1
-0
dbms/src/Common/ErrorCodes.cpp
dbms/src/Common/ErrorCodes.cpp
+1
-0
dbms/src/Functions/array/arrayReduce.cpp
dbms/src/Functions/array/arrayReduce.cpp
+2
-1
dbms/tests/queries/0_stateless/01052_array_reduce_exception.reference
...ueries/0_stateless/01052_array_reduce_exception.reference
+0
-0
dbms/tests/queries/0_stateless/01052_array_reduce_exception.sql
...ests/queries/0_stateless/01052_array_reduce_exception.sql
+1
-0
未找到文件。
dbms/src/AggregateFunctions/AggregateFunctionAggThrow.cpp
0 → 100644
浏览文件 @
95b43aa5
#include <memory>
#include <random>
#include <DataTypes/DataTypesNumber.h>
#include <Common/thread_local_rng.h>
#include <IO/ReadBuffer.h>
#include <IO/WriteBuffer.h>
#include <AggregateFunctions/IAggregateFunction.h>
#include <AggregateFunctions/AggregateFunctionFactory.h>
namespace
DB
{
namespace
ErrorCodes
{
extern
const
int
AGGREGATE_FUNCTION_THROW
;
extern
const
int
NUMBER_OF_ARGUMENTS_DOESNT_MATCH
;
}
namespace
{
struct
AggregateFunctionThrowData
{
bool
allocated
;
AggregateFunctionThrowData
()
:
allocated
(
true
)
{}
~
AggregateFunctionThrowData
()
{
volatile
bool
*
allocated_ptr
=
&
allocated
;
if
(
*
allocated_ptr
)
*
allocated_ptr
=
false
;
else
abort
();
}
};
/** Throw on creation with probability specified in parameter.
* It will check correct destruction of the state.
* This is intended to check for exception safety.
*/
class
AggregateFunctionThrow
final
:
public
IAggregateFunctionDataHelper
<
AggregateFunctionThrowData
,
AggregateFunctionThrow
>
{
private:
Float64
throw_probability
;
public:
AggregateFunctionThrow
(
const
DataTypes
&
argument_types_
,
const
Array
&
parameters_
,
Float64
throw_probability_
)
:
IAggregateFunctionDataHelper
(
argument_types_
,
parameters_
),
throw_probability
(
throw_probability_
)
{}
String
getName
()
const
override
{
return
"aggThrow"
;
}
DataTypePtr
getReturnType
()
const
override
{
return
std
::
make_shared
<
DataTypeUInt8
>
();
}
void
create
(
AggregateDataPtr
place
)
const
override
{
if
(
std
::
uniform_real_distribution
<>
(
0.0
,
1.0
)(
thread_local_rng
)
<=
throw_probability
)
throw
Exception
(
"Aggregate function "
+
getName
()
+
" has thrown exception successfully"
,
ErrorCodes
::
AGGREGATE_FUNCTION_THROW
);
new
(
place
)
Data
;
}
void
destroy
(
AggregateDataPtr
place
)
const
noexcept
override
{
data
(
place
).
~
Data
();
}
void
add
(
AggregateDataPtr
,
const
IColumn
**
,
size_t
,
Arena
*
)
const
override
{
}
void
merge
(
AggregateDataPtr
,
ConstAggregateDataPtr
,
Arena
*
)
const
override
{
}
void
serialize
(
ConstAggregateDataPtr
,
WriteBuffer
&
buf
)
const
override
{
char
c
=
0
;
buf
.
write
(
c
);
}
void
deserialize
(
AggregateDataPtr
,
ReadBuffer
&
buf
,
Arena
*
)
const
override
{
char
c
=
0
;
buf
.
read
(
c
);
}
void
insertResultInto
(
ConstAggregateDataPtr
,
IColumn
&
to
)
const
override
{
to
.
insertDefault
();
}
};
}
void
registerAggregateFunctionAggThrow
(
AggregateFunctionFactory
&
factory
)
{
factory
.
registerFunction
(
"aggThrow"
,
[](
const
std
::
string
&
name
,
const
DataTypes
&
argument_types
,
const
Array
&
parameters
)
{
Float64
throw_probability
=
1.0
;
if
(
parameters
.
size
()
==
1
)
throw_probability
=
parameters
[
0
].
safeGet
<
Float64
>
();
else
if
(
parameters
.
size
()
>
1
)
throw
Exception
(
"Aggregate function "
+
name
+
" cannot have more than one parameter"
,
ErrorCodes
::
NUMBER_OF_ARGUMENTS_DOESNT_MATCH
);
return
std
::
make_shared
<
AggregateFunctionThrow
>
(
argument_types
,
parameters
,
throw_probability
);
});
}
}
dbms/src/AggregateFunctions/AggregateFunctionResample.h
浏览文件 @
95b43aa5
...
...
@@ -100,7 +100,18 @@ public:
void
create
(
AggregateDataPtr
place
)
const
override
{
for
(
size_t
i
=
0
;
i
<
total
;
++
i
)
nested_function
->
create
(
place
+
i
*
size_of_data
);
{
try
{
nested_function
->
create
(
place
+
i
*
size_of_data
);
}
catch
(...)
{
for
(
size_t
j
=
0
;
j
<
i
;
++
j
)
nested_function
->
destroy
(
place
+
j
*
size_of_data
);
throw
;
}
}
}
void
destroy
(
AggregateDataPtr
place
)
const
noexcept
override
...
...
dbms/src/AggregateFunctions/FactoryHelpers.h
浏览文件 @
95b43aa5
...
...
@@ -23,13 +23,13 @@ inline void assertNoParameters(const std::string & name, const Array & parameter
inline
void
assertUnary
(
const
std
::
string
&
name
,
const
DataTypes
&
argument_types
)
{
if
(
argument_types
.
size
()
!=
1
)
throw
Exception
(
"Aggregate function "
+
name
+
" require single argument"
,
ErrorCodes
::
NUMBER_OF_ARGUMENTS_DOESNT_MATCH
);
throw
Exception
(
"Aggregate function "
+
name
+
" require
s
single argument"
,
ErrorCodes
::
NUMBER_OF_ARGUMENTS_DOESNT_MATCH
);
}
inline
void
assertBinary
(
const
std
::
string
&
name
,
const
DataTypes
&
argument_types
)
{
if
(
argument_types
.
size
()
!=
2
)
throw
Exception
(
"Aggregate function "
+
name
+
" require two arguments"
,
ErrorCodes
::
NUMBER_OF_ARGUMENTS_DOESNT_MATCH
);
throw
Exception
(
"Aggregate function "
+
name
+
" require
s
two arguments"
,
ErrorCodes
::
NUMBER_OF_ARGUMENTS_DOESNT_MATCH
);
}
template
<
std
::
size_t
maximal_arity
>
...
...
dbms/src/AggregateFunctions/IAggregateFunction.h
浏览文件 @
95b43aa5
...
...
@@ -213,7 +213,7 @@ protected:
public:
IAggregateFunctionDataHelper
(
const
DataTypes
&
argument_types_
,
const
Array
&
parameters_
)
:
IAggregateFunctionHelper
<
Derived
>
(
argument_types_
,
parameters_
)
{}
:
IAggregateFunctionHelper
<
Derived
>
(
argument_types_
,
parameters_
)
{}
void
create
(
AggregateDataPtr
place
)
const
override
{
...
...
dbms/src/AggregateFunctions/registerAggregateFunctions.cpp
浏览文件 @
95b43aa5
...
...
@@ -42,6 +42,7 @@ void registerAggregateFunctions()
registerAggregateFunctionSimpleLinearRegression
(
factory
);
registerAggregateFunctionMoving
(
factory
);
registerAggregateFunctionCategoricalIV
(
factory
);
registerAggregateFunctionAggThrow
(
factory
);
}
{
...
...
dbms/src/AggregateFunctions/registerAggregateFunctions.h
浏览文件 @
95b43aa5
...
...
@@ -34,6 +34,7 @@ void registerAggregateFunctionEntropy(AggregateFunctionFactory &);
void
registerAggregateFunctionSimpleLinearRegression
(
AggregateFunctionFactory
&
);
void
registerAggregateFunctionMoving
(
AggregateFunctionFactory
&
);
void
registerAggregateFunctionCategoricalIV
(
AggregateFunctionFactory
&
);
void
registerAggregateFunctionAggThrow
(
AggregateFunctionFactory
&
);
class
AggregateFunctionCombinatorFactory
;
void
registerAggregateFunctionCombinatorIf
(
AggregateFunctionCombinatorFactory
&
);
...
...
dbms/src/Common/ErrorCodes.cpp
浏览文件 @
95b43aa5
...
...
@@ -477,6 +477,7 @@ namespace ErrorCodes
extern
const
int
CANNOT_CREATE_DICTIONARY_FROM_METADATA
=
500
;
extern
const
int
CANNOT_CREATE_DATABASE
=
501
;
extern
const
int
CANNOT_SIGQUEUE
=
502
;
extern
const
int
AGGREGATE_FUNCTION_THROW
=
503
;
extern
const
int
KEEPER_EXCEPTION
=
999
;
extern
const
int
POCO_EXCEPTION
=
1000
;
...
...
dbms/src/Functions/array/arrayReduce.cpp
浏览文件 @
95b43aa5
...
...
@@ -168,7 +168,8 @@ void FunctionArrayReduce::executeImpl(Block & block, const ColumnNumbers & argum
}
catch
(...)
{
agg_func
.
destroy
(
places
[
i
]);
for
(
size_t
j
=
0
;
j
<
i
;
++
j
)
agg_func
.
destroy
(
places
[
j
]);
throw
;
}
}
...
...
dbms/tests/queries/0_stateless/01052_array_reduce_exception.reference
0 → 100644
浏览文件 @
95b43aa5
dbms/tests/queries/0_stateless/01052_array_reduce_exception.sql
0 → 100644
浏览文件 @
95b43aa5
SELECT
arrayReduce
(
'aggThrow(0.0001)'
,
range
(
number
%
10
))
FROM
system
.
numbers
;
-- { serverError 503 }
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录