Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
2dot5
ClickHouse
提交
4ace4b4c
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,发现更多精彩内容 >>
提交
4ace4b4c
编写于
6月 22, 2020
作者:
A
Alexey Milovidov
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Fix bugs in DateTime64 parsing
上级
75357ab9
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
36 addition
and
9 deletion
+36
-9
src/IO/ReadHelpers.h
src/IO/ReadHelpers.h
+36
-9
未找到文件。
src/IO/ReadHelpers.h
浏览文件 @
4ace4b4c
...
...
@@ -275,8 +275,11 @@ ReturnType readIntTextImpl(T & x, ReadBuffer & buf)
switch
(
*
buf
.
position
())
{
case
'+'
:
{
break
;
}
case
'-'
:
{
if
constexpr
(
is_signed_v
<
T
>
)
negative
=
true
;
else
...
...
@@ -287,6 +290,7 @@ ReturnType readIntTextImpl(T & x, ReadBuffer & buf)
return
ReturnType
(
false
);
}
break
;
}
case
'0'
:
[[
fallthrough
]];
case
'1'
:
[[
fallthrough
]];
case
'2'
:
[[
fallthrough
]];
...
...
@@ -297,20 +301,27 @@ ReturnType readIntTextImpl(T & x, ReadBuffer & buf)
case
'7'
:
[[
fallthrough
]];
case
'8'
:
[[
fallthrough
]];
case
'9'
:
{
if
constexpr
(
check_overflow
==
ReadIntTextCheckOverflow
::
CHECK_OVERFLOW
)
{
// perform relativelly slow overflow check only when number of decimal digits so far is close to the max for given type.
if
(
buf
.
count
()
-
initial_pos
>=
std
::
numeric_limits
<
T
>::
max_digits10
)
/// Perform relativelly slow overflow check only when
/// number of decimal digits so far is close to the max for given type.
/// Example: 20 * 10 will overflow Int8.
if
(
buf
.
count
()
-
initial_pos
+
1
>=
std
::
numeric_limits
<
T
>::
max_digits10
)
{
if
(
common
::
mulOverflow
(
res
,
static_cast
<
decltype
(
res
)
>
(
10
),
res
)
||
common
::
addOverflow
(
res
,
static_cast
<
decltype
(
res
)
>
(
*
buf
.
position
()
-
'0'
),
res
))
T
signed_res
=
res
;
if
(
common
::
mulOverflow
<
T
>
(
signed_res
,
10
,
signed_res
)
||
common
::
addOverflow
<
T
>
(
signed_res
,
(
*
buf
.
position
()
-
'0'
),
signed_res
))
return
ReturnType
(
false
);
res
=
signed_res
;
break
;
}
}
res
*=
10
;
res
+=
*
buf
.
position
()
-
'0'
;
break
;
}
default:
goto
end
;
}
...
...
@@ -318,7 +329,23 @@ ReturnType readIntTextImpl(T & x, ReadBuffer & buf)
}
end:
x
=
negative
?
-
res
:
res
;
if
(
!
negative
)
{
x
=
res
;
}
else
{
if
constexpr
(
check_overflow
==
ReadIntTextCheckOverflow
::
CHECK_OVERFLOW
)
{
x
=
res
;
if
(
common
::
mulOverflow
<
T
>
(
x
,
-
1
,
x
))
return
ReturnType
(
false
);
}
else
{
x
=
-
res
;
}
}
return
ReturnType
(
true
);
}
...
...
@@ -665,9 +692,7 @@ inline ReturnType readDateTimeTextImpl(DateTime64 & datetime64, UInt32 scale, Re
buf
.
ignore
(
1
);
// skip separator
const
auto
pos_before_fractional
=
buf
.
count
();
if
(
!
tryReadIntText
<
ReadIntTextCheckOverflow
::
CHECK_OVERFLOW
>
(
c
.
fractional
,
buf
))
{
return
ReturnType
(
false
);
}
// Adjust fractional part to the scale, since decimalFromComponents knows nothing
// about convention of ommiting trailing zero on fractional part
...
...
@@ -676,13 +701,15 @@ inline ReturnType readDateTimeTextImpl(DateTime64 & datetime64, UInt32 scale, Re
// If scale is 3, but we read '12', promote fractional part to '120'.
// And vice versa: if we read '1234', denote it to '123'.
const
auto
fractional_length
=
static_cast
<
Int32
>
(
buf
.
count
()
-
pos_before_fractional
);
if
(
const
auto
adjust_scale
=
static_cast
<
Int32
>
(
scale
)
-
fractional_length
;
adjust_scale
>
0
)
const
auto
adjust_scale
=
static_cast
<
Int32
>
(
scale
)
-
fractional_length
;
if
(
adjust_scale
>
0
)
{
c
.
fractional
*=
common
::
exp10_i64
(
adjust_scale
);
}
else
if
(
adjust_scale
<
0
)
{
c
.
fractional
/=
common
::
exp10_i64
(
-
1
*
adjust_scale
);
c
.
fractional
/=
common
::
exp10_i64
(
-
adjust_scale
);
}
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录