mirror of
https://gitee.com/milvus-io/milvus.git
synced 2025-12-06 17:18:35 +08:00
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:
parent
cd0b36c39e
commit
2b5241fe5a
@ -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
|
||||
|
||||
@ -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)
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user