Repository: milvus-io/milvus-sdk-go
Pull request #691 (2024-04-02 03:44:07)

fix: Allow specify scalar index type
Related to #671

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/691#" 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":[]} -->
congqixia: /kind bug
codecov[bot]: ## [Codecov](https://app.codecov.io/gh/milvus-io/milvus-sdk-go/pull/691?dropdown=coverage&src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=milvus-io) Report
All modified and coverable lines are covered by tests :white_check_mark:
> Project coverage is 71.91%. Comparing base [(`3eabbb5`)](https://app.codecov.io/gh/milvus-io/milvus-sdk-go/commit/3eabbb5a2b4353a64fa03e1bec7037325e7dc97d?dropdown=coverage&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=milvus-io) to head [(`c1579b9`)](https://app.codecov.io/gh/milvus-io/milvus-sdk-go/pull/691?dropdown=coverage&src=pr&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=milvus-io).

<details><summary>Additional details and impacted files</summary>


[![Impacted file tree graph](https://app.codecov.io/gh/milvus-io/milvus-sdk-go/pull/691/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/691?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     #691      +/-   ##
==========================================
+ Coverage   71.81%   71.91%   +0.09%     
==========================================
  Files          51       51              
  Lines        4748     4750       +2     
==========================================
+ Hits         3410     3416       +6     
+ Misses       1214     1210       -4     
  Partials      124      124              
```


| [Files](https://app.codecov.io/gh/milvus-io/milvus-sdk-go/pull/691?dropdown=coverage&src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=milvus-io) | Coverage Δ | |
|---|---|---|
| [entity/index.go](https://app.codecov.io/gh/milvus-io/milvus-sdk-go/pull/691?src=pr&el=tree&filepath=entity%2Findex.go&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=milvus-io#diff-ZW50aXR5L2luZGV4Lmdv) | `100.00% <ø> (ø)` | |
| [entity/index\_scalar.go](https://app.codecov.io/gh/milvus-io/milvus-sdk-go/pull/691?src=pr&el=tree&filepath=entity%2Findex_scalar.go&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=milvus-io#diff-ZW50aXR5L2luZGV4X3NjYWxhci5nbw==) | `85.71% <100.00%> (+85.71%)` | :arrow_up: |

</details>
weiliu1031: /lgtm

Patch:
diff --git a/entity/index.go b/entity/index.go
index dd8db14..fbecda0 100644
--- a/entity/index.go
+++ b/entity/index.go
@@ -44,7 +44,12 @@ const (
 	GPUCagra      IndexType = "GPU_CAGRA"
 	GPUBruteForce IndexType = "GPU_BRUTE_FORCE"
 
-	Scalar IndexType = "SCALAR"
+	// DEPRECATED
+	Scalar IndexType = ""
+
+	Trie     IndexType = "Trie"
+	Sorted   IndexType = "STL_SORT"
+	Inverted IndexType = "INVERTED"
 )
 
 // Metric Constants
diff --git a/entity/index_scalar.go b/entity/index_scalar.go
index 44d6fb6..a8c43a4 100644
--- a/entity/index_scalar.go
+++ b/entity/index_scalar.go
@@ -11,9 +11,15 @@ func (i *indexScalar) Params() map[string]string {
 }
 
 func NewScalarIndex() Index {
+	return &indexScalar{
+		baseIndex: baseIndex{},
+	}
+}
+
+func NewScalarIndexWithType(indexType IndexType) Index {
 	return &indexScalar{
 		baseIndex: baseIndex{
-			it: Scalar,
+			it: indexType,
 		},
 	}
 }


Test patch:
diff --git a/entity/index_scalar_test.go b/entity/index_scalar_test.go
new file mode 100644
index 0000000..4107e8f
--- /dev/null
+++ b/entity/index_scalar_test.go
@@ -0,0 +1,17 @@
+package entity
+
+import (
+	"testing"
+
+	"github.com/stretchr/testify/assert"
+)
+
+func TestScalarIndex(t *testing.T) {
+	oldScalarIdx := NewScalarIndex()
+
+	assert.EqualValues(t, "", oldScalarIdx.IndexType(), "use AUTO index when index type not provided")
+
+	idxWithType := NewScalarIndexWithType(Sorted)
+
+	assert.EqualValues(t, Sorted, idxWithType.IndexType())
+}