community: Apache AGE wrapper additional edge cases. (#28151)

Description: 
Current AGEGraph() implementation does some custom wrapping for graph
queries. The method here is _wrap_query() as it parse the field from the
original query to add some SQL context to it.
This improves the current parsing logic to cover additional edge cases
that are added to the test coverage, basically if any Node property name
or value has the "return" literal in it will break the graph / SQL
query.
We discovered this while dealing with real world datasets, is not an
uncommon scenario and I think it needs to be covered.
This commit is contained in:
German Martin
2024-12-16 13:28:01 -03:00
committed by GitHub
parent 768e4a7fd4
commit d5d18c62b3
2 changed files with 36 additions and 4 deletions

View File

@@ -54,6 +54,7 @@ class TestAGEGraph(unittest.TestCase):
def test_wrap_query(self) -> None:
inputs = [
# Positive case: Simple return clause
"""
MATCH (keanu:Person {name:'Keanu Reeves'})
RETURN keanu.name AS name, keanu.born AS born
@@ -61,9 +62,20 @@ class TestAGEGraph(unittest.TestCase):
"""
MERGE (n:a {id: 1})
""",
# Negative case: Return in a string value
"""
MATCH (n {description: "This will return a value"})
MERGE (n)-[:RELATED]->(m)
""",
# Negative case: Return in a property key
"""
MATCH (n {returnValue: "some value"})
MERGE (n)-[:RELATED]->(m)
""",
]
expected = [
# Expected output for the first positive case
"""
SELECT * FROM ag_catalog.cypher('test', $$
MATCH (keanu:Person {name:'Keanu Reeves'})
@@ -75,6 +87,19 @@ class TestAGEGraph(unittest.TestCase):
MERGE (n:a {id: 1})
$$) AS (a agtype);
""",
# Expected output for the negative cases (no return clause)
"""
SELECT * FROM ag_catalog.cypher('test', $$
MATCH (n {description: "This will return a value"})
MERGE (n)-[:RELATED]->(m)
$$) AS (a agtype);
""",
"""
SELECT * FROM ag_catalog.cypher('test', $$
MATCH (n {returnValue: "some value"})
MERGE (n)-[:RELATED]->(m)
$$) AS (a agtype);
""",
]
for idx, value in enumerate(inputs):