milvus/internal/util/indexparamcheck/inverted_checker.go
Bingyi Sun ae8a9cebb8
fix: fix json index not-equal filter (#40648)
issue: #35528 
pr: https://github.com/milvus-io/milvus/pull/40647

---------

Signed-off-by: sunby <sunbingyi1992@gmail.com>
2025-03-14 21:36:10 +08:00

49 lines
1.5 KiB
Go

package indexparamcheck
import (
"fmt"
"github.com/samber/lo"
"github.com/milvus-io/milvus-proto/go-api/v2/schemapb"
"github.com/milvus-io/milvus/pkg/v2/common"
"github.com/milvus-io/milvus/pkg/v2/util/merr"
"github.com/milvus-io/milvus/pkg/v2/util/typeutil"
)
// INVERTEDChecker checks if a INVERTED index can be built.
type INVERTEDChecker struct {
scalarIndexChecker
}
var validJSONCastTypes = []string{"BOOL", "DOUBLE", "VARCHAR"}
func (c *INVERTEDChecker) CheckTrain(dataType schemapb.DataType, params map[string]string) error {
// check json index params
isJSONIndex := typeutil.IsJSONType(dataType)
if isJSONIndex {
castType, exist := params[common.JSONCastTypeKey]
if !exist {
return merr.WrapErrParameterMissing(common.JSONCastTypeKey, "json index must specify cast type")
}
if !lo.Contains(validJSONCastTypes, castType) {
return merr.WrapErrParameterInvalidMsg("json_cast_type %v is not supported", castType)
}
}
return c.scalarIndexChecker.CheckTrain(dataType, params)
}
func (c *INVERTEDChecker) CheckValidDataType(indexType IndexType, field *schemapb.FieldSchema) error {
dType := field.GetDataType()
if !typeutil.IsBoolType(dType) && !typeutil.IsArithmetic(dType) && !typeutil.IsStringType(dType) &&
!typeutil.IsArrayType(dType) && !typeutil.IsJSONType(dType) {
return fmt.Errorf("INVERTED are not supported on %s field", dType.String())
}
return nil
}
func newINVERTEDChecker() *INVERTEDChecker {
return &INVERTEDChecker{}
}