Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
milvus
milvus
提交
f9341f66
M
milvus
项目概览
milvus
/
milvus
10 个月 前同步成功
通知
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,体验更适合开发者的 AI 搜索 >>
未验证
提交
f9341f66
编写于
8月 16, 2023
作者:
N
nico
提交者:
GitHub
8月 16, 2023
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Add test cases of query empty expression (#26271)
Signed-off-by:
N
nico
<
cheng.yuan@zilliz.com
>
上级
5dae6a65
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
153 addition
and
1 deletion
+153
-1
tests/python_client/testcases/test_query.py
tests/python_client/testcases/test_query.py
+153
-1
未找到文件。
tests/python_client/testcases/test_query.py
浏览文件 @
f9341f66
...
...
@@ -592,7 +592,7 @@ class TestQueryParams(TestcaseBase):
res
=
collection_w
.
query
(
expression
)[
0
]
assert
len
(
res
)
==
limit
@
pytest
.
mark
.
tags
(
CaseLabel
.
L
2
)
@
pytest
.
mark
.
tags
(
CaseLabel
.
L
1
)
def
test_query_expr_list_json_contains
(
self
):
"""
target: test query with expression using json_contains
...
...
@@ -686,6 +686,158 @@ class TestQueryParams(TestcaseBase):
res
=
collection_w
.
query
(
expression
,
limit
=
limit
,
offset
=
offset
)[
0
]
assert
len
(
res
)
==
limit
-
offset
@
pytest
.
mark
.
tags
(
CaseLabel
.
L1
)
def
test_query_expr_empty_without_limit
(
self
):
"""
target: test query with empty expression and no limit
method: query empty expression without setting limit
expected: raise error
"""
# 1. initialize with data
collection_w
=
self
.
init_collection_general
(
prefix
,
True
)[
0
]
# 2. query with no limit and no offset
error
=
{
ct
.
err_code
:
1
,
ct
.
err_msg
:
"empty expression should be used with limit"
}
collection_w
.
query
(
""
,
check_task
=
CheckTasks
.
err_res
,
check_items
=
error
)
# 3. query with offset but no limit
collection_w
.
query
(
""
,
offset
=
1
,
check_task
=
CheckTasks
.
err_res
,
check_items
=
error
)
@
pytest
.
mark
.
tags
(
CaseLabel
.
L2
)
def
test_query_empty
(
self
):
"""
target: test query empty
method: query empty
expected: return error
"""
# 1. initialize with data
collection_w
=
self
.
init_collection_general
(
prefix
,
True
)[
0
]
# 2. query
try
:
collection_w
.
query
()
except
TypeError
as
e
:
assert
"missing 1 required positional argument: 'expr'"
in
str
(
e
)
@
pytest
.
mark
.
tags
(
CaseLabel
.
L0
)
@
pytest
.
mark
.
parametrize
(
"limit"
,
[
10
,
100
,
1000
])
@
pytest
.
mark
.
parametrize
(
"auto_id"
,
[
True
,
False
])
def
test_query_expr_empty
(
self
,
auto_id
,
limit
):
"""
target: test query with empty expression
method: query empty expression with a limit
expected: return topK results by order
"""
# 1. initialize with data
collection_w
,
_
,
_
,
insert_ids
=
self
.
init_collection_general
(
prefix
,
True
,
auto_id
=
auto_id
)[
0
:
4
]
exp_ids
,
res
=
insert_ids
[:
limit
],
[]
for
ids
in
exp_ids
:
res
.
append
({
ct
.
default_int64_field_name
:
ids
})
# 2. query with limit
collection_w
.
query
(
""
,
limit
=
limit
,
check_task
=
CheckTasks
.
check_query_results
,
check_items
=
{
exp_res
:
res
})
@
pytest
.
mark
.
tags
(
CaseLabel
.
L2
)
def
test_query_expr_empty_pk_string
(
self
):
"""
target: test query with empty expression
method: query empty expression with a limit
expected: return topK results by order
"""
# 1. initialize with data
collection_w
,
_
,
_
,
insert_ids
=
\
self
.
init_collection_general
(
prefix
,
True
,
primary_field
=
ct
.
default_string_field_name
)[
0
:
4
]
# string field is sorted by lexicographical order
exp_ids
,
res
=
[
'0'
,
'1'
,
'10'
,
'100'
,
'1000'
,
'1001'
,
'1002'
,
'1003'
,
'1004'
,
'1005'
],
[]
for
ids
in
exp_ids
:
res
.
append
({
ct
.
default_string_field_name
:
ids
})
# 2. query with limit
collection_w
.
query
(
""
,
limit
=
ct
.
default_limit
,
check_task
=
CheckTasks
.
check_query_results
,
check_items
=
{
exp_res
:
res
})
# 2. query with limit + offset
res
=
res
[
5
:]
collection_w
.
query
(
""
,
limit
=
5
,
offset
=
5
,
check_task
=
CheckTasks
.
check_query_results
,
check_items
=
{
exp_res
:
res
})
@
pytest
.
mark
.
tags
(
CaseLabel
.
L1
)
@
pytest
.
mark
.
parametrize
(
"offset"
,
[
100
,
1000
])
@
pytest
.
mark
.
parametrize
(
"limit"
,
[
100
,
1000
])
@
pytest
.
mark
.
parametrize
(
"auto_id"
,
[
True
,
False
])
def
test_query_expr_empty_with_pagination
(
self
,
auto_id
,
limit
,
offset
):
"""
target: test query with empty expression
method: query empty expression with a limit
expected: return topK results by order
"""
# 1. initialize with data
collection_w
,
_
,
_
,
insert_ids
=
self
.
init_collection_general
(
prefix
,
True
,
auto_id
=
auto_id
)[
0
:
4
]
exp_ids
,
res
=
insert_ids
[:
limit
+
offset
][
offset
:],
[]
for
ids
in
exp_ids
:
res
.
append
({
ct
.
default_int64_field_name
:
ids
})
# 2. query with limit and offset
collection_w
.
query
(
""
,
limit
=
limit
,
offset
=
offset
,
check_task
=
CheckTasks
.
check_query_results
,
check_items
=
{
exp_res
:
res
})
@
pytest
.
mark
.
tags
(
CaseLabel
.
L2
)
@
pytest
.
mark
.
parametrize
(
"offset"
,
[
100
,
1000
])
@
pytest
.
mark
.
parametrize
(
"limit"
,
[
100
,
1000
])
def
test_query_expr_empty_with_random_pk
(
self
,
limit
,
offset
):
"""
target: test query with empty expression
method: create a collection using random pk, query empty expression with a limit
expected: return topK results by order
"""
# 1. initialize with data
collection_w
=
self
.
init_collection_general
(
prefix
,
with_json
=
False
)[
0
]
# 2. generate unordered pk array and insert
unordered_ids
=
[
i
for
i
in
range
(
ct
.
default_nb
)]
random
.
shuffle
(
unordered_ids
)
float_value
=
[
np
.
float32
(
i
)
for
i
in
unordered_ids
]
string_value
=
[
str
(
i
)
for
i
in
unordered_ids
]
vector_value
=
cf
.
gen_vectors
(
nb
=
ct
.
default_nb
,
dim
=
ct
.
default_dim
)
collection_w
.
insert
([
unordered_ids
,
float_value
,
string_value
,
vector_value
])
collection_w
.
load
()
# 3. query with empty expr and check the result
exp_ids
,
res
=
sorted
(
unordered_ids
)[:
limit
],
[]
for
ids
in
exp_ids
:
res
.
append
({
ct
.
default_int64_field_name
:
ids
,
ct
.
default_string_field_name
:
str
(
ids
)})
collection_w
.
query
(
""
,
limit
=
limit
,
output_fields
=
[
ct
.
default_string_field_name
],
check_task
=
CheckTasks
.
check_query_results
,
check_items
=
{
exp_res
:
res
})
# 4. query with pagination
exp_ids
,
res
=
sorted
(
unordered_ids
)[:
limit
+
offset
][
offset
:],
[]
for
ids
in
exp_ids
:
res
.
append
({
ct
.
default_int64_field_name
:
ids
,
ct
.
default_string_field_name
:
str
(
ids
)})
collection_w
.
query
(
""
,
limit
=
limit
,
offset
=
offset
,
output_fields
=
[
ct
.
default_string_field_name
],
check_task
=
CheckTasks
.
check_query_results
,
check_items
=
{
exp_res
:
res
})
@
pytest
.
mark
.
tags
(
CaseLabel
.
L0
)
def
test_query_expr_with_limit_offset_out_of_range
(
self
):
"""
target: test query with empty expression
method: query empty expression with limit and offset out of range
expected: raise error
"""
# 1. initialize with data
collection_w
=
self
.
init_collection_general
(
prefix
,
True
)[
0
]
# 2. query with limit > 16384
error
=
{
ct
.
err_code
:
1
,
ct
.
err_msg
:
"invalid max query result window, (offset+limit) should be in range [1, 16384]"
}
collection_w
.
query
(
""
,
limit
=
16385
,
check_task
=
CheckTasks
.
err_res
,
check_items
=
error
)
# 3. query with offset + limit > 16384
collection_w
.
query
(
""
,
limit
=
1
,
offset
=
16384
,
check_task
=
CheckTasks
.
err_res
,
check_items
=
error
)
collection_w
.
query
(
""
,
limit
=
16384
,
offset
=
1
,
check_task
=
CheckTasks
.
err_res
,
check_items
=
error
)
# 4. query with limit < 0
error
=
{
ct
.
err_code
:
1
,
ct
.
err_msg
:
"invalid max query result window, offset [-1] is invalid, should be gte than 0"
}
collection_w
.
query
(
""
,
limit
=
2
,
offset
=-
1
,
check_task
=
CheckTasks
.
err_res
,
check_items
=
error
)
@
pytest
.
mark
.
tags
(
CaseLabel
.
L1
)
def
test_query_output_field_none_or_empty
(
self
,
enable_dynamic_field
):
"""
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录