Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
2dot5
ClickHouse
提交
69fee681
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,发现更多精彩内容 >>
提交
69fee681
编写于
1月 21, 2020
作者:
C
chertus
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
variant without catch
上级
cc5fc0a8
变更
2
显示空白变更内容
内联
并排
Showing
2 changed file
with
32 addition
and
20 deletion
+32
-20
dbms/src/IO/readDecimalText.h
dbms/src/IO/readDecimalText.h
+29
-17
dbms/tests/queries/0_stateless/01070_to_decimal_or_null_exception.sql
...ueries/0_stateless/01070_to_decimal_or_null_exception.sql
+3
-3
未找到文件。
dbms/src/IO/readDecimalText.h
浏览文件 @
69fee681
...
...
@@ -11,8 +11,8 @@ namespace ErrorCodes
}
template
<
typename
T
>
inline
void
readDigits
(
ReadBuffer
&
buf
,
T
&
x
,
unsigned
int
&
digits
,
int
&
exponent
,
bool
digits_only
=
false
)
template
<
bool
_throw_on_error
,
typename
T
>
inline
bool
readDigits
(
ReadBuffer
&
buf
,
T
&
x
,
unsigned
int
&
digits
,
int
&
exponent
,
bool
digits_only
=
false
)
{
x
=
0
;
exponent
=
0
;
...
...
@@ -24,7 +24,11 @@ inline void readDigits(ReadBuffer & buf, T & x, unsigned int & digits, int & exp
bool
after_point
=
false
;
if
(
buf
.
eof
())
{
if
constexpr
(
_throw_on_error
)
throwReadAfterEOF
();
return
false
;
}
if
(
!
buf
.
eof
())
{
...
...
@@ -75,8 +79,12 @@ inline void readDigits(ReadBuffer & buf, T & x, unsigned int & digits, int & exp
++
places
;
// num zeroes before + current digit
if
(
digits
+
places
>
max_digits
)
{
if
constexpr
(
_throw_on_error
)
throw
Exception
(
"Too many digits ("
+
std
::
to_string
(
digits
+
places
)
+
" > "
+
std
::
to_string
(
max_digits
)
+
") in decimal value"
,
ErrorCodes
::
ARGUMENT_OUT_OF_BOUND
);
return
false
;
}
digits
+=
places
;
if
(
after_point
)
...
...
@@ -93,7 +101,13 @@ inline void readDigits(ReadBuffer & buf, T & x, unsigned int & digits, int & exp
{
++
buf
.
position
();
Int32
addition_exp
=
0
;
readIntText
(
addition_exp
,
buf
);
if
(
!
tryReadIntText
(
addition_exp
,
buf
))
{
if
constexpr
(
_throw_on_error
)
throw
Exception
(
"Cannot parse exponent while reading decimal"
,
ErrorCodes
::
CANNOT_PARSE_NUMBER
);
else
return
false
;
}
exponent
+=
addition_exp
;
stop
=
true
;
continue
;
...
...
@@ -101,7 +115,11 @@ inline void readDigits(ReadBuffer & buf, T & x, unsigned int & digits, int & exp
default:
if
(
digits_only
)
{
if
constexpr
(
_throw_on_error
)
throw
Exception
(
"Unexpected symbol while reading decimal"
,
ErrorCodes
::
CANNOT_PARSE_NUMBER
);
return
false
;
}
stop
=
true
;
continue
;
}
...
...
@@ -109,6 +127,7 @@ inline void readDigits(ReadBuffer & buf, T & x, unsigned int & digits, int & exp
}
x
*=
sign
;
return
true
;
}
template
<
typename
T
>
...
...
@@ -116,7 +135,7 @@ inline void readDecimalText(ReadBuffer & buf, T & x, unsigned int precision, uns
{
unsigned
int
digits
=
precision
;
int
exponent
;
readDigits
(
buf
,
x
,
digits
,
exponent
,
digits_only
);
readDigits
<
true
>
(
buf
,
x
,
digits
,
exponent
,
digits_only
);
if
(
static_cast
<
int
>
(
digits
)
+
exponent
>
static_cast
<
int
>
(
precision
-
scale
))
throw
Exception
(
"Decimal value is too big"
,
ErrorCodes
::
ARGUMENT_OUT_OF_BOUND
);
...
...
@@ -132,17 +151,10 @@ inline bool tryReadDecimalText(ReadBuffer & buf, T & x, unsigned int precision,
unsigned
int
digits
=
precision
;
int
exponent
;
try
{
readDigits
(
buf
,
x
,
digits
,
exponent
,
true
);
if
(
static_cast
<
int
>
(
digits
)
+
exponent
>
static_cast
<
int
>
(
precision
-
scale
)
||
if
(
!
readDigits
<
false
>
(
buf
,
x
,
digits
,
exponent
,
true
)
||
static_cast
<
int
>
(
digits
)
+
exponent
>
static_cast
<
int
>
(
precision
-
scale
)
||
static_cast
<
int
>
(
scale
)
+
exponent
<
0
)
return
false
;
}
catch
(
const
Exception
&
)
{
return
false
;
}
scale
+=
exponent
;
return
true
;
...
...
dbms/tests/queries/0_stateless/01070_to_decimal_or_null_exception.sql
浏览文件 @
69fee681
SELECT
toDecimal32
(
'e'
,
1
);
-- { serverError
3
2 }
SELECT
toDecimal64
(
'e'
,
2
);
-- { serverError
3
2 }
SELECT
toDecimal128
(
'e'
,
3
);
-- { serverError
3
2 }
SELECT
toDecimal32
(
'e'
,
1
);
-- { serverError
7
2 }
SELECT
toDecimal64
(
'e'
,
2
);
-- { serverError
7
2 }
SELECT
toDecimal128
(
'e'
,
3
);
-- { serverError
7
2 }
SELECT
toDecimal32OrNull
(
'e'
,
1
)
x
,
isNull
(
x
);
SELECT
toDecimal64OrNull
(
'e'
,
2
)
x
,
isNull
(
x
);
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录