-
Notifications
You must be signed in to change notification settings - Fork 56
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: Enable filtering doc by fields of JSON and Blob types (#2841)
## Relevant issue(s) Resolves #2840 ## Description Fixes the issue not being able to filter by JSON and Blob fields
- Loading branch information
1 parent
fe9fae6
commit f6b6485
Showing
8 changed files
with
502 additions
and
2 deletions.
There are no files selected for viewing
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
54 changes: 54 additions & 0 deletions
54
tests/integration/query/simple/with_filter/with_eq_blob_test.go
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,54 @@ | ||
// Copyright 2024 Democratized Data Foundation | ||
// | ||
// Use of this software is governed by the Business Source License | ||
// included in the file licenses/BSL.txt. | ||
// | ||
// As of the Change Date specified in that file, in accordance with | ||
// the Business Source License, use of this software will be governed | ||
// by the Apache License, Version 2.0, included in the file | ||
// licenses/APL.txt. | ||
|
||
package simple | ||
|
||
import ( | ||
"testing" | ||
|
||
testUtils "github.com/sourcenetwork/defradb/tests/integration" | ||
) | ||
|
||
func TestQuerySimple_WithEqOpOnBlobField_ShouldFilter(t *testing.T) { | ||
test := testUtils.TestCase{ | ||
Actions: []any{ | ||
testUtils.SchemaUpdate{ | ||
Schema: ` | ||
type Users { | ||
name: String | ||
data: Blob | ||
} | ||
`, | ||
}, | ||
testUtils.CreateDoc{ | ||
Doc: `{ | ||
"name": "John", | ||
"data": "00FF99AA" | ||
}`, | ||
}, | ||
testUtils.CreateDoc{ | ||
Doc: `{ | ||
"name": "Andy", | ||
"data": "FA02CC45" | ||
}`, | ||
}, | ||
testUtils.Request{ | ||
Request: `query { | ||
Users(filter: {data: {_eq: "00FF99AA"}}) { | ||
name | ||
} | ||
}`, | ||
Results: []map[string]any{{"name": "John"}}, | ||
}, | ||
}, | ||
} | ||
|
||
testUtils.ExecuteTestCase(t, test) | ||
} |
55 changes: 55 additions & 0 deletions
55
tests/integration/query/simple/with_filter/with_eq_json_test.go
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,55 @@ | ||
// Copyright 2024 Democratized Data Foundation | ||
// | ||
// Use of this software is governed by the Business Source License | ||
// included in the file licenses/BSL.txt. | ||
// | ||
// As of the Change Date specified in that file, in accordance with | ||
// the Business Source License, use of this software will be governed | ||
// by the Apache License, Version 2.0, included in the file | ||
// licenses/APL.txt. | ||
|
||
package simple | ||
|
||
import ( | ||
"testing" | ||
|
||
testUtils "github.com/sourcenetwork/defradb/tests/integration" | ||
) | ||
|
||
func TestQuerySimple_WithEqOpOnJSONField_ShouldFilter(t *testing.T) { | ||
test := testUtils.TestCase{ | ||
Actions: []any{ | ||
testUtils.SchemaUpdate{ | ||
Schema: ` | ||
type Users { | ||
name: String | ||
custom: JSON | ||
} | ||
`, | ||
}, | ||
testUtils.CreateDoc{ | ||
DocMap: map[string]any{ | ||
"name": "John", | ||
"custom": "{\"tree\": \"maple\", \"age\": 250}", | ||
}, | ||
}, | ||
testUtils.CreateDoc{ | ||
DocMap: map[string]any{ | ||
"name": "Andy", | ||
"custom": "{\"tree\": \"oak\", \"age\": 450}", | ||
}, | ||
}, | ||
testUtils.Request{ | ||
// the filtered-by JSON has no spaces, because this is now it's stored. | ||
Request: `query { | ||
Users(filter: {custom: {_eq: "{\"tree\":\"oak\",\"age\":450}"}}) { | ||
name | ||
} | ||
}`, | ||
Results: []map[string]any{{"name": "Andy"}}, | ||
}, | ||
}, | ||
} | ||
|
||
testUtils.ExecuteTestCase(t, test) | ||
} |
54 changes: 54 additions & 0 deletions
54
tests/integration/query/simple/with_filter/with_in_blob_test.go
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,54 @@ | ||
// Copyright 2024 Democratized Data Foundation | ||
// | ||
// Use of this software is governed by the Business Source License | ||
// included in the file licenses/BSL.txt. | ||
// | ||
// As of the Change Date specified in that file, in accordance with | ||
// the Business Source License, use of this software will be governed | ||
// by the Apache License, Version 2.0, included in the file | ||
// licenses/APL.txt. | ||
|
||
package simple | ||
|
||
import ( | ||
"testing" | ||
|
||
testUtils "github.com/sourcenetwork/defradb/tests/integration" | ||
) | ||
|
||
func TestQuerySimple_WithInOpOnBlobField_ShouldFilter(t *testing.T) { | ||
test := testUtils.TestCase{ | ||
Actions: []any{ | ||
testUtils.SchemaUpdate{ | ||
Schema: ` | ||
type Users { | ||
name: String | ||
data: Blob | ||
} | ||
`, | ||
}, | ||
testUtils.CreateDoc{ | ||
Doc: `{ | ||
"name": "John", | ||
"data": "00FF99AA" | ||
}`, | ||
}, | ||
testUtils.CreateDoc{ | ||
Doc: `{ | ||
"name": "Andy", | ||
"data": "FA02CC45" | ||
}`, | ||
}, | ||
testUtils.Request{ | ||
Request: `query { | ||
Users(filter: {data: {_in: ["00FF99AA"]}}) { | ||
name | ||
} | ||
}`, | ||
Results: []map[string]any{{"name": "John"}}, | ||
}, | ||
}, | ||
} | ||
|
||
testUtils.ExecuteTestCase(t, test) | ||
} |
Oops, something went wrong.