Skip to content

Commit

Permalink
test: add more bitmap test cases (milvus-io#36290)
Browse files Browse the repository at this point in the history
Signed-off-by: wangting0128 <[email protected]>
  • Loading branch information
wangting0128 authored Sep 16, 2024
1 parent dcd904d commit 526a672
Show file tree
Hide file tree
Showing 6 changed files with 302 additions and 66 deletions.
48 changes: 25 additions & 23 deletions tests/python_client/base/client_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,8 @@ def _teardown_objects(self):
rgs_list = self.utility_wrap.list_resource_groups()[0]
for rg_name in self.resource_group_list:
if rg_name is not None and rg_name in rgs_list:
rg = \
self.utility_wrap.describe_resource_group(name=rg_name, check_task=ct.CheckTasks.check_nothing)[0]
rg = self.utility_wrap.describe_resource_group(
name=rg_name, check_task=ct.CheckTasks.check_nothing)[0]
if isinstance(rg, ResourceGroupInfo):
if rg.num_available_node > 0:
self.utility_wrap.transfer_node(source=rg_name,
Expand Down Expand Up @@ -443,27 +443,7 @@ def show_indexes(self, collection_obj: ApiCollectionWrapper = None):
log.info("[TestcaseBase] Collection: `{0}` index: {1}".format(collection_obj.name, indexes))
return indexes


class TestCaseClassBase(TestcaseBase):
"""
Setup objects on class
"""

def setup_class(self):
log.info("[setup_class] " + " Start setup class ".center(100, "~"))
self._setup_objects(self)

def teardown_class(self):
log.info("[teardown_class]" + " Start teardown class ".center(100, "~"))
self._teardown_objects(self)

def setup_method(self, method):
log.info(" setup ".center(80, "*"))
log.info("[setup_method] Start setup test case %s." % method.__name__)

def teardown_method(self, method):
log.info(" teardown ".center(80, "*"))
log.info("[teardown_method] Start teardown test case %s..." % method.__name__)
""" Property """

@property
def all_scalar_fields(self):
Expand Down Expand Up @@ -493,3 +473,25 @@ def bitmap_support_dtype_names(self):
@property
def bitmap_not_support_dtype_names(self):
return list(set(self.all_scalar_fields) - set(self.bitmap_support_dtype_names))


class TestCaseClassBase(TestcaseBase):
"""
Setup objects on class
"""

def setup_class(self):
log.info("[setup_class] " + " Start setup class ".center(100, "~"))
self._setup_objects(self)

def teardown_class(self):
log.info("[teardown_class]" + " Start teardown class ".center(100, "~"))
self._teardown_objects(self)

def setup_method(self, method):
log.info(" setup ".center(80, "*"))
log.info("[setup_method] Start setup test case %s." % method.__name__)

def teardown_method(self, method):
log.info(" teardown ".center(80, "*"))
log.info("[teardown_method] Start teardown test case %s..." % method.__name__)
1 change: 1 addition & 0 deletions tests/python_client/common/code_mapping.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ class IndexErrorMessage(ExceptionsMessage):
CheckBitmapIndex = "bitmap index are only supported on bool, int, string and array field"
CheckBitmapOnPK = "create bitmap index on primary key not supported"
CheckBitmapCardinality = "failed to check bitmap cardinality limit, should be larger than 0 and smaller than 1000"
NotConfigable = "{0} is not configable index param"


class QueryErrorMessage(ExceptionsMessage):
Expand Down
56 changes: 56 additions & 0 deletions tests/python_client/common/common_func.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
from pymilvus import DataType, CollectionSchema
from base.schema_wrapper import ApiCollectionSchemaWrapper, ApiFieldSchemaWrapper
from common import common_type as ct
from common.common_params import ExprCheckParams
from utils.util_log import test_log as log
from customize.milvus_operator import MilvusOperator
import pickle
Expand Down Expand Up @@ -2061,6 +2062,48 @@ def gen_varchar_expression(expr_fields):
return exprs


def gen_varchar_unicode_expression(expr_fields):
exprs = []
for field in expr_fields:
exprs.extend([
(Expr.like(field, "国%").value, field, r'^国.*'),
(Expr.LIKE(field, "%中").value, field, r'.*中$'),
(Expr.AND(Expr.like(field, "%江").subset, Expr.LIKE(field, "麚%").subset).value, field, r'^麚.*江$'),
(Expr.And(Expr.like(field, "鄷%").subset, Expr.LIKE(field, "%薞").subset).value, field, r'^鄷.*薞$'),
(Expr.OR(Expr.like(field, "%核%").subset, Expr.LIKE(field, "%臥蜜").subset).value, field, fr'(?:核.*|.*臥蜜$)'),
(Expr.Or(Expr.like(field, "咴矷%").subset, Expr.LIKE(field, "%濉蠬%").subset).value, field, fr'(?:^咴矷.*|.*濉蠬)'),
])
return exprs


def gen_varchar_unicode_expression_array(expr_fields):
exprs = []
for field in expr_fields:
exprs.extend([
ExprCheckParams(field, Expr.ARRAY_CONTAINS(field, '"中"').value, 'set(["中"]).issubset({0})'),
ExprCheckParams(field, Expr.array_contains(field, '"国"').value, 'set(["国"]).issubset({0})'),
ExprCheckParams(field, Expr.ARRAY_CONTAINS_ALL(field, ["华"]).value, 'set(["华"]).issubset({0})'),
ExprCheckParams(field, Expr.array_contains_all(field, ["中", "国"]).value, 'set(["中", "国"]).issubset({0})'),
ExprCheckParams(field, Expr.ARRAY_CONTAINS_ANY(field, ["紅"]).value, 'not set(["紅"]).isdisjoint({0})'),
ExprCheckParams(field, Expr.array_contains_any(field, ["紅", "父", "环", "稵"]).value,
'not set(["紅", "父", "环", "稵"]).isdisjoint({0})'),
ExprCheckParams(field, Expr.AND(Expr.ARRAY_CONTAINS(field, '"噜"').value,
Expr.ARRAY_CONTAINS_ANY(field, ["浮", "沮", "茫"]).value).value,
'set(["噜"]).issubset({0}) and not set(["浮", "沮", "茫"]).isdisjoint({0})'),
ExprCheckParams(field, Expr.And(Expr.ARRAY_CONTAINS_ALL(field, ["爤"]).value,
Expr.array_contains_any(field, ["暁", "非", "鸳", "丹"]).value).value,
'set(["爤"]).issubset({0}) and not set(["暁", "非", "鸳", "丹"]).isdisjoint({0})'),
ExprCheckParams(field, Expr.OR(Expr.array_contains(field, '"草"').value,
Expr.array_contains_all(field, ["昩", "苴"]).value).value,
'set(["草"]).issubset({0}) or set(["昩", "苴"]).issubset({0})'),
ExprCheckParams(field, Expr.Or(Expr.ARRAY_CONTAINS_ANY(field, ["魡", "展", "隶", "韀", "脠", "噩"]).value,
Expr.array_contains_any(field, ["备", "嘎", "蝐", "秦", "万"]).value).value,
'not set(["魡", "展", "隶", "韀", "脠", "噩"]).isdisjoint({0}) or ' +
'not set(["备", "嘎", "蝐", "秦", "万"]).isdisjoint({0})')
])
return exprs


def gen_number_operation(expr_fields):
exprs = []
for field in expr_fields:
Expand Down Expand Up @@ -2747,3 +2790,16 @@ def check_keys(_source, _target):

check_keys(source, target)
return flag


def gen_unicode_string():
return chr(random.randint(0x4e00, 0x9fbf))


def gen_unicode_string_batch(nb, string_len: int = 1):
return [''.join([gen_unicode_string() for _ in range(string_len)]) for _ in range(nb)]


def gen_unicode_string_array_batch(nb, string_len: int = 1, max_capacity: int = ct.default_max_capacity):
return [[''.join([gen_unicode_string() for _ in range(min(random.randint(1, string_len), 50))]) for _ in
range(random.randint(0, max_capacity))] for _ in range(nb)]
7 changes: 7 additions & 0 deletions tests/python_client/common/common_params.py
Original file line number Diff line number Diff line change
Expand Up @@ -388,3 +388,10 @@ def index_offset_cache(enable: bool = True):
@staticmethod
def index_mmap(enable: bool = True):
return {'mmap.enabled': enable}


@dataclass
class ExprCheckParams:
field: str
field_expr: str
rex: str
Loading

0 comments on commit 526a672

Please sign in to comment.