shikeying
2024-01-11 3b67e947e36133e2a40eb2737b15ea375e157ea0
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
package com.walker.support.milvus;
 
//import io.milvus.param.ParamUtils;
 
import org.apache.commons.lang3.StringUtils;
 
import java.util.HashMap;
import java.util.Map;
 
public class FieldType {
//    private FieldType fieldType = null;
 
    private String name;
    private boolean primaryKey;
    private String description;
    private DataType dataType;
    private Map<String, String> typeParams;
 
    private FieldType(FieldType.Builder builder) {
        if (builder == null) {
            throw new NullPointerException("builder is marked non-null but is null");
        } else {
            this.name = builder.name;
            this.primaryKey = builder.primaryKey;
            this.description = builder.description;
            this.dataType = builder.dataType;
            this.typeParams = builder.typeParams;
//            this.autoID = builder.autoID;
        }
    }
 
    public static FieldType.Builder newBuilder() {
        return new FieldType.Builder();
    }
 
    @Override
    public String toString(){
        return new StringBuilder("[name=").append(this.name)
                .append(", isPrimary=").append(this.primaryKey)
                .append(", dataType=").append(this.dataType)
                .append(", summary=").append(this.description)
                .append("]").toString();
    }
 
    public String getName(){
        return this.name;
    }
    public boolean isPrimaryKey(){
        return this.primaryKey;
    }
    public String getDescription(){
        return this.description;
    }
    public DataType getDataType(){
        return this.dataType;
    }
    public Map<String, String> getTypeParams(){
        return this.typeParams;
    }
 
    public static final class Builder {
        private String name;
        private boolean primaryKey;
        private String description;
        private DataType dataType;
        private final Map<String, String> typeParams;
//        private boolean autoID;
 
        private Builder() {
            this.primaryKey = false;
            this.description = "";
            this.typeParams = new HashMap();
//            this.autoID = false;
        }
 
        public Builder withName(String name) {
            if (name == null) {
                throw new NullPointerException("name is marked non-null but is null");
            } else {
                this.name = name;
                return this;
            }
        }
 
        public Builder withPrimaryKey(boolean primaryKey) {
            this.primaryKey = primaryKey;
            return this;
        }
 
        public Builder withDescription(String description) {
            if (description == null) {
                throw new NullPointerException("description is marked non-null but is null");
            } else {
                this.description = description;
                return this;
            }
        }
 
        public Builder withDataType(DataType dataType) {
            if (dataType == null) {
                throw new NullPointerException("dataType is marked non-null but is null");
            } else {
                this.dataType = dataType;
                return this;
            }
        }
 
        public Builder addTypeParam(String key, String value) {
            if (key == null) {
                throw new NullPointerException("key is marked non-null but is null");
            } else if (value == null) {
                throw new NullPointerException("value is marked non-null but is null");
            } else {
                this.typeParams.put(key, value);
                return this;
            }
        }
 
        public Builder withTypeParams(Map<String, String> typeParams) {
            if (typeParams == null) {
                throw new NullPointerException("typeParams is marked non-null but is null");
            } else {
                Map var10001 = this.typeParams;
                typeParams.forEach(var10001::put);
                return this;
            }
        }
 
        public Builder withDimension(Integer dimension) {
            if (dimension == null) {
                throw new NullPointerException("dimension is marked non-null but is null");
            } else {
                this.typeParams.put("dim", dimension.toString());
                return this;
            }
        }
 
        public Builder withMaxLength(Integer maxLength) {
            if (maxLength == null) {
                throw new NullPointerException("maxLength is marked non-null but is null");
            } else {
                this.typeParams.put("max_length", maxLength.toString());
                return this;
            }
        }
 
//        public Builder withAutoID(boolean autoID) {
//            this.autoID = autoID;
//            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");
            }
            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");
                        }
                    }
 
//                    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");
//                        }
//                    }
 
                    return new FieldType(this);
                }
            } else {
                throw new ParamException("Field data type is illegal");
            }
        }
    }
}