mirror of
https://gitee.com/milvus-io/milvus.git
synced 2025-12-07 01:28:27 +08:00
fix: json path should be empty string if it's root (#40611)
issue: #35528 --------- Signed-off-by: sunby <sunbingyi1992@gmail.com>
This commit is contained in:
parent
a7cff3873b
commit
8f66a0432d
@ -239,6 +239,11 @@ func (s *Server) parseAndVerifyNestedPath(identifier string, schema *schemapb.Co
|
||||
s = strings.ReplaceAll(s, "/", "~1")
|
||||
return s
|
||||
})
|
||||
if len(nestedPath) == 0 {
|
||||
// if nested path is empty, it means the json path is the field name.
|
||||
// Dont return "/" here, it not a valid json path for simdjson.
|
||||
return "", nil
|
||||
}
|
||||
return "/" + strings.Join(nestedPath, "/"), nil
|
||||
}
|
||||
|
||||
|
||||
@ -46,6 +46,7 @@ import (
|
||||
"github.com/milvus-io/milvus/pkg/v2/proto/datapb"
|
||||
"github.com/milvus-io/milvus/pkg/v2/proto/indexpb"
|
||||
"github.com/milvus-io/milvus/pkg/v2/proto/workerpb"
|
||||
"github.com/milvus-io/milvus/pkg/v2/util/funcutil"
|
||||
"github.com/milvus-io/milvus/pkg/v2/util/merr"
|
||||
"github.com/milvus-io/milvus/pkg/v2/util/typeutil"
|
||||
)
|
||||
@ -167,6 +168,21 @@ func TestServer_CreateIndex(t *testing.T) {
|
||||
IsDynamic: false,
|
||||
IsPartitionKey: false,
|
||||
},
|
||||
{
|
||||
FieldID: fieldID + 1,
|
||||
Name: "json",
|
||||
IsPrimaryKey: false,
|
||||
Description: "",
|
||||
DataType: schemapb.DataType_JSON,
|
||||
TypeParams: nil,
|
||||
IndexParams: nil,
|
||||
AutoID: false,
|
||||
State: 0,
|
||||
ElementType: 0,
|
||||
DefaultValue: nil,
|
||||
IsDynamic: false,
|
||||
IsPartitionKey: false,
|
||||
},
|
||||
},
|
||||
EnableDynamicField: false,
|
||||
},
|
||||
@ -178,6 +194,41 @@ func TestServer_CreateIndex(t *testing.T) {
|
||||
assert.NoError(t, merr.CheckRPCCall(resp, err))
|
||||
})
|
||||
|
||||
t.Run("test json path", func(t *testing.T) {
|
||||
req := &indexpb.CreateIndexRequest{
|
||||
CollectionID: collID,
|
||||
FieldID: fieldID + 1,
|
||||
IndexName: "",
|
||||
TypeParams: typeParams,
|
||||
IndexParams: indexParams,
|
||||
Timestamp: 100,
|
||||
IsAutoIndex: false,
|
||||
UserIndexParams: indexParams,
|
||||
}
|
||||
req.IndexParams = []*commonpb.KeyValuePair{
|
||||
{
|
||||
Key: common.JSONPathKey,
|
||||
Value: "json",
|
||||
},
|
||||
{
|
||||
Key: common.JSONCastTypeKey,
|
||||
Value: "int64",
|
||||
},
|
||||
{
|
||||
Key: common.IndexTypeKey,
|
||||
Value: "INVERTED",
|
||||
},
|
||||
}
|
||||
resp, err := s.CreateIndex(ctx, req)
|
||||
assert.NoError(t, merr.CheckRPCCall(resp, err))
|
||||
|
||||
indexes := s.meta.indexMeta.GetFieldIndexes(req.GetCollectionID(), req.GetFieldID(), req.GetIndexName())
|
||||
assert.Equal(t, 1, len(indexes))
|
||||
jsonPath, err := funcutil.GetAttrByKeyFromRepeatedKV(common.JSONPathKey, indexes[0].IndexParams)
|
||||
assert.NoError(t, err)
|
||||
assert.Equal(t, "", jsonPath)
|
||||
})
|
||||
|
||||
t.Run("success with index exist", func(t *testing.T) {
|
||||
req.IndexName = ""
|
||||
resp, err := s.CreateIndex(ctx, req)
|
||||
|
||||
@ -1343,7 +1343,7 @@ class TestMilvusClientJsonPathIndexValid(TestMilvusClientV2Base):
|
||||
"index_type": supported_varchar_scalar_index,
|
||||
"field_name": json_field_name,
|
||||
"index_name": index_name})
|
||||
index_name = f"{json_field_name}/"
|
||||
index_name = f"{json_field_name}"
|
||||
self.describe_index(client, collection_name, index_name,
|
||||
check_task=CheckTasks.check_describe_index_property,
|
||||
check_items={
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user