Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
2dot5
ClickHouse
提交
125bf1d0
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,体验更适合开发者的 AI 搜索 >>
未验证
提交
125bf1d0
编写于
2月 21, 2021
作者:
A
alexey-milovidov
提交者:
GitHub
2月 21, 2021
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #20479 from ucasFL/tr
fix transform with floating point key
上级
20a7ccf5
5d3b8d99
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
92 addition
and
39 deletion
+92
-39
src/Functions/transform.cpp
src/Functions/transform.cpp
+59
-39
tests/queries/0_stateless/01704_transform_with_float_key.reference
...ries/0_stateless/01704_transform_with_float_key.reference
+30
-0
tests/queries/0_stateless/01704_transform_with_float_key.sql
tests/queries/0_stateless/01704_transform_with_float_key.sql
+3
-0
未找到文件。
src/Functions/transform.cpp
浏览文件 @
125bf1d0
#include <mutex>
#include <ext/bit_cast.h>
#include <Common/FieldVisitors.h>
#include <DataTypes/DataTypeArray.h>
#include <Columns/ColumnString.h>
...
...
@@ -13,6 +15,7 @@
#include <Functions/FunctionHelpers.h>
#include <Functions/FunctionFactory.h>
#include <DataTypes/getLeastSupertype.h>
#include <Interpreters/convertFieldToType.h>
namespace
DB
...
...
@@ -491,7 +494,7 @@ private:
dst
.
resize
(
size
);
for
(
size_t
i
=
0
;
i
<
size
;
++
i
)
{
auto
it
=
table
.
find
(
src
[
i
]
);
const
auto
*
it
=
table
.
find
(
ext
::
bit_cast
<
UInt64
>
(
src
[
i
])
);
if
(
it
)
memcpy
(
&
dst
[
i
],
&
it
->
getMapped
(),
sizeof
(
dst
[
i
]));
/// little endian.
else
...
...
@@ -507,7 +510,7 @@ private:
dst
.
resize
(
size
);
for
(
size_t
i
=
0
;
i
<
size
;
++
i
)
{
auto
it
=
table
.
find
(
src
[
i
]
);
const
auto
*
it
=
table
.
find
(
ext
::
bit_cast
<
UInt64
>
(
src
[
i
])
);
if
(
it
)
memcpy
(
&
dst
[
i
],
&
it
->
getMapped
(),
sizeof
(
dst
[
i
]));
/// little endian.
else
...
...
@@ -523,7 +526,7 @@ private:
dst
.
resize
(
size
);
for
(
size_t
i
=
0
;
i
<
size
;
++
i
)
{
auto
it
=
table
.
find
(
src
[
i
]
);
const
auto
*
it
=
table
.
find
(
ext
::
bit_cast
<
UInt64
>
(
src
[
i
])
);
if
(
it
)
memcpy
(
&
dst
[
i
],
&
it
->
getMapped
(),
sizeof
(
dst
[
i
]));
else
...
...
@@ -541,7 +544,7 @@ private:
ColumnString
::
Offset
current_dst_offset
=
0
;
for
(
size_t
i
=
0
;
i
<
size
;
++
i
)
{
auto
it
=
table
.
find
(
src
[
i
]
);
const
auto
*
it
=
table
.
find
(
ext
::
bit_cast
<
UInt64
>
(
src
[
i
])
);
StringRef
ref
=
it
?
it
->
getMapped
()
:
dst_default
;
dst_data
.
resize
(
current_dst_offset
+
ref
.
size
);
memcpy
(
&
dst_data
[
current_dst_offset
],
ref
.
data
,
ref
.
size
);
...
...
@@ -562,7 +565,8 @@ private:
ColumnString
::
Offset
current_dst_default_offset
=
0
;
for
(
size_t
i
=
0
;
i
<
size
;
++
i
)
{
auto
it
=
table
.
find
(
src
[
i
]);
Field
key
=
src
[
i
];
const
auto
*
it
=
table
.
find
(
key
.
reinterpret
<
UInt64
>
());
StringRef
ref
;
if
(
it
)
...
...
@@ -778,50 +782,66 @@ private:
/// Note: Doesn't check the duplicates in the `from` array.
if
(
from
[
0
].
getType
()
!=
Field
::
Types
::
String
&&
to
[
0
].
getType
()
!=
Field
::
Types
::
String
)
const
IDataType
&
from_type
=
*
arguments
[
0
].
type
;
if
(
from
[
0
].
getType
()
!=
Field
::
Types
::
String
)
{
cache
.
table_num_to_num
=
std
::
make_unique
<
Cache
::
NumToNum
>
();
auto
&
table
=
*
cache
.
table_num_to_num
;
for
(
size_t
i
=
0
;
i
<
size
;
++
i
)
if
(
to
[
0
].
getType
()
!=
Field
::
Types
::
String
)
{
// Field may be of Float type, but for the purpose of bitwise
// equality we can treat them as UInt64, hence the reinterpret().
table
[
from
[
i
].
reinterpret
<
UInt64
>
()]
=
(
*
used_to
)[
i
].
reinterpret
<
UInt64
>
();
cache
.
table_num_to_num
=
std
::
make_unique
<
Cache
::
NumToNum
>
();
auto
&
table
=
*
cache
.
table_num_to_num
;
for
(
size_t
i
=
0
;
i
<
size
;
++
i
)
{
Field
key
=
convertFieldToType
(
from
[
i
],
from_type
);
if
(
key
.
isNull
())
continue
;
// Field may be of Float type, but for the purpose of bitwise
// equality we can treat them as UInt64, hence the reinterpret().
table
[
key
.
reinterpret
<
UInt64
>
()]
=
(
*
used_to
)[
i
].
reinterpret
<
UInt64
>
();
}
}
}
else
if
(
from
[
0
].
getType
()
!=
Field
::
Types
::
String
&&
to
[
0
].
getType
()
==
Field
::
Types
::
String
)
{
cache
.
table_num_to_string
=
std
::
make_unique
<
Cache
::
NumToString
>
();
auto
&
table
=
*
cache
.
table_num_to_string
;
for
(
size_t
i
=
0
;
i
<
size
;
++
i
)
else
{
const
String
&
str_to
=
to
[
i
].
get
<
const
String
&>
();
StringRef
ref
{
cache
.
string_pool
.
insert
(
str_to
.
data
(),
str_to
.
size
()
+
1
),
str_to
.
size
()
+
1
};
table
[
from
[
i
].
reinterpret
<
UInt64
>
()]
=
ref
;
cache
.
table_num_to_string
=
std
::
make_unique
<
Cache
::
NumToString
>
();
auto
&
table
=
*
cache
.
table_num_to_string
;
for
(
size_t
i
=
0
;
i
<
size
;
++
i
)
{
Field
key
=
convertFieldToType
(
from
[
i
],
from_type
);
if
(
key
.
isNull
())
continue
;
const
String
&
str_to
=
to
[
i
].
get
<
const
String
&>
();
StringRef
ref
{
cache
.
string_pool
.
insert
(
str_to
.
data
(),
str_to
.
size
()
+
1
),
str_to
.
size
()
+
1
};
table
[
key
.
reinterpret
<
UInt64
>
()]
=
ref
;
}
}
}
else
if
(
from
[
0
].
getType
()
==
Field
::
Types
::
String
&&
to
[
0
].
getType
()
!=
Field
::
Types
::
String
)
else
{
cache
.
table_string_to_num
=
std
::
make_unique
<
Cache
::
StringToNum
>
();
auto
&
table
=
*
cache
.
table_string_to_num
;
for
(
size_t
i
=
0
;
i
<
size
;
++
i
)
if
(
to
[
0
].
getType
()
!=
Field
::
Types
::
String
)
{
const
String
&
str_from
=
from
[
i
].
get
<
const
String
&>
();
StringRef
ref
{
cache
.
string_pool
.
insert
(
str_from
.
data
(),
str_from
.
size
()
+
1
),
str_from
.
size
()
+
1
};
table
[
ref
]
=
(
*
used_to
)[
i
].
reinterpret
<
UInt64
>
();
cache
.
table_string_to_num
=
std
::
make_unique
<
Cache
::
StringToNum
>
();
auto
&
table
=
*
cache
.
table_string_to_num
;
for
(
size_t
i
=
0
;
i
<
size
;
++
i
)
{
const
String
&
str_from
=
from
[
i
].
get
<
const
String
&>
();
StringRef
ref
{
cache
.
string_pool
.
insert
(
str_from
.
data
(),
str_from
.
size
()
+
1
),
str_from
.
size
()
+
1
};
table
[
ref
]
=
(
*
used_to
)[
i
].
reinterpret
<
UInt64
>
();
}
}
}
else
if
(
from
[
0
].
getType
()
==
Field
::
Types
::
String
&&
to
[
0
].
getType
()
==
Field
::
Types
::
String
)
{
cache
.
table_string_to_string
=
std
::
make_unique
<
Cache
::
StringToString
>
();
auto
&
table
=
*
cache
.
table_string_to_string
;
for
(
size_t
i
=
0
;
i
<
size
;
++
i
)
else
{
const
String
&
str_from
=
from
[
i
].
get
<
const
String
&>
();
const
String
&
str_to
=
to
[
i
].
get
<
const
String
&>
();
StringRef
ref_from
{
cache
.
string_pool
.
insert
(
str_from
.
data
(),
str_from
.
size
()
+
1
),
str_from
.
size
()
+
1
};
StringRef
ref_to
{
cache
.
string_pool
.
insert
(
str_to
.
data
(),
str_to
.
size
()
+
1
),
str_to
.
size
()
+
1
};
table
[
ref_from
]
=
ref_to
;
cache
.
table_string_to_string
=
std
::
make_unique
<
Cache
::
StringToString
>
();
auto
&
table
=
*
cache
.
table_string_to_string
;
for
(
size_t
i
=
0
;
i
<
size
;
++
i
)
{
const
String
&
str_from
=
from
[
i
].
get
<
const
String
&>
();
const
String
&
str_to
=
to
[
i
].
get
<
const
String
&>
();
StringRef
ref_from
{
cache
.
string_pool
.
insert
(
str_from
.
data
(),
str_from
.
size
()
+
1
),
str_from
.
size
()
+
1
};
StringRef
ref_to
{
cache
.
string_pool
.
insert
(
str_to
.
data
(),
str_to
.
size
()
+
1
),
str_to
.
size
()
+
1
};
table
[
ref_from
]
=
ref_to
;
}
}
}
...
...
tests/queries/0_stateless/01704_transform_with_float_key.reference
0 → 100644
浏览文件 @
125bf1d0
-
Hello
-
World
-
-
-
-
-
-
-
-
Hello
-
World
-
-
-
-
-
-
-
Hello
-
World
-
-
-
-
-
tests/queries/0_stateless/01704_transform_with_float_key.sql
0 → 100644
浏览文件 @
125bf1d0
SELECT
transform
(
number
/
2
,
[
0
.
5
,
1
.
5
],
[
'Hello'
,
'World'
],
'-'
)
FROM
numbers
(
10
);
SELECT
transform
(
number
/
2
,
[
1
.
0
,
2
.
0
],
[
'Hello'
,
'World'
],
'-'
)
FROM
numbers
(
10
);
SELECT
transform
(
number
/
2
,
[
1
,
2
],
[
'Hello'
,
'World'
],
'-'
)
FROM
numbers
(
10
);
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录