fix: allow "[" and "]" in index name (#45193)

issue: https://github.com/milvus-io/milvus/issues/42148

---------

Signed-off-by: SpadeA <tangchenjie1210@gmail.com>
Signed-off-by: SpadeA-Tang <tangchenjie1210@gmail.com>
This commit is contained in:
Spade A 2025-11-04 11:59:34 +08:00 committed by GitHub
parent cd0b36c39e
commit 2b5241fe5a
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 7 additions and 3 deletions

View File

@ -55,7 +55,7 @@ func (s *Server) serverID() int64 {
return 0
}
func (s *Server) getFieldNameByID(schema *schemapb.CollectionSchema, fieldID int64) (string, error) {
func (s *Server) defaultIndexNameByID(schema *schemapb.CollectionSchema, fieldID int64) (string, error) {
for _, field := range schema.GetFields() {
if field.FieldID == fieldID {
return field.Name, nil
@ -184,7 +184,7 @@ func (s *Server) CreateIndex(ctx context.Context, req *indexpb.CreateIndexReques
if req.GetIndexName() == "" {
indexes := s.meta.indexMeta.GetFieldIndexes(req.GetCollectionID(), req.GetFieldID(), req.GetIndexName())
fieldName, err := s.getFieldNameByID(schema, req.GetFieldID())
fieldName, err := s.defaultIndexNameByID(schema, req.GetFieldID())
if err != nil {
log.Warn("get field name from schema failed", zap.Int64("fieldID", req.GetFieldID()))
return merr.Status(err), nil

View File

@ -1620,6 +1620,10 @@ func translateOutputFields(outputFields []string, schema *schemaInfo, removePkFi
return resultFieldNames, userOutputFields, userDynamicFields, userRequestedPkFieldExplicitly, nil
}
func validCharInIndexName(c byte) bool {
return c == '_' || c == '[' || c == ']' || isAlpha(c) || isNumber(c)
}
func validateIndexName(indexName string) error {
indexName = strings.TrimSpace(indexName)
@ -1641,7 +1645,7 @@ func validateIndexName(indexName string) error {
indexNameSize := len(indexName)
for i := 1; i < indexNameSize; i++ {
c := indexName[i]
if c != '_' && !isAlpha(c) && !isNumber(c) {
if !validCharInIndexName(c) {
msg := invalidMsg + "Index name can only contain numbers, letters, and underscores."
return errors.New(msg)
}