|
@@ -41,6 +41,7 @@ public class FieldType {
|
|
private final DataType dataType;
|
|
private final DataType dataType;
|
|
private final Map<String,String> typeParams;
|
|
private final Map<String,String> typeParams;
|
|
private final boolean autoID;
|
|
private final boolean autoID;
|
|
|
|
+ private final boolean partitionKey;
|
|
|
|
|
|
private FieldType(@NonNull Builder builder){
|
|
private FieldType(@NonNull Builder builder){
|
|
this.name = builder.name;
|
|
this.name = builder.name;
|
|
@@ -49,6 +50,7 @@ public class FieldType {
|
|
this.dataType = builder.dataType;
|
|
this.dataType = builder.dataType;
|
|
this.typeParams = builder.typeParams;
|
|
this.typeParams = builder.typeParams;
|
|
this.autoID = builder.autoID;
|
|
this.autoID = builder.autoID;
|
|
|
|
+ this.partitionKey = builder.partitionKey;
|
|
}
|
|
}
|
|
|
|
|
|
public int getDimension() {
|
|
public int getDimension() {
|
|
@@ -81,6 +83,7 @@ public class FieldType {
|
|
private DataType dataType;
|
|
private DataType dataType;
|
|
private final Map<String,String> typeParams = new HashMap<>();
|
|
private final Map<String,String> typeParams = new HashMap<>();
|
|
private boolean autoID = false;
|
|
private boolean autoID = false;
|
|
|
|
+ private boolean partitionKey = false;
|
|
|
|
|
|
private Builder() {
|
|
private Builder() {
|
|
}
|
|
}
|
|
@@ -184,6 +187,20 @@ public class FieldType {
|
|
return this;
|
|
return this;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ /**
|
|
|
|
+ * Sets the field to be partition key.
|
|
|
|
+ * A partition key field's values are hashed and distributed to different logic partitions.
|
|
|
|
+ * Only int64 and varchar type field can be partition key.
|
|
|
|
+ * Primary key field cannot be partition key.
|
|
|
|
+ *
|
|
|
|
+ * @param partitionKey true is partition key, false is not
|
|
|
|
+ * @return <code>Builder</code>
|
|
|
|
+ */
|
|
|
|
+ public Builder withPartitionKey(boolean partitionKey) {
|
|
|
|
+ this.partitionKey = partitionKey;
|
|
|
|
+ return this;
|
|
|
|
+ }
|
|
|
|
+
|
|
/**
|
|
/**
|
|
* Verifies parameters and creates a new {@link FieldType} instance.
|
|
* Verifies parameters and creates a new {@link FieldType} instance.
|
|
*
|
|
*
|
|
@@ -197,7 +214,7 @@ public class FieldType {
|
|
}
|
|
}
|
|
|
|
|
|
if (dataType == DataType.String) {
|
|
if (dataType == DataType.String) {
|
|
- throw new ParamException("String type is not supported, use VarChar instead");
|
|
|
|
|
|
+ throw new ParamException("String type is not supported, use Varchar instead");
|
|
}
|
|
}
|
|
|
|
|
|
if (dataType == DataType.FloatVector || dataType == DataType.BinaryVector) {
|
|
if (dataType == DataType.FloatVector || dataType == DataType.BinaryVector) {
|
|
@@ -230,6 +247,17 @@ public class FieldType {
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ // verify partition key
|
|
|
|
+ if (partitionKey) {
|
|
|
|
+ if (primaryKey) {
|
|
|
|
+ throw new ParamException("Primary key field can not be partition key");
|
|
|
|
+ }
|
|
|
|
+ if (dataType != DataType.Int64 && dataType != DataType.VarChar) {
|
|
|
|
+ throw new ParamException("Only Int64 and Varchar type field can be partition key");
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+
|
|
return new FieldType(this);
|
|
return new FieldType(this);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
@@ -245,6 +273,7 @@ public class FieldType {
|
|
"name='" + name + '\'' +
|
|
"name='" + name + '\'' +
|
|
", type='" + dataType.name() + '\'' +
|
|
", type='" + dataType.name() + '\'' +
|
|
", primaryKey=" + primaryKey +
|
|
", primaryKey=" + primaryKey +
|
|
|
|
+ ", partitionKey=" + partitionKey +
|
|
", autoID=" + autoID +
|
|
", autoID=" + autoID +
|
|
", params=" + typeParams +
|
|
", params=" + typeParams +
|
|
'}';
|
|
'}';
|