| | |
| | | |
| | | //import io.milvus.param.ParamUtils; |
| | | |
| | | import org.apache.commons.lang3.StringUtils; |
| | | import io.milvus.param.ParamUtils; |
| | | import org.checkerframework.checker.nullness.qual.NonNull; |
| | | |
| | | import java.util.HashMap; |
| | | import java.util.Map; |
| | |
| | | private String description; |
| | | private DataType dataType; |
| | | private Map<String, String> typeParams; |
| | | // 2024-03-28 |
| | | private DataType elementType; |
| | | private boolean partitionKey; |
| | | |
| | | private FieldType(FieldType.Builder builder) { |
| | | if (builder == null) { |
| | |
| | | this.dataType = builder.dataType; |
| | | this.typeParams = builder.typeParams; |
| | | // this.autoID = builder.autoID; |
| | | this.elementType = builder.elementType; |
| | | this.partitionKey = builder.partitionKey; |
| | | } |
| | | } |
| | | |
| | |
| | | private DataType dataType; |
| | | private final Map<String, String> typeParams; |
| | | // private boolean autoID; |
| | | private DataType elementType; |
| | | private boolean partitionKey; |
| | | |
| | | private Builder() { |
| | | this.primaryKey = false; |
| | | this.description = ""; |
| | | this.typeParams = new HashMap(); |
| | | // this.autoID = false; |
| | | this.elementType = DataType.None; |
| | | this.partitionKey = false; |
| | | } |
| | | |
| | | public Builder withName(String name) { |
| | |
| | | throw new NullPointerException("dataType is marked non-null but is null"); |
| | | } else { |
| | | this.dataType = dataType; |
| | | return this; |
| | | } |
| | | } |
| | | |
| | | public Builder withElementType(@NonNull DataType elementType) { |
| | | if (elementType == null) { |
| | | throw new NullPointerException("elementType is marked non-null but is null"); |
| | | } else { |
| | | this.elementType = elementType; |
| | | return this; |
| | | } |
| | | } |
| | |
| | | // this.autoID = autoID; |
| | | // return this; |
| | | // } |
| | | public Builder withPartitionKey(boolean partitionKey) { |
| | | this.partitionKey = partitionKey; |
| | | return this; |
| | | } |
| | | |
| | | public FieldType build() throws ParamException { |
| | | // ParamUtils.CheckNullEmptyString(this.name, "Field name"); |
| | | if (this.name == null || StringUtils.isBlank(this.name)) { |
| | | throw new ParamException(name + " cannot be null or empty"); |
| | | } |
| | | ParamUtils.CheckNullEmptyString(this.name, "Field name"); |
| | | if (this.dataType != null && this.dataType != DataType.None) { |
| | | if (this.dataType == DataType.String) { |
| | | throw new ParamException("String type is not supported, use VarChar instead"); |
| | | throw new io.milvus.exception.ParamException("String type is not supported, use Varchar instead"); |
| | | } else { |
| | | int len; |
| | | if (this.dataType == DataType.FloatVector || this.dataType == DataType.BinaryVector) { |
| | | if (!this.typeParams.containsKey("dim")) { |
| | | throw new ParamException("Vector field dimension must be specified"); |
| | | throw new io.milvus.exception.ParamException("Vector field dimension must be specified"); |
| | | } |
| | | |
| | | try { |
| | | len = Integer.parseInt((String)this.typeParams.get("dim")); |
| | | if (len <= 0) { |
| | | throw new ParamException("Vector field dimension must be larger than zero"); |
| | | throw new io.milvus.exception.ParamException("Vector field dimension must be larger than zero"); |
| | | } |
| | | } catch (NumberFormatException var3) { |
| | | throw new ParamException("Vector field dimension must be an integer number"); |
| | | throw new io.milvus.exception.ParamException("Vector field dimension must be an integer number"); |
| | | } |
| | | } |
| | | |
| | | // if (this.dataType == io.milvus.grpc.DataType.VarChar) { |
| | | // if (!this.typeParams.containsKey("max_length")) { |
| | | // throw new ParamException("Varchar field max length must be specified"); |
| | | // } |
| | | // |
| | | // try { |
| | | // len = Integer.parseInt((String)this.typeParams.get("max_length")); |
| | | // if (len <= 0) { |
| | | // throw new ParamException("Varchar field max length must be larger than zero"); |
| | | // } |
| | | // } catch (NumberFormatException var2) { |
| | | // throw new ParamException("Varchar field max length must be an integer number"); |
| | | // } |
| | | // } |
| | | if (this.dataType == DataType.VarChar) { |
| | | if (!this.typeParams.containsKey("max_length")) { |
| | | throw new io.milvus.exception.ParamException("Varchar field max length must be specified"); |
| | | } |
| | | |
| | | try { |
| | | len = Integer.parseInt((String)this.typeParams.get("max_length")); |
| | | if (len <= 0) { |
| | | throw new io.milvus.exception.ParamException("Varchar field max length must be larger than zero"); |
| | | } |
| | | } catch (NumberFormatException var2) { |
| | | throw new io.milvus.exception.ParamException("Varchar field max length must be an integer number"); |
| | | } |
| | | } |
| | | |
| | | if (this.partitionKey) { |
| | | if (this.primaryKey) { |
| | | throw new io.milvus.exception.ParamException("Primary key field can not be partition key"); |
| | | } |
| | | |
| | | if (this.dataType != DataType.Long && this.dataType != DataType.VarChar) { |
| | | throw new io.milvus.exception.ParamException("Only Int64 and Varchar type field can be partition key"); |
| | | } |
| | | } |
| | | |
| | | if (this.dataType == DataType.Array) { |
| | | if (this.elementType == DataType.String) { |
| | | throw new io.milvus.exception.ParamException("String type is not supported, use Varchar instead"); |
| | | } |
| | | |
| | | if (this.elementType == DataType.None || this.elementType == DataType.Array || this.elementType == DataType.Json || this.elementType == DataType.String || this.elementType == DataType.FloatVector || this.elementType == DataType.Float16Vector || this.elementType == DataType.BinaryVector) { |
| | | throw new io.milvus.exception.ParamException("Unsupported element type"); |
| | | } |
| | | |
| | | if (!this.typeParams.containsKey("max_capacity")) { |
| | | throw new io.milvus.exception.ParamException("Array field max capacity must be specified"); |
| | | } |
| | | |
| | | if (this.elementType == DataType.VarChar && !this.typeParams.containsKey("max_length")) { |
| | | throw new io.milvus.exception.ParamException("Varchar array field max length must be specified"); |
| | | } |
| | | } |
| | | |
| | | return new FieldType(this); |
| | | } |
| | | } else { |
| | | throw new ParamException("Field data type is illegal"); |
| | | throw new io.milvus.exception.ParamException("Field data type is illegal"); |
| | | } |
| | | // if (this.name == null || StringUtils.isBlank(this.name)) { |
| | | // throw new ParamException(name + " cannot be null or empty"); |
| | | // } |
| | | // if (this.dataType != null && this.dataType != DataType.None) { |
| | | // if (this.dataType == DataType.String) { |
| | | // throw new ParamException("String type is not supported, use VarChar instead"); |
| | | // } else { |
| | | // int len; |
| | | // if (this.dataType == DataType.FloatVector || this.dataType == DataType.BinaryVector) { |
| | | // if (!this.typeParams.containsKey("dim")) { |
| | | // throw new ParamException("Vector field dimension must be specified"); |
| | | // } |
| | | // |
| | | // try { |
| | | // len = Integer.parseInt((String)this.typeParams.get("dim")); |
| | | // if (len <= 0) { |
| | | // throw new ParamException("Vector field dimension must be larger than zero"); |
| | | // } |
| | | // } catch (NumberFormatException var3) { |
| | | // throw new ParamException("Vector field dimension must be an integer number"); |
| | | // } |
| | | // } |
| | | // return new FieldType(this); |
| | | // } |
| | | // } else { |
| | | // throw new ParamException("Field data type is illegal"); |
| | | // } |
| | | } |
| | | |
| | | } |
| | | } |