Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
2dot5
ClickHouse
提交
ff3e5e1a
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,发现更多精彩内容 >>
提交
ff3e5e1a
编写于
6月 14, 2020
作者:
A
Alexey Milovidov
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Allow implicit conversion from String in IN, VALUES and comparison #11630
上级
eec5abde
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
19 addition
and
10 deletion
+19
-10
src/Interpreters/convertFieldToType.cpp
src/Interpreters/convertFieldToType.cpp
+19
-10
未找到文件。
src/Interpreters/convertFieldToType.cpp
浏览文件 @
ff3e5e1a
...
...
@@ -148,7 +148,7 @@ Field convertFieldToTypeImpl(const Field & src, const IDataType & type, const ID
{
return
static_cast
<
const
DataTypeDateTime
&>
(
type
).
getTimeZone
().
fromDayNum
(
DayNum
(
src
.
get
<
UInt64
>
()));
}
else
if
(
type
.
isValueRepresentedByNumber
())
else
if
(
type
.
isValueRepresentedByNumber
()
&&
src
.
getType
()
!=
Field
::
Types
::
String
)
{
if
(
which_type
.
isUInt8
())
return
convertNumericType
<
UInt8
>
(
src
,
type
);
if
(
which_type
.
isUInt16
())
return
convertNumericType
<
UInt16
>
(
src
,
type
);
...
...
@@ -164,9 +164,6 @@ Field convertFieldToTypeImpl(const Field & src, const IDataType & type, const ID
if
(
const
auto
*
ptype
=
typeid_cast
<
const
DataTypeDecimal
<
Decimal64
>
*>
(
&
type
))
return
convertDecimalType
(
src
,
*
ptype
);
if
(
const
auto
*
ptype
=
typeid_cast
<
const
DataTypeDecimal
<
Decimal128
>
*>
(
&
type
))
return
convertDecimalType
(
src
,
*
ptype
);
if
(
!
which_type
.
isDateOrDateTime
()
&&
!
which_type
.
isUUID
()
&&
!
which_type
.
isEnum
())
throw
Exception
{
"Cannot convert field to type "
+
type
.
getName
(),
ErrorCodes
::
CANNOT_CONVERT_TYPE
};
if
(
which_type
.
isEnum
()
&&
(
src
.
getType
()
==
Field
::
Types
::
UInt64
||
src
.
getType
()
==
Field
::
Types
::
Int64
))
{
/// Convert UInt64 or Int64 to Enum's value
...
...
@@ -263,17 +260,29 @@ Field convertFieldToTypeImpl(const Field & src, const IDataType & type, const ID
return
src
;
}
/// Conversion from string by parsing.
if
(
src
.
getType
()
==
Field
::
Types
::
String
)
{
const
auto
col
=
type
.
createColumn
();
ReadBufferFromString
buffer
(
src
.
get
<
String
>
())
;
type
.
deserializeAsTextEscaped
(
*
col
,
buffer
,
FormatSettings
{})
;
/// Promote data type to avoid overflows. Note that overflows in the largest data type are still possible.
const
IDataType
*
type_to_parse
=
&
type
;
DataTypePtr
holder
;
return
(
*
col
)[
0
];
}
if
(
type
.
canBePromoted
())
{
holder
=
type
.
promoteNumericType
();
type_to_parse
=
holder
.
get
();
}
const
auto
col
=
type_to_parse
->
createColumn
();
ReadBufferFromString
in_buffer
(
src
.
get
<
String
>
());
type_to_parse
->
deserializeAsWholeText
(
*
col
,
in_buffer
,
FormatSettings
{});
if
(
!
in_buffer
.
eof
())
throw
Exception
(
ErrorCodes
::
TOO_LARGE_STRING_SIZE
,
"String is too long for {}: {}"
,
type
.
getName
(),
src
.
get
<
String
>
());
Field
parsed
=
(
*
col
)[
0
];
return
convertFieldToType
(
parsed
,
type
,
from_type_hint
);
}
// TODO (nemkov): should we attempt to parse value using or `type.deserializeAsTextEscaped()` type.deserializeAsTextEscaped() ?
throw
Exception
(
"Type mismatch in IN or VALUES section. Expected: "
+
type
.
getName
()
+
". Got: "
+
Field
::
Types
::
toString
(
src
.
getType
()),
ErrorCodes
::
TYPE_MISMATCH
);
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录