Repository: milvus-io/milvus-sdk-go
Pull request #460 (2023-05-22 11:26:20)

Add PartitionKey definition for schema
See also milvus-io/milvus#23553
/kind improvement


sre-ci-robot: [APPROVALNOTIFIER] This PR is **APPROVED**

This pull-request has been approved by: *<a href="https://github.com/milvus-io/milvus-sdk-go/pull/460#" title="Author self-approved">congqixia</a>*

The full list of commands accepted by this bot can be found [here](https://go.k8s.io/bot-commands?repo=milvus-io%2Fmilvus-sdk-go).

The pull request process is described [here](https://git.k8s.io/community/contributors/guide/owners.md#the-code-review-process)

<details >
Needs approval from an approver in each of these files:

- ~~[OWNERS](https://github.com/milvus-io/milvus-sdk-go/blob/master/OWNERS)~~ [congqixia]

Approvers can indicate their approval by writing `/approve` in a comment
Approvers can cancel approval by writing `/approve cancel` in a comment
</details>
<!-- META={"approvers":[]} -->
codecov[bot]: ## [Codecov](https://app.codecov.io/gh/milvus-io/milvus-sdk-go/pull/460?src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=milvus-io) Report
> Merging [#460](https://app.codecov.io/gh/milvus-io/milvus-sdk-go/pull/460?src=pr&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=milvus-io) (f41dc15) into [master](https://app.codecov.io/gh/milvus-io/milvus-sdk-go/commit/12b2160e8909686793ea053e49bbb12a32977bdd?el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=milvus-io) (12b2160) will **increase** coverage by `0.01%`.
> The diff coverage is `100.00%`.

[![Impacted file tree graph](https://app.codecov.io/gh/milvus-io/milvus-sdk-go/pull/460/graphs/tree.svg?width=650&height=150&src=pr&token=WJK43PV390&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=milvus-io)](https://app.codecov.io/gh/milvus-io/milvus-sdk-go/pull/460?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=milvus-io)

```diff
@@            Coverage Diff             @@
##           master     #460      +/-   ##
==========================================
+ Coverage   84.98%   85.00%   +0.01%     
==========================================
  Files          35       35              
  Lines        3276     3280       +4     
==========================================
+ Hits         2784     2788       +4     
  Misses        389      389              
  Partials      103      103              
```


| [Impacted Files](https://app.codecov.io/gh/milvus-io/milvus-sdk-go/pull/460?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=milvus-io) | Coverage Δ | |
|---|---|---|
| [entity/schema.go](https://app.codecov.io/gh/milvus-io/milvus-sdk-go/pull/460?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=milvus-io#diff-ZW50aXR5L3NjaGVtYS5nbw==) | `94.31% <100.00%> (+0.13%)` | :arrow_up: |

sre-ci-robot: [APPROVALNOTIFIER] This PR is **APPROVED**

This pull-request has been approved by: *<a href="https://github.com/milvus-io/milvus-sdk-go/pull/460#" title="Author self-approved">congqixia</a>*, *<a href="https://github.com/milvus-io/milvus-sdk-go/pull/460#pullrequestreview-1438137038" title="LGTM">yah01</a>*

The full list of commands accepted by this bot can be found [here](https://go.k8s.io/bot-commands?repo=milvus-io%2Fmilvus-sdk-go).

The pull request process is described [here](https://git.k8s.io/community/contributors/guide/owners.md#the-code-review-process)

<details >
Needs approval from an approver in each of these files:

- ~~[OWNERS](https://github.com/milvus-io/milvus-sdk-go/blob/master/OWNERS)~~ [congqixia]

Approvers can indicate their approval by writing `/approve` in a comment
Approvers can cancel approval by writing `/approve cancel` in a comment
</details>
<!-- META={"approvers":[]} -->

Patch:
diff --git a/entity/schema.go b/entity/schema.go
index 8b7810b..181d5a7 100644
--- a/entity/schema.go
+++ b/entity/schema.go
@@ -140,29 +140,31 @@ func (s *Schema) PKFieldName() string {
 
 // Field represent field schema in milvus
 type Field struct {
-	ID          int64  // field id, generated when collection is created, input value is ignored
-	Name        string // field name
-	PrimaryKey  bool   // is primary key
-	AutoID      bool   // is auto id
-	Description string
-	DataType    FieldType
-	TypeParams  map[string]string
-	IndexParams map[string]string
-	IsDynamic   bool
+	ID             int64  // field id, generated when collection is created, input value is ignored
+	Name           string // field name
+	PrimaryKey     bool   // is primary key
+	AutoID         bool   // is auto id
+	Description    string
+	DataType       FieldType
+	TypeParams     map[string]string
+	IndexParams    map[string]string
+	IsDynamic      bool
+	IsPartitionKey bool
 }
 
 // ProtoMessage generates corresponding FieldSchema
 func (f *Field) ProtoMessage() *schema.FieldSchema {
 	return &schema.FieldSchema{
-		FieldID:      f.ID,
-		Name:         f.Name,
-		Description:  f.Description,
-		IsPrimaryKey: f.PrimaryKey,
-		AutoID:       f.AutoID,
-		DataType:     schema.DataType(f.DataType),
-		TypeParams:   MapKvPairs(f.TypeParams),
-		IndexParams:  MapKvPairs(f.IndexParams),
-		IsDynamic:    f.IsDynamic,
+		FieldID:        f.ID,
+		Name:           f.Name,
+		Description:    f.Description,
+		IsPrimaryKey:   f.PrimaryKey,
+		AutoID:         f.AutoID,
+		DataType:       schema.DataType(f.DataType),
+		TypeParams:     MapKvPairs(f.TypeParams),
+		IndexParams:    MapKvPairs(f.IndexParams),
+		IsDynamic:      f.IsDynamic,
+		IsPartitionKey: f.IsPartitionKey,
 	}
 }
 
@@ -204,6 +206,11 @@ func (f *Field) WithIsDynamic(isDynamic bool) *Field {
 	return f
 }
 
+func (f *Field) WithIsPartitionKey(isPartitionKey bool) *Field {
+	f.IsPartitionKey = isPartitionKey
+	return f
+}
+
 func (f *Field) WithTypeParams(key string, value string) *Field {
 	if f.TypeParams == nil {
 		f.TypeParams = make(map[string]string)
@@ -239,6 +246,7 @@ func (f *Field) ReadProto(p *schema.FieldSchema) *Field {
 	f.TypeParams = KvPairsMap(p.GetTypeParams())
 	f.IndexParams = KvPairsMap(p.GetIndexParams())
 	f.IsDynamic = p.GetIsDynamic()
+	f.IsPartitionKey = p.GetIsPartitionKey()
 
 	return f
 }


Test patch:
diff --git a/entity/schema_test.go b/entity/schema_test.go
index b6f55fc..06f7bfb 100644
--- a/entity/schema_test.go
+++ b/entity/schema_test.go
@@ -24,6 +24,7 @@ func TestFieldSchema(t *testing.T) {
 	fields := []*Field{
 		NewField().WithName("int_field").WithDataType(FieldTypeInt64).WithIsAutoID(true).WithIsPrimaryKey(true).WithDescription("int_field desc"),
 		NewField().WithName("string_field").WithDataType(FieldTypeString).WithIsAutoID(false).WithIsPrimaryKey(true).WithIsDynamic(false).WithTypeParams("max_len", "32").WithDescription("string_field desc"),
+		NewField().WithName("partition_key").WithDataType(FieldTypeInt32).WithIsPartitionKey(true),
 	}
 
 	for _, field := range fields {
@@ -33,6 +34,8 @@ func TestFieldSchema(t *testing.T) {
 		assert.EqualValues(t, field.DataType, fieldSchema.GetDataType())
 		assert.Equal(t, field.AutoID, fieldSchema.GetAutoID())
 		assert.Equal(t, field.PrimaryKey, fieldSchema.GetIsPrimaryKey())
+		assert.Equal(t, field.IsPartitionKey, fieldSchema.GetIsPartitionKey())
+		assert.Equal(t, field.IsDynamic, fieldSchema.GetIsDynamic())
 		assert.Equal(t, field.Description, fieldSchema.GetDescription())
 		assert.Equal(t, field.TypeParams, KvPairsMap(fieldSchema.GetTypeParams()))
 		// marshal & unmarshal, still equals
@@ -44,6 +47,8 @@ func TestFieldSchema(t *testing.T) {
 		assert.Equal(t, field.AutoID, nf.AutoID)
 		assert.Equal(t, field.PrimaryKey, nf.PrimaryKey)
 		assert.Equal(t, field.Description, nf.Description)
+		assert.Equal(t, field.IsDynamic, nf.IsDynamic)
+		assert.Equal(t, field.IsPartitionKey, nf.IsPartitionKey)
 		assert.EqualValues(t, field.TypeParams, nf.TypeParams)
 	}