Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
milvus
milvus
提交
8f52e5b6
M
milvus
项目概览
milvus
/
milvus
11 个月 前同步成功
通知
260
Star
22476
Fork
2472
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
M
milvus
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
未验证
提交
8f52e5b6
编写于
3月 10, 2022
作者:
L
Letian Jiang
提交者:
GitHub
3月 10, 2022
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Add unit tests in segcore (#15960)
Signed-off-by:
N
Letian Jiang
<
letian.jiang@zilliz.com
>
上级
c6839bc7
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
75 addition
and
0 deletion
+75
-0
internal/core/unittest/test_segcore.cpp
internal/core/unittest/test_segcore.cpp
+75
-0
未找到文件。
internal/core/unittest/test_segcore.cpp
浏览文件 @
8f52e5b6
...
...
@@ -56,6 +56,7 @@ TEST(SegmentCoreTest, NormalDistributionTest) {
segment
->
PreDelete
(
N
);
}
// Test insert row-based data
TEST
(
SegmentCoreTest
,
MockTest
)
{
using
namespace
milvus
::
segcore
;
using
namespace
milvus
::
engine
;
...
...
@@ -95,6 +96,80 @@ TEST(SegmentCoreTest, MockTest) {
i
++
;
}
// Test insert column-based data
TEST
(
SegmentCoreTest
,
MockTest2
)
{
using
namespace
milvus
::
segcore
;
using
namespace
milvus
::
engine
;
// schema
auto
schema
=
std
::
make_shared
<
Schema
>
();
schema
->
AddDebugField
(
"fakevec"
,
DataType
::
VECTOR_FLOAT
,
16
,
MetricType
::
METRIC_L2
);
schema
->
AddDebugField
(
"age"
,
DataType
::
INT32
);
// generate random row-based data
std
::
vector
<
char
>
row_data
;
std
::
vector
<
Timestamp
>
timestamps
;
std
::
vector
<
int64_t
>
uids
;
int
N
=
10000
;
// number of records
std
::
default_random_engine
e
(
67
);
for
(
int
i
=
0
;
i
<
N
;
++
i
)
{
uids
.
push_back
(
100000
+
i
);
timestamps
.
push_back
(
0
);
// append vec
float
vec
[
16
];
for
(
auto
&
x
:
vec
)
{
x
=
e
()
%
2000
*
0.001
-
1.0
;
}
row_data
.
insert
(
row_data
.
end
(),
(
const
char
*
)
std
::
begin
(
vec
),
(
const
char
*
)
std
::
end
(
vec
));
int
age
=
e
()
%
100
;
row_data
.
insert
(
row_data
.
end
(),
(
const
char
*
)
&
age
,
((
const
char
*
)
&
age
)
+
sizeof
(
age
));
}
auto
line_sizeof
=
(
sizeof
(
int
)
+
sizeof
(
float
)
*
16
);
assert
(
row_data
.
size
()
==
line_sizeof
*
N
);
int64_t
size
=
N
;
const
int64_t
*
uids_raw
=
uids
.
data
();
const
Timestamp
*
timestamps_raw
=
timestamps
.
data
();
std
::
vector
<
std
::
tuple
<
Timestamp
,
idx_t
,
int64_t
>>
ordering
(
size
);
// timestamp, pk, order_index
for
(
int
i
=
0
;
i
<
size
;
++
i
)
{
ordering
[
i
]
=
std
::
make_tuple
(
timestamps_raw
[
i
],
uids_raw
[
i
],
i
);
}
std
::
sort
(
ordering
.
begin
(),
ordering
.
end
());
// sort according to timestamp
// convert row-based data to column-based data accordingly
auto
sizeof_infos
=
schema
->
get_sizeof_infos
();
std
::
vector
<
int
>
offset_infos
(
schema
->
size
()
+
1
,
0
);
std
::
partial_sum
(
sizeof_infos
.
begin
(),
sizeof_infos
.
end
(),
offset_infos
.
begin
()
+
1
);
std
::
vector
<
aligned_vector
<
uint8_t
>>
entities
(
schema
->
size
());
for
(
int
fid
=
0
;
fid
<
schema
->
size
();
++
fid
)
{
auto
len
=
sizeof_infos
[
fid
];
entities
[
fid
].
resize
(
len
*
size
);
}
auto
raw_data
=
row_data
.
data
();
std
::
vector
<
idx_t
>
sorted_uids
(
size
);
std
::
vector
<
Timestamp
>
sorted_timestamps
(
size
);
for
(
int
index
=
0
;
index
<
size
;
++
index
)
{
auto
[
t
,
uid
,
order_index
]
=
ordering
[
index
];
sorted_timestamps
[
index
]
=
t
;
sorted_uids
[
index
]
=
uid
;
for
(
int
fid
=
0
;
fid
<
schema
->
size
();
++
fid
)
{
auto
len
=
sizeof_infos
[
fid
];
auto
offset
=
offset_infos
[
fid
];
auto
src
=
raw_data
+
order_index
*
line_sizeof
+
offset
;
auto
dst
=
entities
[
fid
].
data
()
+
index
*
len
;
memcpy
(
dst
,
src
,
len
);
}
}
// insert column-based data
ColumnBasedRawData
data_chunk
{
entities
,
N
};
auto
segment
=
CreateGrowingSegment
(
schema
);
auto
reserved_begin
=
segment
->
PreInsert
(
N
);
segment
->
Insert
(
reserved_begin
,
size
,
sorted_uids
.
data
(),
sorted_timestamps
.
data
(),
data_chunk
);
}
TEST
(
SegmentCoreTest
,
SmallIndex
)
{
using
namespace
milvus
::
segcore
;
using
namespace
milvus
::
engine
;
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录