mirror of
https://gitee.com/milvus-io/milvus.git
synced 2025-12-06 17:18:35 +08:00
enhance: add json path escape and replace $meta with dynamic field name (#40407)
issue: #35528 Signed-off-by: sunby <sunbingyi1992@gmail.com>
This commit is contained in:
parent
d9fe8f0dcf
commit
a729bb84ba
@ -233,6 +233,12 @@ func (s *Server) parseAndVerifyNestedPath(identifier string, schema *schemapb.Co
|
||||
}
|
||||
|
||||
nestedPath := identifierExpr.GetColumnExpr().GetInfo().GetNestedPath()
|
||||
// escape the nested path to avoid the path being interpreted as a JSON Pointer
|
||||
nestedPath = lo.Map(nestedPath, func(path string, _ int) string {
|
||||
s := strings.ReplaceAll(path, "~", "~0")
|
||||
s = strings.ReplaceAll(s, "/", "~1")
|
||||
return s
|
||||
})
|
||||
return "/" + strings.Join(nestedPath, "/"), nil
|
||||
}
|
||||
|
||||
|
||||
@ -19,6 +19,7 @@ package proxy
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
"github.com/cockroachdb/errors"
|
||||
"go.uber.org/zap"
|
||||
@ -806,10 +807,29 @@ func (dit *describeIndexTask) Execute(ctx context.Context) error {
|
||||
params = wrapUserIndexParams(metricType)
|
||||
}
|
||||
}
|
||||
fieldName := field.Name
|
||||
if field.IsDynamic {
|
||||
jsonPath, err := funcutil.GetAttrByKeyFromRepeatedKV(common.JSONPathKey, indexInfo.GetIndexParams())
|
||||
if err != nil {
|
||||
log.Ctx(ctx).Warn("failed to get json path for dynamic field", zap.Error(err))
|
||||
} else if jsonPath != "" {
|
||||
// Skip leading "/" and find next "/" to get first path segment
|
||||
trimmedPath := strings.TrimPrefix(jsonPath, "/")
|
||||
slashIndex := strings.Index(trimmedPath, "/")
|
||||
if slashIndex == -1 {
|
||||
fieldName = trimmedPath // Use full remaining path if no more "/"
|
||||
} else {
|
||||
fieldName = trimmedPath[:slashIndex]
|
||||
}
|
||||
// Unescape JSON Pointer path: ~1 -> / and ~0 -> ~
|
||||
fieldName = strings.ReplaceAll(fieldName, "~1", "/")
|
||||
fieldName = strings.ReplaceAll(fieldName, "~0", "~")
|
||||
}
|
||||
}
|
||||
desc := &milvuspb.IndexDescription{
|
||||
IndexName: indexInfo.GetIndexName(),
|
||||
IndexID: indexInfo.GetIndexID(),
|
||||
FieldName: field.Name,
|
||||
FieldName: fieldName,
|
||||
Params: params,
|
||||
IndexedRows: indexInfo.GetIndexedRows(),
|
||||
TotalRows: indexInfo.GetTotalRows(),
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user