-
-
Notifications
You must be signed in to change notification settings - Fork 68
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add a test for ignoring necessary filters (#431)
* add a test for ignoring necessary filters * simplify query suggestion
- Loading branch information
Showing
5 changed files
with
690 additions
and
0 deletions.
There are no files selected for viewing
124 changes: 124 additions & 0 deletions
124
trustfall_core/test_data/tests/valid_queries/fold_count_filter_on_a_tag.graphql-parsed.ron
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,124 @@ | ||
Ok(TestParsedGraphQLQuery( | ||
schema_name: "numbers", | ||
query: Query( | ||
root_connection: FieldConnection( | ||
position: Pos( | ||
line: 3, | ||
column: 5, | ||
), | ||
name: "Two", | ||
), | ||
root_field: FieldNode( | ||
position: Pos( | ||
line: 3, | ||
column: 5, | ||
), | ||
name: "Two", | ||
connections: [ | ||
(FieldConnection( | ||
position: Pos( | ||
line: 4, | ||
column: 9, | ||
), | ||
name: "value", | ||
), FieldNode( | ||
position: Pos( | ||
line: 4, | ||
column: 9, | ||
), | ||
name: "value", | ||
tag: [ | ||
TagDirective( | ||
name: Some("two"), | ||
), | ||
], | ||
)), | ||
(FieldConnection( | ||
position: Pos( | ||
line: 5, | ||
column: 9, | ||
), | ||
name: "multiple", | ||
arguments: { | ||
"max": Int64(3), | ||
}, | ||
), FieldNode( | ||
position: Pos( | ||
line: 5, | ||
column: 9, | ||
), | ||
name: "multiple", | ||
connections: [ | ||
(FieldConnection( | ||
position: Pos( | ||
line: 6, | ||
column: 13, | ||
), | ||
name: "value", | ||
), FieldNode( | ||
position: Pos( | ||
line: 6, | ||
column: 13, | ||
), | ||
name: "value", | ||
filter: [ | ||
FilterDirective( | ||
operation: Equals((), VariableRef("six")), | ||
), | ||
], | ||
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: GreaterThanOrEqual((), VariableRef("zero")), | ||
), | ||
FilterDirective( | ||
operation: LessThan((), TagRef("two")), | ||
), | ||
], | ||
)), | ||
)), | ||
), FieldNode( | ||
position: Pos( | ||
line: 7, | ||
column: 13, | ||
), | ||
name: "primeFactor", | ||
transform_group: Some(TransformGroup( | ||
transform: TransformDirective( | ||
kind: Count, | ||
), | ||
filter: [ | ||
FilterDirective( | ||
operation: GreaterThanOrEqual((), VariableRef("zero")), | ||
), | ||
FilterDirective( | ||
operation: LessThan((), TagRef("two")), | ||
), | ||
], | ||
)), | ||
)), | ||
], | ||
)), | ||
], | ||
), | ||
), | ||
arguments: { | ||
"six": Uint64(6), | ||
"zero": Uint64(0), | ||
}, | ||
)) |
26 changes: 26 additions & 0 deletions
26
trustfall_core/test_data/tests/valid_queries/fold_count_filter_on_a_tag.graphql.ron
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,26 @@ | ||
TestGraphQLQuery ( | ||
// This test ensures that we do not ignore filters that should | ||
// disable an optimization in which we only compute part of a | ||
// fold. | ||
// | ||
// This test should result in no results. However, if we partially | ||
// compute the fold ignoring the `>=` filter, we will get a result | ||
// of `{ "value": 6 }`. | ||
schema_name: "numbers", | ||
query: r#" | ||
{ | ||
Two { | ||
value @tag(name: "two") | ||
multiple(max: 3) { | ||
value @filter(op: "=", value: ["$six"]) @output | ||
primeFactor @fold @transform(op: "count") | ||
@filter(op: ">=", value: ["$zero"]) | ||
@filter(op: "<", value: ["%two"]) | ||
} | ||
} | ||
}"#, | ||
arguments: { | ||
"zero": Uint64(0), | ||
"six": Uint64(6), | ||
}, | ||
) |
84 changes: 84 additions & 0 deletions
84
trustfall_core/test_data/tests/valid_queries/fold_count_filter_on_a_tag.ir.ron
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,84 @@ | ||
Ok(TestIRQuery( | ||
schema_name: "numbers", | ||
ir_query: IRQuery( | ||
root_name: "Two", | ||
root_component: IRQueryComponent( | ||
root: Vid(1), | ||
vertices: { | ||
Vid(1): IRVertex( | ||
vid: Vid(1), | ||
type_name: "Prime", | ||
), | ||
Vid(2): IRVertex( | ||
vid: Vid(2), | ||
type_name: "Composite", | ||
filters: [ | ||
Equals(LocalField( | ||
field_name: "value", | ||
field_type: "Int", | ||
), Variable(VariableRef( | ||
variable_name: "six", | ||
variable_type: "Int", | ||
))), | ||
], | ||
), | ||
}, | ||
edges: { | ||
Eid(1): IREdge( | ||
eid: Eid(1), | ||
from_vid: Vid(1), | ||
to_vid: Vid(2), | ||
edge_name: "multiple", | ||
parameters: EdgeParameters( | ||
contents: { | ||
"max": Int64(3), | ||
}, | ||
), | ||
), | ||
}, | ||
folds: { | ||
Eid(2): IRFold( | ||
eid: Eid(2), | ||
from_vid: Vid(2), | ||
to_vid: Vid(3), | ||
edge_name: "primeFactor", | ||
component: IRQueryComponent( | ||
root: Vid(3), | ||
vertices: { | ||
Vid(3): IRVertex( | ||
vid: Vid(3), | ||
type_name: "Prime", | ||
), | ||
}, | ||
), | ||
post_filters: [ | ||
GreaterThanOrEqual(Count, Variable(VariableRef( | ||
variable_name: "zero", | ||
variable_type: "Int!", | ||
))), | ||
LessThan(Count, Tag(ContextField(ContextField( | ||
vertex_id: Vid(1), | ||
field_name: "value", | ||
field_type: "Int", | ||
)))), | ||
], | ||
), | ||
}, | ||
outputs: { | ||
"value": ContextField( | ||
vertex_id: Vid(2), | ||
field_name: "value", | ||
field_type: "Int", | ||
), | ||
}, | ||
), | ||
variables: { | ||
"six": "Int", | ||
"zero": "Int!", | ||
}, | ||
), | ||
arguments: { | ||
"six": Uint64(6), | ||
"zero": Uint64(0), | ||
}, | ||
)) |
11 changes: 11 additions & 0 deletions
11
trustfall_core/test_data/tests/valid_queries/fold_count_filter_on_a_tag.output.ron
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,11 @@ | ||
TestInterpreterOutputData( | ||
schema_name: "numbers", | ||
outputs: { | ||
"value": Output( | ||
name: "value", | ||
value_type: "Int", | ||
vid: Vid(2), | ||
), | ||
}, | ||
results: [], | ||
) |
Oops, something went wrong.