Skip to content

Commit

Permalink
Fix dynamic field $meta not in result set if using wildcard
Browse files Browse the repository at this point in the history
Signed-off-by: Congqi Xia <[email protected]>
  • Loading branch information
congqixia committed Nov 8, 2023
1 parent ed14896 commit 2b46ba5
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 12 deletions.
13 changes: 7 additions & 6 deletions client/data.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,8 @@ func (c *GrpcClient) Search(ctx context.Context, collName string, partitions []s
}

func (c *GrpcClient) parseSearchResult(sch *entity.Schema, outputFields []string, fieldDataList []*schemapb.FieldData, _, from, to int) ([]entity.Column, error) {
outputFields = expandWildcard(sch, outputFields)
var wildcard bool
outputFields, wildcard = expandWildcard(sch, outputFields)
// duplicated name will have only one column now
outputSet := make(map[string]struct{})
for _, output := range outputFields {
Expand All @@ -114,8 +115,8 @@ func (c *GrpcClient) parseSearchResult(sch *entity.Schema, outputFields []string
return nil, errors.New("dynamic field not json")
}

// return json column only explicitly specified in output fields
if _, ok := outputSet[fieldData.GetFieldName()]; !ok {
// return json column only explicitly specified in output fields and not in wildcard mode
if _, ok := outputSet[fieldData.GetFieldName()]; !ok && !wildcard {
continue
}
}
Expand All @@ -142,15 +143,15 @@ func (c *GrpcClient) parseSearchResult(sch *entity.Schema, outputFields []string
return columns, nil
}

func expandWildcard(schema *entity.Schema, outputFields []string) []string {
func expandWildcard(schema *entity.Schema, outputFields []string) ([]string, bool) {
wildcard := false
for _, outputField := range outputFields {
if outputField == "*" {
wildcard = true
}
}
if !wildcard {
return outputFields
return outputFields, false
}

set := make(map[string]struct{})
Expand All @@ -170,7 +171,7 @@ func expandWildcard(schema *entity.Schema, outputFields []string) []string {
result = append(result, output)
}
}
return result
return result, true
}

func PKs2Expr(backName string, ids entity.Column) string {
Expand Down
14 changes: 8 additions & 6 deletions client/data_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1195,21 +1195,23 @@ func (s *WildcardSuite) SetupTest() {

func (s *WildcardSuite) TestExpandWildcard() {
type testCase struct {
tag string
input []string
expect []string
tag string
input []string
expect []string
expectWildCard bool
}

cases := []testCase{
{tag: "normal", input: []string{"pk", "attr"}, expect: []string{"pk", "attr"}},
{tag: "with_wildcard", input: []string{"*"}, expect: []string{"pk", "attr", "$meta", "vector"}},
{tag: "wildcard_dynamic", input: []string{"*", "a"}, expect: []string{"pk", "attr", "$meta", "vector", "a"}},
{tag: "with_wildcard", input: []string{"*"}, expect: []string{"pk", "attr", "$meta", "vector"}, expectWildCard: true},
{tag: "wildcard_dynamic", input: []string{"*", "a"}, expect: []string{"pk", "attr", "$meta", "vector", "a"}, expectWildCard: true},
}

for _, tc := range cases {
s.Run(tc.tag, func() {
output := expandWildcard(s.schema, tc.input)
output, wildCard := expandWildcard(s.schema, tc.input)
s.ElementsMatch(tc.expect, output)
s.Equal(tc.expectWildCard, wildCard)
})
}
}
Expand Down

0 comments on commit 2b46ba5

Please sign in to comment.