Repository: milvus-io/milvus-sdk-go
Pull request #452 (2023-05-11 02:14:51)

Add AutoCompactionEnabled collection attribute
Related to https://github.com/milvus-io/milvus/issues/23993
/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/452#" 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/452?src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=milvus-io) Report
> Merging [#452](https://app.codecov.io/gh/milvus-io/milvus-sdk-go/pull/452?src=pr&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=milvus-io) (36686b4) into [master](https://app.codecov.io/gh/milvus-io/milvus-sdk-go/commit/73c54d3d2ef07a62741b428aca03de7b613b6793?el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=milvus-io) (73c54d3) will **increase** coverage by `0.03%`.
> The diff coverage is `100.00%`.

[![Impacted file tree graph](https://app.codecov.io/gh/milvus-io/milvus-sdk-go/pull/452/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/452?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     #452      +/-   ##
==========================================
+ Coverage   87.27%   87.30%   +0.03%     
==========================================
  Files          32       32              
  Lines        2931     2939       +8     
==========================================
+ Hits         2558     2566       +8     
  Misses        282      282              
  Partials       91       91              
```


| [Impacted Files](https://app.codecov.io/gh/milvus-io/milvus-sdk-go/pull/452?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=milvus-io) | Coverage Δ | |
|---|---|---|
| [entity/collection\_attr.go](https://app.codecov.io/gh/milvus-io/milvus-sdk-go/pull/452?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=milvus-io#diff-ZW50aXR5L2NvbGxlY3Rpb25fYXR0ci5nbw==) | `100.00% <100.00%> (ø)` | |


Patch:
diff --git a/entity/collection_attr.go b/entity/collection_attr.go
index 4c97b79..c96f297 100644
--- a/entity/collection_attr.go
+++ b/entity/collection_attr.go
@@ -20,6 +20,8 @@ import (
 const (
 	// cakTTL const for collection attribute key TTL in seconds.
 	cakTTL = `collection.ttl.seconds`
+	// cakAutoCompaction const for collection attribute key autom compaction enabled.
+	cakAutoCompaction = `collection.autocompaction.enabled`
 )
 
 // CollectionAttribute is the interface for altering collection attributes.
@@ -64,3 +66,26 @@ func CollectionTTL(ttl int64) ttlCollAttr {
 	ca.value = strconv.FormatInt(ttl, 10)
 	return ca
 }
+
+type autoCompactionCollAttr struct {
+	collAttrBase
+}
+
+// Valid implements CollectionAttribute.
+// checks collection auto compaction is valid bool.
+func (ca autoCompactionCollAttr) Valid() error {
+	_, err := strconv.ParseBool(ca.value)
+	if err != nil {
+		return errors.Wrap(err, "auto compaction setting is not valid boolean")
+	}
+
+	return nil
+}
+
+// CollectionAutoCompactionEnabled returns collection attribute to set collection auto compaction enabled.
+func CollectionAutoCompactionEnabled(enabled bool) autoCompactionCollAttr {
+	ca := autoCompactionCollAttr{}
+	ca.key = cakAutoCompaction
+	ca.value = strconv.FormatBool(enabled)
+	return ca
+}


Test patch:
diff --git a/entity/collection_attr_test.go b/entity/collection_attr_test.go
index fb570bd..b4f42e4 100644
--- a/entity/collection_attr_test.go
+++ b/entity/collection_attr_test.go
@@ -81,3 +81,52 @@ func (s *CollectionTTLSuite) TestCollectionTTL() {
 func TestCollectionTTL(t *testing.T) {
 	suite.Run(t, new(CollectionTTLSuite))
 }
+
+type CollectionAutoCompactionSuite struct {
+	suite.Suite
+}
+
+func (s *CollectionAutoCompactionSuite) TestValid() {
+	type testCase struct {
+		input     string
+		expectErr bool
+	}
+
+	cases := []testCase{
+		{input: "a", expectErr: true},
+		{input: "true", expectErr: false},
+		{input: "false", expectErr: false},
+		{input: "", expectErr: true},
+	}
+
+	for _, tc := range cases {
+		s.Run(tc.input, func() {
+			ca := autoCompactionCollAttr{}
+			ca.value = tc.input
+			err := ca.Valid()
+			if tc.expectErr {
+				s.Error(err)
+			} else {
+				s.NoError(err)
+			}
+		})
+	}
+}
+
+func (s *CollectionAutoCompactionSuite) TestCollectionAutoCompactionEnabled() {
+
+	cases := []bool{true, false}
+
+	for _, tc := range cases {
+		s.Run(fmt.Sprintf("%v", tc), func() {
+			ca := CollectionAutoCompactionEnabled(tc)
+			key, value := ca.KeyValue()
+			s.Equal(cakAutoCompaction, key)
+			s.Equal(strconv.FormatBool(tc), value)
+		})
+	}
+}
+
+func TestCollectionAutoCompaction(t *testing.T) {
+	suite.Run(t, new(CollectionAutoCompactionSuite))
+}
diff --git a/test/testcases/index_test.go b/test/testcases/index_test.go
index 01860c7..ee242be 100644
--- a/test/testcases/index_test.go
+++ b/test/testcases/index_test.go
@@ -218,7 +218,8 @@ func TestCreateIndexInvalidParams(t *testing.T) {
 	// TODO unclear error message
 	idxInvalidm, _ := entity.NewIndexIvfPQ(entity.L2, 128, 7, 8)
 	errm := mc.CreateIndex(ctx, collName, common.DefaultFloatVecFieldName, idxInvalidm, false)
-	common.CheckErr(t, errm, false, "invalid index params")
+	// TODO change error message check
+	common.CheckErr(t, errm, false, "dimension")
 
 	// invalid Hnsw M [4, 64], efConstruction [8, 512]
 	_, errHnswM := entity.NewIndexHNSW(entity.L2, 3, 96)
@@ -232,9 +233,11 @@ func TestCreateIndexInvalidParams(t *testing.T) {
 
 	// invalid flat metric type jaccard
 	// TODO unclear error message
-	idx, _ := entity.NewIndexFlat(entity.JACCARD)
-	errMetricType := mc.CreateIndex(ctx, collName, common.DefaultFloatVecFieldName, idx, false)
-	common.CheckErr(t, errMetricType, false, "invalid index params")
+	// See also https://github.com/milvus-io/milvus/issues/24080
+	/*
+		idx, _ := entity.NewIndexFlat(entity.JACCARD)
+		errMetricType := mc.CreateIndex(ctx, collName, common.DefaultFloatVecFieldName, idx, false)
+		common.CheckErr(t, errMetricType, false, "invalid index params")*/
 }
 
 // test create index with nil index
diff --git a/test/testcases/load_release_test.go b/test/testcases/load_release_test.go
index e5e2371..5865864 100644
--- a/test/testcases/load_release_test.go
+++ b/test/testcases/load_release_test.go
@@ -340,7 +340,8 @@ func TestReleasePartition(t *testing.T) {
 	// check release success
 	_, errQuery := mc.Query(ctx, collName, []string{}, entity.NewColumnInt64(common.DefaultIntFieldName, []int64{0}),
 		[]string{common.DefaultIntFieldName})
-	common.CheckErr(t, errQuery, false, "has not been loaded to memory or load failed")
+	// TODO change error msg or code
+	common.CheckErr(t, errQuery, false, "not loaded")
 }
 
 // test release not exist collection
@@ -394,7 +395,9 @@ func TestReleasePartitions(t *testing.T) {
 	// check release success
 	_, errQuery := mc.Query(ctx, collName, []string{partitionName}, entity.NewColumnInt64(common.DefaultIntFieldName, []int64{common.DefaultNb}),
 		[]string{common.DefaultIntFieldName})
-	common.CheckErr(t, errQuery, false, "has not been loaded to memory or load failed")
+
+	// TODO fix error msg or code
+	common.CheckErr(t, errQuery, false, "not loaded")
 }
 
 // test release partition not exist -> error or part exist -> success
diff --git a/test/testcases/search_test.go b/test/testcases/search_test.go
index 23c77ff..4e6dd96 100644
--- a/test/testcases/search_test.go
+++ b/test/testcases/search_test.go
@@ -742,9 +742,9 @@ func TestSearchInvalidExpr(t *testing.T) {
 		errMsg string
 	}
 	invalidExpr := []invalidExprStruct{
-		{expr: "id in [0]", errMsg: "fieldName(id) not found"},               // not exist field
+		//{expr: "id in [0]", errMsg: "fieldName(id) not found"},               // not exist field
 		{expr: "int64 in not [0]", errMsg: "cannot parse expression"},        // wrong term expr keyword
-		{expr: "int64 < floatVec", errMsg: "unsupported datatype"},           // unsupported compare field
+		{expr: "int64 < floatVec", errMsg: "unsupported data type"},          // unsupported compare field
 		{expr: "floatVec in [0]", errMsg: "cannot be casted to FloatVector"}, // value and field type mismatch
 	}