Skip to content

Commit

Permalink
Add impossible filter and dominated filter tests (#429)
Browse files Browse the repository at this point in the history
* add test for impossible filter

* add overrode filter test

* Update trustfall_core/test_data/tests/valid_queries/fold_count_filter_with_overrode_filter.graphql.ron

Co-authored-by: Predrag Gruevski <2348618+obi1kenobi@users.noreply.github.com>

* Update trustfall_core/test_data/tests/valid_queries/fold_count_filter_with_overrode_filter.graphql.ron

Co-authored-by: Predrag Gruevski <2348618+obi1kenobi@users.noreply.github.com>

* rename > dominated filter test

* add < dominated filter test

* fix dominated by lt test

* make _gt test has results

* correct test again to agree with comment

* correct lt test to match what comment says about it

---------

Co-authored-by: Predrag Gruevski <2348618+obi1kenobi@users.noreply.github.com>
  • Loading branch information
u9g and obi1kenobi authored Aug 4, 2023
1 parent c63d358 commit fbcb02a
Show file tree
Hide file tree
Showing 15 changed files with 1,267 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
Ok(TestParsedGraphQLQuery(
schema_name: "numbers",
query: Query(
root_connection: FieldConnection(
position: Pos(
line: 3,
column: 5,
),
name: "Number",
arguments: {
"max": Int64(30),
"min": Int64(30),
},
),
root_field: FieldNode(
position: Pos(
line: 3,
column: 5,
),
name: "Number",
coerced_to: Some("Composite"),
connections: [
(FieldConnection(
position: Pos(
line: 5,
column: 13,
),
name: "value",
), FieldNode(
position: Pos(
line: 5,
column: 13,
),
name: "value",
output: [
OutputDirective(),
],
)),
(FieldConnection(
position: Pos(
line: 7,
column: 13,
),
name: "primeFactor",
fold: Some(FoldGroup(
fold: FoldDirective(),
transform: Some(TransformGroup(
transform: TransformDirective(
kind: Count,
),
filter: [
FilterDirective(
operation: GreaterThan((), VariableRef("two")),
),
FilterDirective(
operation: GreaterThan((), VariableRef("three")),
),
],
)),
)),
), FieldNode(
position: Pos(
line: 7,
column: 13,
),
name: "primeFactor",
transform_group: Some(TransformGroup(
transform: TransformDirective(
kind: Count,
),
filter: [
FilterDirective(
operation: GreaterThan((), VariableRef("two")),
),
FilterDirective(
operation: GreaterThan((), VariableRef("three")),
),
],
)),
)),
],
),
),
arguments: {
"three": Uint64(3),
"two": Uint64(2),
},
))
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
TestGraphQLQuery (
// Ensure that we properly handle two of the same type of filters
// but one of the filters dominates the other. In this case filtering
// by greater than two is dominated by filtering for greater than three.
//
// This test guards against an accidental min/max mixup in the implementation
// of the optimization that allows us to stop expanding folds early.
// We should only stop when the dominating filter is satisfied,
// not when the dominated filter is satisfied. If such a bug were to happen,
// this query would return `{ "value": 30 }` instead of having no results.
schema_name: "numbers",
query: r#"
{
Number(min: 30, max: 30) {
... on Composite {
value @output
primeFactor @fold @transform(op: "count")
@filter(op: ">", value: ["$two"])
@filter(op: ">", value: ["$three"])
}
}
}"#,
arguments: {
"two": Uint64(2),
"three": Uint64(3),
},
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
Ok(TestIRQuery(
schema_name: "numbers",
ir_query: IRQuery(
root_name: "Number",
root_parameters: EdgeParameters(
contents: {
"max": Int64(30),
"min": Int64(30),
},
),
root_component: IRQueryComponent(
root: Vid(1),
vertices: {
Vid(1): IRVertex(
vid: Vid(1),
type_name: "Composite",
coerced_from_type: Some("Number"),
),
},
folds: {
Eid(1): IRFold(
eid: Eid(1),
from_vid: Vid(1),
to_vid: Vid(2),
edge_name: "primeFactor",
component: IRQueryComponent(
root: Vid(2),
vertices: {
Vid(2): IRVertex(
vid: Vid(2),
type_name: "Prime",
),
},
),
post_filters: [
GreaterThan(Count, Variable(VariableRef(
variable_name: "two",
variable_type: "Int!",
))),
GreaterThan(Count, Variable(VariableRef(
variable_name: "three",
variable_type: "Int!",
))),
],
),
},
outputs: {
"value": ContextField(
vertex_id: Vid(1),
field_name: "value",
field_type: "Int",
),
},
),
variables: {
"three": "Int!",
"two": "Int!",
},
),
arguments: {
"three": Uint64(3),
"two": Uint64(2),
},
))
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
TestInterpreterOutputData(
schema_name: "numbers",
outputs: {
"value": Output(
name: "value",
value_type: "Int",
vid: Vid(1),
),
},
results: [],
)
Loading

0 comments on commit fbcb02a

Please sign in to comment.