Return all dynamic field when retrieve json key (#24205)

Signed-off-by: cai.zhang <cai.zhang@zilliz.com>
pull/24249/head
cai.zhang 2023-05-19 09:41:25 +08:00 committed by GitHub
parent 31b23bf460
commit 98d86e2391
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 36 additions and 7 deletions

View File

@ -432,6 +432,26 @@ func TestTranslateOutputFields(t *testing.T) {
outputFields, err = translateOutputFields([]string{"*", floatVectorFieldName}, schema, true)
assert.Equal(t, nil, err)
assert.ElementsMatch(t, []string{idFieldName, tsFieldName, floatVectorFieldName, binaryVectorFieldName}, outputFields)
t.Run("enable dynamic schema", func(t *testing.T) {
schema := &schemapb.CollectionSchema{
Name: "TestTranslateOutputFields",
Description: "TestTranslateOutputFields",
AutoID: false,
EnableDynamicField: true,
Fields: []*schemapb.FieldSchema{
{Name: idFieldName, DataType: schemapb.DataType_Int64, IsPrimaryKey: true},
{Name: tsFieldName, DataType: schemapb.DataType_Int64},
{Name: floatVectorFieldName, DataType: schemapb.DataType_FloatVector},
{Name: binaryVectorFieldName, DataType: schemapb.DataType_BinaryVector},
{Name: common.MetaFieldName, DataType: schemapb.DataType_JSON, IsDynamic: true},
},
}
outputFields, err = translateOutputFields([]string{"A", idFieldName}, schema, true)
assert.Equal(t, nil, err)
assert.ElementsMatch(t, []string{common.MetaFieldName, idFieldName}, outputFields)
})
}
func TestCreateCollectionTask(t *testing.T) {

View File

@ -800,7 +800,7 @@ func passwordVerify(ctx context.Context, username, rawPwd string, globalMetaCach
// output_fields=["*",C] ==> [A,B,C,D]
func translateOutputFields(outputFields []string, schema *schemapb.CollectionSchema, addPrimary bool) ([]string, error) {
var primaryFieldName string
allFielNameMap := make(map[string]bool)
allFieldNameMap := make(map[string]bool)
resultFieldNameMap := make(map[string]bool)
resultFieldNames := make([]string, 0)
@ -808,17 +808,26 @@ func translateOutputFields(outputFields []string, schema *schemapb.CollectionSch
if field.IsPrimaryKey {
primaryFieldName = field.Name
}
allFielNameMap[field.Name] = true
allFieldNameMap[field.Name] = true
}
for _, outputFieldName := range outputFields {
outputFieldName = strings.TrimSpace(outputFieldName)
if outputFieldName == "*" {
for fieldName := range allFielNameMap {
for fieldName := range allFieldNameMap {
resultFieldNameMap[fieldName] = true
}
} else {
resultFieldNameMap[outputFieldName] = true
if _, ok := allFieldNameMap[outputFieldName]; ok {
resultFieldNameMap[outputFieldName] = true
} else {
if schema.EnableDynamicField {
resultFieldNameMap[common.MetaFieldName] = true
} else {
return nil, fmt.Errorf("field %s not exist", outputFieldName)
}
}
}
}

View File

@ -134,7 +134,7 @@ func checkSearch(t *testing.T, c *MiniCluster, collectionName, fieldName string,
assert.Equal(t, schemapb.DataType_JSON, result.Results.FieldsData[0].GetType())
assert.Equal(t, 5, len(result.Results.FieldsData[0].GetScalars().GetJsonData().GetData()))
}
doSearch(c, collectionName, []string{fieldName}, expr, dim, t, checkFunc)
doSearch(c, collectionName, []string{"A"}, expr, dim, t, checkFunc)
log.Info("GT expression run successfully")
expr = `$meta["A"] < 10`
@ -144,7 +144,7 @@ func checkSearch(t *testing.T, c *MiniCluster, collectionName, fieldName string,
assert.Equal(t, schemapb.DataType_JSON, result.Results.FieldsData[0].GetType())
assert.Equal(t, 5, len(result.Results.FieldsData[0].GetScalars().GetJsonData().GetData()))
}
doSearch(c, collectionName, []string{fieldName}, expr, dim, t, checkFunc)
doSearch(c, collectionName, []string{"B"}, expr, dim, t, checkFunc)
log.Info("LT expression run successfully")
expr = `$meta["A"] <= 5`
@ -154,7 +154,7 @@ func checkSearch(t *testing.T, c *MiniCluster, collectionName, fieldName string,
assert.Equal(t, schemapb.DataType_JSON, result.Results.FieldsData[0].GetType())
assert.Equal(t, 3, len(result.Results.FieldsData[0].GetScalars().GetJsonData().GetData()))
}
doSearch(c, collectionName, []string{fieldName}, expr, dim, t, checkFunc)
doSearch(c, collectionName, []string{"C"}, expr, dim, t, checkFunc)
log.Info("LE expression run successfully")
expr = `A >= 95`