Skip to content

Commit aaa2e48

Browse files
authored
Merge pull request #70 from zilliztech/support-array
Support array
2 parents 02ccd2f + 54048ca commit aaa2e48

5 files changed

Lines changed: 37 additions & 11 deletions

File tree

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ Python >= 3.8.5
3131
#### Install from PyPI (Recommended)
3232

3333
Run `pip install pymilvus==2.3.4`
34-
Run `pip install milvus-cli==0.4.1`
34+
Run `pip install milvus-cli==0.4.2`
3535

3636
#### Install from a tarball
3737

milvus_cli/Collection.py

Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,30 +36,44 @@ def create_collection(
3636
):
3737
fieldList = []
3838
for field in fields:
39-
[fieldName, fieldType, fieldData] = field.split(":")
39+
[fieldName, fieldType, *restData] = field.split(":")
4040
upperFieldType = fieldType.upper()
4141
if upperFieldType in ["BINARY_VECTOR", "FLOAT_VECTOR"]:
4242
fieldList.append(
4343
FieldSchema(
4444
name=fieldName,
4545
dtype=DataType[upperFieldType],
46-
dim=int(fieldData),
46+
dim=int(restData[0]),
4747
)
4848
)
4949
elif upperFieldType == "VARCHAR":
5050
fieldList.append(
5151
FieldSchema(
5252
name=fieldName,
5353
dtype=DataType[upperFieldType],
54-
max_length=fieldData,
54+
max_length=restData[0],
5555
)
5656
)
57+
elif upperFieldType == "ARRAY":
58+
upperElementType = restData[1].upper()
59+
max_capacity = restData[0]
60+
maxLength = restData[2] if len(restData) == 3 else None
61+
fieldList.append(
62+
FieldSchema(
63+
name=fieldName,
64+
dtype=DataType[upperFieldType],
65+
element_type=DataType[upperElementType],
66+
max_capacity=max_capacity,
67+
max_length=maxLength,
68+
)
69+
)
70+
5771
else:
5872
fieldList.append(
5973
FieldSchema(
6074
name=fieldName,
6175
dtype=DataType[upperFieldType],
62-
description=fieldData,
76+
description=restData[0],
6377
)
6478
)
6579
schema = CollectionSchema(
@@ -147,11 +161,21 @@ def get_collection_details(self, collectionName="", collection=None):
147161
fieldSchemaDetails = ""
148162
for fieldSchema in schema.fields:
149163
_name = f"{'*' if fieldSchema.is_primary else ''}{fieldSchema.name}"
164+
150165
_type = DataTypeByNum[fieldSchema.dtype]
151166
_desc = fieldSchema.description
152167
_params = fieldSchema.params
153168
_dim = _params.get("dim")
154169
_params_desc = f"dim: {_dim}" if _dim else ""
170+
if fieldSchema.dtype == DataType.ARRAY:
171+
_max_length = _params.get("max_length")
172+
_element_type = fieldSchema.element_type
173+
_max_capacity = _params.get("max_capacity")
174+
_params_desc = (
175+
f"max_capacity: {_max_capacity},element_type: {_element_type}"
176+
)
177+
_params_desc += f",max_length: {_max_length}" if _max_length else ""
178+
155179
fieldSchemaDetails += f"\n - {_name} {_type} {_params_desc} {_desc}"
156180
schemaDetails = """Description: {}\n\nAuto ID: {}\n\nFields(* is the primary field):{}""".format(
157181
schema.description, schema.auto_id, fieldSchemaDetails

milvus_cli/Types.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ def __str__(self):
3333
"BINARY_VECTOR",
3434
"FLOAT_VECTOR",
3535
"JSON",
36+
"ARRAY",
3637
]
3738

3839
IndexTypes = [
@@ -144,6 +145,7 @@ def __str__(self):
144145
11: "DOUBLE",
145146
20: "STRING",
146147
21: "VARCHAR",
148+
22: "ARRAY",
147149
23: "JSON",
148150
100: "BINARY_VECTOR",
149151
101: "FLOAT_VECTOR",

milvus_cli/Validation.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,11 @@ def validateCollectionParameter(collectionName, primaryField, fields):
2727
fieldNames = []
2828
for field in fields:
2929
fieldList = field.split(":")
30-
if not (len(fieldList) == 3):
30+
if len(fieldList) < 3:
3131
raise ParameterException(
32-
'Field should contain three parameters concatenated by ":".'
32+
'Field should contain three parameters(array field need more) concatenated by ":".'
3333
)
34-
[fieldName, fieldType, fieldData] = fieldList
34+
[fieldName, fieldType, *restData] = fieldList
3535
upperFieldType = fieldType.upper()
3636
fieldNames.append(fieldName)
3737
if upperFieldType not in FiledDataTypes:
@@ -42,7 +42,7 @@ def validateCollectionParameter(collectionName, primaryField, fields):
4242
)
4343
if upperFieldType in ["BINARY_VECTOR", "FLOAT_VECTOR"]:
4444
try:
45-
int(fieldData)
45+
int(restData[0])
4646
except ValueError as e:
4747
raise ParameterException("""Vector's dim should be int.""")
4848
# Dedup field name.

milvus_cli/scripts/collection_cli.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@
5656
"-f",
5757
"--schema-field",
5858
"fields",
59-
help='[Multiple] - FieldSchema. Usage is "<Name>:<DataType>:<Dim(if vector) or Description>"',
59+
help='[Multiple] - FieldSchema. Usage is "<Name>:<DataType>:<Dim(if vector) or Description>", Array Type is <Name>:<DataType>:<MaxCapacity>:<ElementDataType>(:<MaxLength>if Varchar)',
6060
default=None,
6161
multiple=True,
6262
)
@@ -85,7 +85,7 @@ def create_collection(
8585
8686
Example:
8787
88-
create collection -c car -f id:INT64:primary_field -f vector:FLOAT_VECTOR:128 -f color:INT64:color -f brand:INT64:brand -p id -A -d 'car_collection'
88+
create collection -c car -f id:INT64:primary_field -f vector:FLOAT_VECTOR:128 -f color:INT64:color -f brand:ARRAY:64:VARCHAR:128 -p id -A -d 'car_collection'
8989
"""
9090
try:
9191
validateCollectionParameter(

0 commit comments

Comments
 (0)