Skip to content

Commit

Permalink
test: add json and array datatype check in restful v1 (#31096)
Browse files Browse the repository at this point in the history
pr: #31097

* When the collection is created using an SDK and includes array and
JSON datatypes in the schema, data can be inserted using the RESTful
API.
* When the collection is created using the RESTful API and includes JSON
and array datatypes in dynamic fields, data can also be inserted using
the RESTful API.

Signed-off-by: zhuwenxing <[email protected]>
  • Loading branch information
zhuwenxing authored Mar 7, 2024
1 parent 005dbf2 commit 542b46f
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,9 @@ def test_collection_create_by_sdk_insert_vector_by_restful(self):
FieldSchema(name="int64", dtype=DataType.INT64, is_primary=True),
FieldSchema(name="float", dtype=DataType.FLOAT),
FieldSchema(name="varchar", dtype=DataType.VARCHAR, max_length=65535),
FieldSchema(name="json", dtype=DataType.JSON),
FieldSchema(name="int_array", dtype=DataType.ARRAY, element_type=DataType.INT64, max_capacity=1024),
FieldSchema(name="varchar_array", dtype=DataType.ARRAY, element_type=DataType.VARCHAR, max_capacity=1024, max_length=65535),
FieldSchema(name="float_vector", dtype=DataType.FLOAT_VECTOR, dim=128)
]
default_schema = CollectionSchema(fields=default_fields, description="test collection",
Expand All @@ -149,7 +152,14 @@ def test_collection_create_by_sdk_insert_vector_by_restful(self):
collection.load()
# insert data by restful
data = [
{"int64": i, "float": i, "varchar": str(i), "float_vector": [random.random() for _ in range(dim)], "age": i}
{"int64": i,
"float": i,
"varchar": str(i),
"json": {"name": "name", "age": i},
"int_array": [i for i in range(10)],
"varchar_array": [str(i) for i in range(10)],
"float_vector": [random.random() for _ in range(dim)],
"age": i}
for i in range(nb)
]
client = self.vector_client
Expand Down
2 changes: 2 additions & 0 deletions tests/restful_client/utils/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,8 @@ def get_random_json_data(uid=None):
uid = 0
data = {"uid": uid, "name": fake.name(), "address": fake.address(), "text": fake.text(), "email": fake.email(),
"phone_number": fake.phone_number(),
"array_int_dynamic": [random.randint(1, 100_000) for i in range(random.randint(1, 10))],
"array_varchar_dynamic": [fake.name() for i in range(random.randint(1, 10))],
"json": {
"name": fake.name(),
"address": fake.address()
Expand Down

0 comments on commit 542b46f

Please sign in to comment.