2020package io .milvus .v2 .service .collection .request ;
2121
2222import io .milvus .common .clientenum .FunctionType ;
23+ import io .milvus .exception .ParamException ;
2324import io .milvus .v2 .common .ConsistencyLevel ;
2425import io .milvus .v2 .common .DataType ;
2526import io .milvus .v2 .common .IndexParam ;
@@ -447,17 +448,24 @@ public CreateCollectionReq build() {
447448
448449 public static class CollectionSchema {
449450 private List <CreateCollectionReq .FieldSchema > fieldSchemaList = new ArrayList <>();
451+ private List <CreateCollectionReq .StructFieldSchema > structFields = new ArrayList <>();
452+
450453 private boolean enableDynamicField = false ;
451454 private List <CreateCollectionReq .Function > functionList = new ArrayList <>();
452455
453456 private CollectionSchema (Builder builder ) {
454457 this .fieldSchemaList = builder .fieldSchemaList ;
458+ this .structFields = builder .structFields ;
455459 this .enableDynamicField = builder .enableDynamicField ;
456460 this .functionList = builder .functionList ;
457461 }
458462
459463 public CollectionSchema addField (AddFieldReq addFieldReq ) {
460- fieldSchemaList .add (SchemaUtils .convertFieldReqToFieldSchema (addFieldReq ));
464+ if (addFieldReq .getDataType () == DataType .Array && addFieldReq .getElementType () == DataType .Struct ) {
465+ structFields .add (SchemaUtils .convertFieldReqToStructFieldSchema (addFieldReq ));
466+ } else {
467+ fieldSchemaList .add (SchemaUtils .convertFieldReqToFieldSchema (addFieldReq ));
468+ }
461469 return this ;
462470 }
463471
@@ -483,6 +491,14 @@ public void setFieldSchemaList(List<CreateCollectionReq.FieldSchema> fieldSchema
483491 this .fieldSchemaList = fieldSchemaList ;
484492 }
485493
494+ public List <CreateCollectionReq .StructFieldSchema > getStructFields () {
495+ return structFields ;
496+ }
497+
498+ public void setStructFields (List <CreateCollectionReq .StructFieldSchema > structFields ) {
499+ this .structFields = structFields ;
500+ }
501+
486502 public boolean isEnableDynamicField () {
487503 return enableDynamicField ;
488504 }
@@ -507,6 +523,7 @@ public boolean equals(Object obj) {
507523 return new EqualsBuilder ()
508524 .append (enableDynamicField , that .enableDynamicField )
509525 .append (fieldSchemaList , that .fieldSchemaList )
526+ .append (structFields , that .structFields )
510527 .append (functionList , that .functionList )
511528 .isEquals ();
512529 }
@@ -515,6 +532,7 @@ public boolean equals(Object obj) {
515532 public int hashCode () {
516533 return new HashCodeBuilder (17 , 37 )
517534 .append (fieldSchemaList )
535+ .append (structFields )
518536 .append (enableDynamicField )
519537 .append (functionList )
520538 .toHashCode ();
@@ -524,6 +542,7 @@ public int hashCode() {
524542 public String toString () {
525543 return "CollectionSchema{" +
526544 "fieldSchemaList=" + fieldSchemaList +
545+ ", structFields=" + structFields +
527546 ", enableDynamicField=" + enableDynamicField +
528547 ", functionList=" + functionList +
529548 '}' ;
@@ -535,6 +554,7 @@ public static Builder builder() {
535554
536555 public static class Builder {
537556 private List <CreateCollectionReq .FieldSchema > fieldSchemaList = new ArrayList <>();
557+ private List <CreateCollectionReq .StructFieldSchema > structFields = new ArrayList <>();
538558 private boolean enableDynamicField = false ;
539559 private List <CreateCollectionReq .Function > functionList = new ArrayList <>();
540560
@@ -545,6 +565,11 @@ public Builder fieldSchemaList(List<CreateCollectionReq.FieldSchema> fieldSchema
545565 return this ;
546566 }
547567
568+ public Builder structFields (List <CreateCollectionReq .StructFieldSchema > structFields ) {
569+ this .structFields = structFields ;
570+ return this ;
571+ }
572+
548573 public Builder enableDynamicField (boolean enableDynamicField ) {
549574 this .enableDynamicField = enableDynamicField ;
550575 return this ;
@@ -947,7 +972,7 @@ public FieldSchema build() {
947972 }
948973
949974 public static class Function {
950- private String name ;
975+ private String name = "" ;
951976 private String description = "" ;
952977 private FunctionType functionType = FunctionType .UNKNOWN ;
953978 private List <String > inputFieldNames = new ArrayList <>();
@@ -1107,4 +1132,137 @@ public Function build() {
11071132 }
11081133 }
11091134 }
1135+
1136+ public static class StructFieldSchema {
1137+ private String name ;
1138+ private String description = "" ;
1139+ private List <CreateCollectionReq .FieldSchema > fields = new ArrayList <>();
1140+ private Integer maxCapacity ;
1141+
1142+ private StructFieldSchema (Builder builder ) {
1143+ this .name = builder .name ;
1144+ this .description = builder .description ;
1145+ this .fields = builder .fields ;
1146+ this .maxCapacity = builder .maxCapacity ;
1147+ }
1148+
1149+ public StructFieldSchema addField (AddFieldReq addFieldReq ) {
1150+ if (addFieldReq .getDataType () == DataType .Array || addFieldReq .getElementType () == DataType .Struct ) {
1151+ throw new ParamException ("Struct field schema does not support Array, ArrayOfVector or Struct" );
1152+ }
1153+ fields .add (SchemaUtils .convertFieldReqToFieldSchema (addFieldReq ));
1154+ return this ;
1155+ }
1156+
1157+ public DataType getDataType () {
1158+ return DataType .Array ;
1159+ }
1160+
1161+ public DataType getElementType () {
1162+ return DataType .Struct ;
1163+ }
1164+
1165+ // Getters and Setters
1166+ public String getName () {
1167+ return name ;
1168+ }
1169+
1170+ public void setName (String name ) {
1171+ this .name = name ;
1172+ }
1173+
1174+ public String getDescription () {
1175+ return description ;
1176+ }
1177+
1178+ public void setDescription (String description ) {
1179+ this .description = description ;
1180+ }
1181+
1182+ public List <CreateCollectionReq .FieldSchema > getFields () {
1183+ return fields ;
1184+ }
1185+
1186+ public void setFields (List <CreateCollectionReq .FieldSchema > fields ) {
1187+ this .fields = fields ;
1188+ }
1189+
1190+ public Integer getMaxCapacity () {
1191+ return maxCapacity ;
1192+ }
1193+
1194+ public void setMaxCapacity (Integer maxCapacity ) {
1195+ this .maxCapacity = maxCapacity ;
1196+ }
1197+
1198+ @ Override
1199+ public boolean equals (Object obj ) {
1200+ if (this == obj ) return true ;
1201+ if (obj == null || getClass () != obj .getClass ()) return false ;
1202+ StructFieldSchema that = (StructFieldSchema ) obj ;
1203+ return new EqualsBuilder ()
1204+ .append (name , that .name )
1205+ .append (description , that .description )
1206+ .append (fields , that .fields )
1207+ .append (maxCapacity , that .maxCapacity )
1208+ .isEquals ();
1209+ }
1210+
1211+ @ Override
1212+ public int hashCode () {
1213+ return new HashCodeBuilder (17 , 37 )
1214+ .append (name )
1215+ .append (description )
1216+ .append (fields )
1217+ .append (maxCapacity )
1218+ .toHashCode ();
1219+ }
1220+
1221+ @ Override
1222+ public String toString () {
1223+ return "StructFieldSchema{" +
1224+ "name='" + name + '\'' +
1225+ ", description='" + description + '\'' +
1226+ ", fields=" + fields +
1227+ ", maxCapacity=" + maxCapacity +
1228+ '}' ;
1229+ }
1230+
1231+ public static Builder builder () {
1232+ return new Builder ();
1233+ }
1234+
1235+ public static class Builder {
1236+ private String name ;
1237+ private String description = "" ;
1238+ private List <CreateCollectionReq .FieldSchema > fields = new ArrayList <>();
1239+ private Integer maxCapacity ;
1240+
1241+ private Builder () {}
1242+
1243+ public Builder name (String name ) {
1244+ this .name = name ;
1245+ return this ;
1246+ }
1247+
1248+ public Builder description (String description ) {
1249+ this .description = description ;
1250+ return this ;
1251+ }
1252+
1253+ public Builder fields (List <CreateCollectionReq .FieldSchema > fields ) {
1254+ this .fields = fields ;
1255+ return this ;
1256+ }
1257+
1258+ public Builder maxCapacity (Integer maxCapacity ) {
1259+ this .maxCapacity = maxCapacity ;
1260+ return this ;
1261+ }
1262+
1263+ public StructFieldSchema build () {
1264+ return new StructFieldSchema (this );
1265+ }
1266+ }
1267+ }
11101268}
0 commit comments