Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix count with facets filter #4751

Merged
merged 11 commits into from
Feb 25, 2020
134 changes: 134 additions & 0 deletions query/query_facets_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2198,3 +2198,137 @@ func TestFacetsWithExpand(t *testing.T) {
}
}`, js)
}

func TestCountFacetsFilteringUidListPredicate(t *testing.T) {
populateClusterWithFacets()

query := `{
q(func: uid(1, 33)) {
name
filtered_count: count(friend) @facets(eq(since, "2006-01-02T15:04:05"))
full_count: count(friend)
}
}`

js := processQueryNoErr(t, query)
require.JSONEq(t, `
{
"data": {
"q": [
{
"name": "Michonne",
"filtered_count": 2,
"full_count": 5
},
{
"name": "Michale",
"filtered_count": 1,
"full_count": 3
}
]
}
}`, js)
}

func TestCountFacetsFilteringUidPredicate(t *testing.T) {
populateClusterWithFacets()

query := `{
q(func: uid(1, 33)) {
name
filtered_count: count(boss) @facets(eq(company, "company1"))
full_count: count(boss)
}
}`

js := processQueryNoErr(t, query)
require.JSONEq(t, `
{
"data": {
"q": [
{
"name": "Michonne",
"filtered_count": 1,
"full_count": 1
},
{
"name": "Michale",
"filtered_count": 0,
"full_count": 0
}
]
}
}`, js)
}

func TestCountFacetsFilteringScalarPredicate(t *testing.T) {
populateClusterWithFacets()

query := `{
q(func: uid(1, 23)) {
name
french_origin_count: count(name) @facets(eq(origin, "french"))
french_spanish_count: count(name) @facets(eq(origin, "spanish"))
full_count: count(name)
}
}`

js := processQueryNoErr(t, query)
require.JSONEq(t, `
{
"data": {
"q": [
{
"name": "Michonne",
"french_origin_count": 1,
"french_spanish_count": 0,
"full_count": 1
},
{
"name": "Rick Grimes",
"french_origin_count": 1,
"french_spanish_count": 0,
"full_count": 1
}
]
}
}`, js)
}

func TestCountFacetsFilteringScalarListPredicate(t *testing.T) {
populateClusterWithFacets()

query := `{
q(func: uid(1, 12000)) {
name
alt_name
filtered_count: count(alt_name) @facets(eq(origin, "french"))
full_count: count(alt_name)
}
}`

js := processQueryNoErr(t, query)
require.JSONEq(t, `
{
"data": {
"q": [
{
"name": "Michonne",
"alt_name": [
"Michelle",
"Michelin"
],
"filtered_count": 1,
"full_count": 2
},
{
"alt_name": [
"Potter"
],
"filtered_count": 0,
"full_count": 1
}
]
}
}`, js)
}
Loading