Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: read fields support for search (#381)
- Loading branch information
1 parent
72a86de
commit 45a7e5d
Showing
9 changed files
with
193 additions
and
20 deletions.
There are no files selected for viewing
Submodule proto
updated
from 02fad3 to 4669ee
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
package v1 | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
api "github.com/tigrisdata/tigris/api/server/v1" | ||
"github.com/tigrisdata/tigris/schema" | ||
) | ||
|
||
func TestSearchQueryRunner_getFieldSelection(t *testing.T) { | ||
t.Run("only include fields are provided", func(t *testing.T) { | ||
collFields := []*schema.Field{ | ||
{FieldName: "field_1"}, | ||
{FieldName: "field_2"}, | ||
} | ||
|
||
runner := &SearchQueryRunner{ | ||
req: &api.SearchRequest{ | ||
IncludeFields: []string{"field_1", "field_2"}, | ||
}, | ||
} | ||
|
||
factory, err := runner.getFieldSelection(collFields) | ||
|
||
assert.Nil(t, err) | ||
assert.NotNil(t, factory) | ||
assert.Empty(t, factory.Exclude) | ||
assert.Len(t, factory.Include, 2) | ||
assert.Contains(t, factory.Include, "field_1") | ||
assert.Contains(t, factory.Include, "field_2") | ||
}) | ||
|
||
t.Run("only exclude fields are provided", func(t *testing.T) { | ||
collFields := []*schema.Field{ | ||
{FieldName: "field_1"}, | ||
{FieldName: "field_2"}, | ||
} | ||
|
||
runner := &SearchQueryRunner{ | ||
req: &api.SearchRequest{ | ||
ExcludeFields: []string{"field_1", "field_2"}, | ||
}, | ||
} | ||
|
||
factory, err := runner.getFieldSelection(collFields) | ||
|
||
assert.Nil(t, err) | ||
assert.NotNil(t, factory) | ||
assert.Empty(t, factory.Include) | ||
assert.Len(t, factory.Exclude, 2) | ||
assert.Contains(t, factory.Exclude, "field_1") | ||
assert.Contains(t, factory.Exclude, "field_2") | ||
}) | ||
|
||
t.Run("no fields to include or exclude", func(t *testing.T) { | ||
collFields := []*schema.Field{ | ||
{FieldName: "field_1"}, | ||
{FieldName: "field_2"}, | ||
} | ||
runner := &SearchQueryRunner{req: &api.SearchRequest{}} | ||
|
||
factory, err := runner.getFieldSelection(collFields) | ||
|
||
assert.Nil(t, err) | ||
assert.Nil(t, factory) | ||
}) | ||
|
||
t.Run("no schema fields are defined", func(t *testing.T) { | ||
var collFields []*schema.Field | ||
runner := &SearchQueryRunner{req: &api.SearchRequest{}} | ||
|
||
factory, err := runner.getFieldSelection(collFields) | ||
|
||
assert.Nil(t, err) | ||
assert.Nil(t, factory) | ||
}) | ||
|
||
t.Run("selection fields are not in schema", func(t *testing.T) { | ||
collFields := []*schema.Field{ | ||
{FieldName: "field_1"}, | ||
{FieldName: "field_2"}, | ||
} | ||
|
||
runner := &SearchQueryRunner{ | ||
req: &api.SearchRequest{ | ||
ExcludeFields: []string{"field_2", "field_3"}, | ||
}, | ||
} | ||
|
||
factory, err := runner.getFieldSelection(collFields) | ||
|
||
assert.Nil(t, factory) | ||
assert.NotNil(t, err) | ||
assert.ErrorContains(t, err, "`field_3` is not a schema field") | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters