Skip to content

Commit

Permalink
Add test cases with @fold and edge degree filter.
Browse files Browse the repository at this point in the history
  • Loading branch information
obi1kenobi committed Oct 24, 2017
1 parent 6bb19b0 commit f840aa9
Show file tree
Hide file tree
Showing 2 changed files with 158 additions and 0 deletions.
71 changes: 71 additions & 0 deletions graphql_compiler/tests/test_compiler.py
Expand Up @@ -1717,6 +1717,77 @@ def test_has_edge_degree_op_filter_with_optional(self):
check_test_data(self, graphql_input, expected_match, expected_gremlin,
expected_output_metadata, expected_input_metadata)

def test_has_edge_degree_op_filter_with_fold(self):
graphql_input = '''{
Species {
name @output(out_name: "species_name")
in_Animal_OfSpecies {
name @output(out_name: "parent_name")
out_Animal_ParentOf @filter(op_name: "has_edge_degree", value: ["$child_count"])
@fold {
name @output(out_name: "child_names")
}
}
}
}'''

expected_match = '''
SELECT
$Species__in_Animal_OfSpecies___1___out_Animal_ParentOf.name AS `child_names`,
Species__in_Animal_OfSpecies___1.name AS `parent_name`,
Species___1.name AS `species_name`
FROM (
MATCH {{
class: Species,
as: Species___1
}}.in('Animal_OfSpecies') {{
where: ((
(({child_count} = 0) AND (out_Animal_ParentOf IS null)) OR
((out_Animal_ParentOf IS NOT null) AND
(out_Animal_ParentOf.size() = {child_count}))
)),
as: Species__in_Animal_OfSpecies___1
}}
RETURN $matches
) LET
$Species__in_Animal_OfSpecies___1___out_Animal_ParentOf =
Species__in_Animal_OfSpecies___1.out("Animal_ParentOf").asList()
'''
expected_gremlin = '''
g.V('@class', 'Species')
.as('Species___1')
.in('Animal_OfSpecies')
.filter{it, m -> (
(($child_count == 0) && (it.out_Animal_ParentOf == null)) ||
((it.out_Animal_ParentOf != null) &&
(it.out_Animal_ParentOf.count() == $child_count))
)}
.as('Species__in_Animal_OfSpecies___1')
.back('Species___1')
.transform{it, m -> new com.orientechnologies.orient.core.record.impl.ODocument([
child_names: (
(m.Species__in_Animal_OfSpecies___1.out_Animal_ParentOf == null) ?
[] :
(m.Species__in_Animal_OfSpecies___1.out_Animal_ParentOf.collect{entry -> entry.inV.next().name})
),
parent_name: m.Species__in_Animal_OfSpecies___1.name,
species_name: m.Species___1.name
])}
'''
expected_output_metadata = {
'species_name': OutputMetadata(type=GraphQLString, optional=False),
'parent_name': OutputMetadata(type=GraphQLString, optional=False),
'child_names': OutputMetadata(type=GraphQLList(GraphQLString), optional=False),
}
expected_input_metadata = {
'child_count': GraphQLInt,
}

check_test_data(self, graphql_input, expected_match, expected_gremlin,
expected_output_metadata, expected_input_metadata)

def test_simple_union(self):
graphql_input = '''{
Species {
Expand Down
87 changes: 87 additions & 0 deletions graphql_compiler/tests/test_ir_generation.py
Expand Up @@ -1966,6 +1966,93 @@ def test_has_edge_degree_op_filter_with_optional(self):
check_test_data(self, graphql_input, expected_blocks,
expected_output_metadata, expected_input_metadata, expected_location_types)

def test_has_edge_degree_op_filter_with_fold(self):
graphql_input = '''{
Species {
name @output(out_name: "species_name")
in_Animal_OfSpecies {
name @output(out_name: "parent_name")
out_Animal_ParentOf @filter(op_name: "has_edge_degree", value: ["$child_count"])
@fold {
name @output(out_name: "child_names")
}
}
}
}'''

base_location = helpers.Location(('Species',))
animal_location = base_location.navigate_to_subpath('in_Animal_OfSpecies')
animal_fold = helpers.FoldScopeLocation(animal_location, ('out', 'Animal_ParentOf'))

expected_blocks = [
blocks.QueryRoot({'Species'}),
blocks.MarkLocation(base_location),
blocks.Traverse('in', 'Animal_OfSpecies'),
blocks.Filter(
expressions.BinaryComposition(
u'||',
expressions.BinaryComposition( # the zero-edge check
u'&&',
expressions.BinaryComposition(
u'=',
expressions.Variable('$child_count', GraphQLInt),
expressions.ZeroLiteral
),
expressions.BinaryComposition(
u'=',
expressions.LocalField('out_Animal_ParentOf'),
expressions.NullLiteral
)
),
expressions.BinaryComposition( # the non-zero-edge check
u'&&',
expressions.BinaryComposition(
u'!=',
expressions.LocalField('out_Animal_ParentOf'),
expressions.NullLiteral
),
expressions.BinaryComposition(
u'=',
expressions.UnaryTransformation(
u'size',
expressions.LocalField('out_Animal_ParentOf')
),
expressions.Variable('$child_count', GraphQLInt),
)
)
)
),
blocks.MarkLocation(animal_location),
blocks.Fold(animal_fold),
blocks.Unfold(),
blocks.Backtrack(base_location),
blocks.ConstructResult({
'species_name': expressions.OutputContextField(
base_location.navigate_to_field('name'), GraphQLString),
'parent_name': expressions.OutputContextField(
animal_location.navigate_to_field('name'), GraphQLString),
'child_names': expressions.FoldedOutputContextField(
animal_fold, 'name', GraphQLList(GraphQLString)),
}),
]
expected_output_metadata = {
'species_name': OutputMetadata(type=GraphQLString, optional=False),
'parent_name': OutputMetadata(type=GraphQLString, optional=False),
'child_names': OutputMetadata(type=GraphQLList(GraphQLString), optional=False),
}
expected_input_metadata = {
'child_count': GraphQLInt,
}
expected_location_types = {
base_location: 'Species',
animal_location: 'Animal',
}

check_test_data(self, graphql_input, expected_blocks,
expected_output_metadata, expected_input_metadata, expected_location_types)

# Disabled until OrientDB fixes the limitation against traversing from an optional vertex.
# For details, see https://github.com/orientechnologies/orientdb/issues/6788
@pytest.mark.skip(reason='traversing from an optional node is not currently supported in MATCH')
Expand Down

0 comments on commit f840aa9

Please sign in to comment.