Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
2dot5
ClickHouse
提交
7577b1db
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,发现更多精彩内容 >>
提交
7577b1db
编写于
3月 10, 2018
作者:
A
Alexey Milovidov
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Added function "throwIf" [#CLICKHOUSE-2543]
上级
988835e9
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
83 addition
and
1 deletion
+83
-1
dbms/src/Common/ErrorCodes.cpp
dbms/src/Common/ErrorCodes.cpp
+1
-0
dbms/src/Functions/FunctionsMiscellaneous.cpp
dbms/src/Functions/FunctionsMiscellaneous.cpp
+71
-1
dbms/tests/queries/0_stateless/00602_throw_if.reference
dbms/tests/queries/0_stateless/00602_throw_if.reference
+2
-0
dbms/tests/queries/0_stateless/00602_throw_if.sql
dbms/tests/queries/0_stateless/00602_throw_if.sql
+9
-0
未找到文件。
dbms/src/Common/ErrorCodes.cpp
浏览文件 @
7577b1db
...
...
@@ -370,6 +370,7 @@ namespace ErrorCodes
extern
const
int
QUERY_IS_PROHIBITED
=
392
;
extern
const
int
THERE_IS_NO_QUERY
=
393
;
extern
const
int
QUERY_WAS_CANCELLED
=
394
;
extern
const
int
FUNCTION_THROW_IF_VALUE_IS_NON_ZERO
=
395
;
extern
const
int
KEEPER_EXCEPTION
=
999
;
...
...
dbms/src/Functions/FunctionsMiscellaneous.cpp
浏览文件 @
7577b1db
...
...
@@ -41,6 +41,7 @@ namespace ErrorCodes
extern
const
int
FUNCTION_IS_SPECIAL
;
extern
const
int
ARGUMENT_OUT_OF_BOUND
;
extern
const
int
TOO_SLOW
;
extern
const
int
FUNCTION_THROW_IF_VALUE_IS_NON_ZERO
;
}
/** Helper functions
...
...
@@ -1140,7 +1141,9 @@ public:
{
const
auto
in
=
block
.
getByPosition
(
arguments
.
front
()).
column
.
get
();
if
(
!
execute
<
UInt8
>
(
block
,
in
,
result
)
&&
!
execute
<
UInt16
>
(
block
,
in
,
result
)
&&
!
execute
<
UInt32
>
(
block
,
in
,
result
)
if
(
!
execute
<
UInt8
>
(
block
,
in
,
result
)
&&
!
execute
<
UInt16
>
(
block
,
in
,
result
)
&&
!
execute
<
UInt32
>
(
block
,
in
,
result
)
&&
!
execute
<
UInt64
>
(
block
,
in
,
result
)
&&
!
execute
<
Int8
>
(
block
,
in
,
result
)
&&
!
execute
<
Int16
>
(
block
,
in
,
result
)
...
...
@@ -1756,6 +1759,72 @@ void FunctionHasColumnInTable::executeImpl(Block & block, const ColumnNumbers &
}
/// Throw an exception if the argument is non zero.
class
FunctionThrowIf
:
public
IFunction
{
public:
static
constexpr
auto
name
=
"throwIf"
;
static
FunctionPtr
create
(
const
Context
&
)
{
return
std
::
make_shared
<
FunctionThrowIf
>
();
}
String
getName
()
const
override
{
return
name
;
}
size_t
getNumberOfArguments
()
const
override
{
return
1
;
}
DataTypePtr
getReturnTypeImpl
(
const
DataTypes
&
arguments
)
const
override
{
if
(
!
arguments
.
front
()
->
isNumber
())
throw
Exception
{
"Argument for function "
+
getName
()
+
" must be number"
,
ErrorCodes
::
ILLEGAL_TYPE_OF_ARGUMENT
};
return
std
::
make_shared
<
DataTypeUInt8
>
();
}
bool
useDefaultImplementationForConstants
()
const
override
{
return
true
;
}
void
executeImpl
(
Block
&
block
,
const
ColumnNumbers
&
arguments
,
const
size_t
result
)
override
{
const
auto
in
=
block
.
getByPosition
(
arguments
.
front
()).
column
.
get
();
if
(
!
execute
<
UInt8
>
(
block
,
in
,
result
)
&&
!
execute
<
UInt16
>
(
block
,
in
,
result
)
&&
!
execute
<
UInt32
>
(
block
,
in
,
result
)
&&
!
execute
<
UInt64
>
(
block
,
in
,
result
)
&&
!
execute
<
Int8
>
(
block
,
in
,
result
)
&&
!
execute
<
Int16
>
(
block
,
in
,
result
)
&&
!
execute
<
Int32
>
(
block
,
in
,
result
)
&&
!
execute
<
Int64
>
(
block
,
in
,
result
)
&&
!
execute
<
Float32
>
(
block
,
in
,
result
)
&&
!
execute
<
Float64
>
(
block
,
in
,
result
))
throw
Exception
{
"Illegal column "
+
in
->
getName
()
+
" of first argument of function "
+
getName
(),
ErrorCodes
::
ILLEGAL_COLUMN
};
}
template
<
typename
T
>
bool
execute
(
Block
&
block
,
const
IColumn
*
in_untyped
,
const
size_t
result
)
{
if
(
const
auto
in
=
checkAndGetColumn
<
ColumnVector
<
T
>>
(
in_untyped
))
{
const
auto
&
in_data
=
in
->
getData
();
if
(
!
memoryIsZero
(
in_data
.
data
(),
in_data
.
size
()
*
sizeof
(
in_data
[
0
])))
throw
Exception
(
"Value passed to 'throwIf' function is non zero"
,
ErrorCodes
::
FUNCTION_THROW_IF_VALUE_IS_NON_ZERO
);
/// We return non constant to avoid constant folding.
block
.
getByPosition
(
result
).
column
=
ColumnUInt8
::
create
(
in_data
.
size
(),
0
);
return
true
;
}
return
false
;
}
};
std
::
string
FunctionVersion
::
getVersion
()
const
{
std
::
ostringstream
os
;
...
...
@@ -1797,6 +1866,7 @@ void registerFunctionsMiscellaneous(FunctionFactory & factory)
factory
.
registerFunction
<
FunctionIsFinite
>
();
factory
.
registerFunction
<
FunctionIsInfinite
>
();
factory
.
registerFunction
<
FunctionIsNaN
>
();
factory
.
registerFunction
<
FunctionThrowIf
>
();
factory
.
registerFunction
<
FunctionVersion
>
();
factory
.
registerFunction
<
FunctionUptime
>
();
...
...
dbms/tests/queries/0_stateless/00602_throw_if.reference
0 → 100644
浏览文件 @
7577b1db
1
1000000
dbms/tests/queries/0_stateless/00602_throw_if.sql
0 → 100755
浏览文件 @
7577b1db
#!/
usr
/
bin
/
env
bash
CURDIR
=
$
(
cd
"$(dirname "
${
BASH_SOURCE
[
0
]
}
")"
&&
pwd
)
.
$
CURDIR
/
..
/
shell_config
.
sh
exception_pattern
=
"Value passed to 'throwIf' function is non zero"
${
CLICKHOUSE_CLIENT
}
--query="SELECT throwIf(number = 1000000) FROM system.numbers" 2>&1 | grep -cF "$exception_pattern"
${
CLICKHOUSE_CLIENT
}
--query="SELECT sum(x = 0) FROM (SELECT throwIf(number = 1000000) AS x FROM numbers(1000000))" 2>&1
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录