Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
2dot5
ClickHouse
提交
0ba72436
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,发现更多精彩内容 >>
提交
0ba72436
编写于
4月 18, 2017
作者:
A
artpaul
提交者:
alexey-milovidov
4月 19, 2017
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
#214 fix conversion from fixed-string to string
上级
1fedee71
变更
3
显示空白变更内容
内联
并排
Showing
3 changed file
with
45 addition
and
24 deletion
+45
-24
dbms/src/Functions/FunctionsStringSearch.cpp
dbms/src/Functions/FunctionsStringSearch.cpp
+30
-24
dbms/tests/queries/0_stateless/00394_replaceall_vector_fixed.reference
...eries/0_stateless/00394_replaceall_vector_fixed.reference
+4
-0
dbms/tests/queries/0_stateless/00394_replaceall_vector_fixed.sql
...sts/queries/0_stateless/00394_replaceall_vector_fixed.sql
+11
-0
未找到文件。
dbms/src/Functions/FunctionsStringSearch.cpp
浏览文件 @
0ba72436
...
...
@@ -832,6 +832,8 @@ struct ReplaceStringImpl
}
}
/// Note: this function converts fixed-length strings to variable-length strings
/// and each variable-length string should ends with zero byte.
static
void
vector_fixed
(
const
ColumnString
::
Chars_t
&
data
,
size_t
n
,
const
std
::
string
&
needle
,
...
...
@@ -844,9 +846,9 @@ struct ReplaceStringImpl
const
UInt8
*
end
=
pos
+
data
.
size
();
ColumnString
::
Offset_t
res_offset
=
0
;
size_t
size
=
data
.
size
()
/
n
;
size_t
count
=
data
.
size
()
/
n
;
res_data
.
reserve
(
data
.
size
());
res_offsets
.
resize
(
size
);
res_offsets
.
resize
(
count
);
/// The current index in the string array.
size_t
i
=
0
;
...
...
@@ -858,33 +860,45 @@ struct ReplaceStringImpl
{
const
UInt8
*
match
=
searcher
.
search
(
pos
,
end
-
pos
);
/// Copy the data without changing
res_data
.
resize
(
res_data
.
size
()
+
(
match
-
pos
));
memcpy
(
&
res_data
[
res_offset
],
pos
,
match
-
pos
);
#define COPY_REST_OF_CURRENT_STRING() \
do { \
const size_t len = begin + n * (i + 1) - pos; \
res_data.resize(res_data.size() + len + 1); \
memcpy(&res_data[res_offset], pos, len); \
res_offset += len; \
res_data[res_offset++] = 0; \
res_offsets[i] = res_offset; \
pos = begin + n * (i + 1); \
++i; \
} while (false)
/// Let's determine which index it belongs to.
while
(
i
<
size
&&
begin
+
n
*
(
i
+
1
)
<=
match
)
/// Copy skipped strings without any changes but
/// add zero byte to the end of each string.
while
(
i
<
count
&&
begin
+
n
*
(
i
+
1
)
<=
match
)
{
res_offsets
[
i
]
=
res_offset
+
((
begin
+
n
*
(
i
+
1
))
-
pos
)
+
1
;
++
i
;
COPY_REST_OF_CURRENT_STRING
();
}
res_offset
+=
(
match
-
pos
);
/// If you have reached the end, it's time to stop
if
(
i
==
size
)
if
(
i
==
count
)
break
;
/// Copy unchanged part of current string.
res_data
.
resize
(
res_data
.
size
()
+
(
match
-
pos
));
memcpy
(
&
res_data
[
res_offset
],
pos
,
match
-
pos
);
res_offset
+=
(
match
-
pos
);
/// Is it true that this line no longer needs to perform conversions.
bool
can_finish_current_string
=
false
;
/// We check that the entry does not pass through the boundaries of strings.
if
(
match
+
needle
.
size
()
-
1
<
begin
+
n
*
(
i
+
1
))
if
(
match
+
needle
.
size
()
<=
begin
+
n
*
(
i
+
1
))
{
res_data
.
resize
(
res_data
.
size
()
+
replacement
.
size
());
memcpy
(
&
res_data
[
res_offset
],
replacement
.
data
(),
replacement
.
size
());
res_offset
+=
replacement
.
size
();
pos
=
match
+
needle
.
size
();
if
(
replace_one
)
if
(
replace_one
||
pos
==
begin
+
n
*
(
i
+
1
)
)
can_finish_current_string
=
true
;
}
else
...
...
@@ -895,17 +909,9 @@ struct ReplaceStringImpl
if
(
can_finish_current_string
)
{
res_data
.
resize
(
res_data
.
size
()
+
(
begin
+
n
*
(
i
+
1
)
-
pos
));
memcpy
(
&
res_data
[
res_offset
],
pos
,
(
begin
+
n
*
(
i
+
1
)
-
pos
));
res_offset
+=
(
begin
+
n
*
(
i
+
1
)
-
pos
);
res_offsets
[
i
]
=
res_offset
;
pos
=
begin
+
n
*
(
i
+
1
);
}
COPY_REST_OF_CURRENT_STRING
();
}
if
(
i
<
size
)
{
res_offsets
[
i
]
=
res_offset
+
((
begin
+
n
*
(
i
+
1
))
-
pos
)
+
1
;
#undef COPY_REST_OF_CURRENT_STRING
}
}
...
...
dbms/tests/queries/0_stateless/00394_replaceall_vector_fixed.reference
浏览文件 @
0ba72436
...
...
@@ -2,3 +2,7 @@ bao ba*
bar bar
boa b*a
foo f**
54db0d43009d\0\0\0\0 54db0d43009d****
fe2b58224766cf10 fe2b58224766cf10
54db0d43009d\0\0\0\0 54db0d43009d****
fe2b58224766cf10 fe2b58224766cf10
dbms/tests/queries/0_stateless/00394_replaceall_vector_fixed.sql
浏览文件 @
0ba72436
...
...
@@ -13,3 +13,14 @@ FROM test.replaceall
ORDER
BY
str
ASC
;
DROP
TABLE
test
.
replaceall
;
CREATE
TABLE
test
.
replaceall
(
date
Date
DEFAULT
today
(),
fs
FixedString
(
16
))
ENGINE
=
MergeTree
(
date
,
(
date
,
fs
),
8192
);
INSERT
INTO
test
(
fs
)
VALUES
(
'54db0d43009d
\0\0\0\0
'
),
(
'fe2b58224766cf10'
),
(
'54db0d43009d
\0\0\0\0
'
),
(
'fe2b58224766cf10'
);
SELECT
fs
,
replaceAll
(
fs
,
'
\0
'
,
'*'
)
FROM
test
.
replaceall
ORDER
BY
fs
ASC
;
DROP
TABLE
test
.
replaceall
;
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录