From 99f8c64c313f1b1e9cfe857a819fd6462d91ba7a Mon Sep 17 00:00:00 2001 From: congqixia Date: Tue, 20 Aug 2024 19:44:55 +0800 Subject: [PATCH] enhance: [GoSDK] support Bitmap Index (#35585) See also #32900 Signed-off-by: Congqi Xia --- client/index/common.go | 1 + client/index/scalar.go | 6 ++++ client/index/scalar_test.go | 63 +++++++++++++++++++++++++++++++++++++ 3 files changed, 70 insertions(+) create mode 100644 client/index/scalar_test.go diff --git a/client/index/common.go b/client/index/common.go index 162e475ad3..214abdb8ce 100644 --- a/client/index/common.go +++ b/client/index/common.go @@ -64,4 +64,5 @@ const ( Trie IndexType = "Trie" Sorted IndexType = "STL_SORT" Inverted IndexType = "INVERTED" + BITMAP IndexType = "BITMAP" ) diff --git a/client/index/scalar.go b/client/index/scalar.go index 88433e1eee..6b9f14396a 100644 --- a/client/index/scalar.go +++ b/client/index/scalar.go @@ -54,3 +54,9 @@ func NewSortedIndex() Index { indexType: Sorted, } } + +func NewBitmapIndex() Index { + return scalarIndex{ + indexType: BITMAP, + } +} diff --git a/client/index/scalar_test.go b/client/index/scalar_test.go new file mode 100644 index 0000000000..2548e13a92 --- /dev/null +++ b/client/index/scalar_test.go @@ -0,0 +1,63 @@ +// Licensed to the LF AI & Data foundation under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package index + +import ( + "fmt" + "testing" + + "github.com/stretchr/testify/suite" +) + +type ScalarIndexSuite struct { + suite.Suite +} + +func (s *ScalarIndexSuite) TestConstructors() { + type testCase struct { + tag string + input Index + expectIndexType IndexType + } + + testcases := []testCase{ + {tag: "Trie", input: NewTrieIndex(), expectIndexType: Trie}, + {tag: "Sorted", input: NewSortedIndex(), expectIndexType: Sorted}, + {tag: "Inverted", input: NewInvertedIndex(), expectIndexType: Inverted}, + {tag: "Bitmap", input: NewBitmapIndex(), expectIndexType: BITMAP}, + } + + for _, tc := range testcases { + s.Run(fmt.Sprintf("%s_indextype", tc.tag), func() { + s.Equal(tc.expectIndexType, tc.input.IndexType()) + }) + } + + for _, tc := range testcases { + s.Run(fmt.Sprintf("%s_params", tc.tag), func() { + params := tc.input.Params() + itv, ok := params[IndexTypeKey] + if s.True(ok) { + s.EqualValues(tc.expectIndexType, itv) + } + }) + } +} + +func TestScalarIndexes(t *testing.T) { + suite.Run(t, new(ScalarIndexSuite)) +}