Skip to content

Commit

Permalink
Add a test for ignoring necessary filters (#431)
Browse files Browse the repository at this point in the history
* add a test for ignoring necessary filters

* simplify query suggestion
  • Loading branch information
u9g authored Aug 5, 2023
1 parent fbcb02a commit 1794044
Show file tree
Hide file tree
Showing 5 changed files with 690 additions and 0 deletions.
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),
},
))
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),
},
)
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),
},
))
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: [],
)
Loading

0 comments on commit 1794044

Please sign in to comment.