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:
Bingyi Sun 2025-03-11 14:00:05 +08:00 committed by GitHub
parent d9fe8f0dcf
commit a729bb84ba
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 27 additions and 1 deletions

View File

@ -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
}

View File

@ -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(),