From b77abcbc0f17070a2a970e0c4aa5837e90f28e1f Mon Sep 17 00:00:00 2001 From: shikeying <pxzsky@163.com> Date: 星期三, 03 四月 2024 14:02:49 +0800 Subject: [PATCH] 提供ip转地区离线查询(未完成) --- walker-support-milvus/src/main/java/com/walker/support/milvus/FieldType.java | 124 +++++++++++++++++++++++++++++++++-------- 1 files changed, 100 insertions(+), 24 deletions(-) diff --git a/walker-support-milvus/src/main/java/com/walker/support/milvus/FieldType.java b/walker-support-milvus/src/main/java/com/walker/support/milvus/FieldType.java index 6c12313..794e996 100644 --- a/walker-support-milvus/src/main/java/com/walker/support/milvus/FieldType.java +++ b/walker-support-milvus/src/main/java/com/walker/support/milvus/FieldType.java @@ -2,7 +2,8 @@ //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; @@ -15,6 +16,9 @@ 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) { @@ -26,6 +30,8 @@ this.dataType = builder.dataType; this.typeParams = builder.typeParams; // this.autoID = builder.autoID; + this.elementType = builder.elementType; + this.partitionKey = builder.partitionKey; } } @@ -65,12 +71,16 @@ 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) { @@ -101,6 +111,15 @@ 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; } } @@ -148,52 +167,109 @@ // 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"); +// } } + } } -- Gitblit v1.9.1