Repository: milvus-io/milvus-sdk-go
Pull request #696 (2024-04-03 07:53:25)

fix: Pass index type for Scalar indexes
Related to #694 #695

congqixia: /kind bug
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/696#" 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/696?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.92%. Comparing base [(`7d66951`)](https://app.codecov.io/gh/milvus-io/milvus-sdk-go/commit/7d669517c9784611ec4bf0ca30cdc76dfe2c9e7c?dropdown=coverage&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=milvus-io) to head [(`de44939`)](https://app.codecov.io/gh/milvus-io/milvus-sdk-go/pull/696?dropdown=coverage&src=pr&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=milvus-io).
> Report is 1 commits behind head on master.

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


[![Impacted file tree graph](https://app.codecov.io/gh/milvus-io/milvus-sdk-go/pull/696/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/696?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     #696      +/-   ##
==========================================
+ Coverage   71.90%   71.92%   +0.02%     
==========================================
  Files          51       51              
  Lines        4751     4752       +1     
==========================================
+ Hits         3416     3418       +2     
+ Misses       1211     1210       -1     
  Partials      124      124              
```


| [Files](https://app.codecov.io/gh/milvus-io/milvus-sdk-go/pull/696?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\_scalar.go](https://app.codecov.io/gh/milvus-io/milvus-sdk-go/pull/696?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==) | `100.00% <100.00%> (+14.28%)` | :arrow_up: |

</details>
ThreadDao: /lgtm

Patch:
diff --git a/entity/index_scalar.go b/entity/index_scalar.go
index a8c43a4..ffaa5de 100644
--- a/entity/index_scalar.go
+++ b/entity/index_scalar.go
@@ -7,7 +7,11 @@ type indexScalar struct {
 }
 
 func (i *indexScalar) Params() map[string]string {
-	return map[string]string{}
+	result := make(map[string]string)
+	if i.baseIndex.it != "" {
+		result[tIndexType] = string(i.baseIndex.it)
+	}
+	return result
 }
 
 func NewScalarIndex() Index {


Test patch:
diff --git a/entity/index_scalar_test.go b/entity/index_scalar_test.go
index 4107e8f..5442f0d 100644
--- a/entity/index_scalar_test.go
+++ b/entity/index_scalar_test.go
@@ -10,8 +10,16 @@ func TestScalarIndex(t *testing.T) {
 	oldScalarIdx := NewScalarIndex()
 
 	assert.EqualValues(t, "", oldScalarIdx.IndexType(), "use AUTO index when index type not provided")
+	_, has := oldScalarIdx.Params()[tIndexType]
+	assert.False(t, has)
 
 	idxWithType := NewScalarIndexWithType(Sorted)
 
 	assert.EqualValues(t, Sorted, idxWithType.IndexType())
+	assert.EqualValues(t, Sorted, idxWithType.Params()[tIndexType])
+
+	idxWithType = NewScalarIndexWithType(Trie)
+
+	assert.EqualValues(t, Trie, idxWithType.IndexType())
+	assert.EqualValues(t, Trie, idxWithType.Params()[tIndexType])
 }