raederan opened a new issue, #1391:
URL: https://github.com/apache/age/issues/1391

   Hi,
   
   Maybe its an issue with my query, with the binding or something else. I've 
created a query that follows a nested SPARQL query transpiled to Cypher. Below 
you see two cypher statements and the difference is in the `WHERE` clause.
   
   Query that works as expected:
   ```sql
   SELECT * FROM ag_catalog.cypher('spcustom', $$
   MATCH 
(class)-[{iri:'http://www.w3.org/2000/01/rdf-schema#subClassOf'}]->({iri:'http://xmlns.com/foaf/0.1/Document'})
   MATCH 
(document)-[{iri:'http://www.w3.org/1999/02/22-rdf-syntax-ns#type'}]->(class)
   MATCH (document)-[{iri:'http://purl.org/dc/terms/issued'}]->(yr)
   MATCH (document)-[{iri:'http://purl.org/dc/elements/1.1/creator'}]->(author)
   MATCH (author)-[{iri:'http://xmlns.com/foaf/0.1/name'}]->(name) 
   OPTIONAL MATCH 
(class2)-[{iri:'http://www.w3.org/2000/01/rdf-schema#subClassOf'}]->({iri:'http://xmlns.com/foaf/0.1/Document'}),
 
(document2)-[{iri:'http://www.w3.org/1999/02/22-rdf-syntax-ns#type'}]->(class2),
 (document2)-[{iri:'http://purl.org/dc/terms/issued'}]->(yr2), 
(document2)-[{iri:'http://purl.org/dc/elements/1.1/creator'}]->(author2) 
   WHERE coalesce(yr2.iri, yr2.bnid, yr2.value) < coalesce(yr.iri, yr.bnid, 
yr.value) 
     AND coalesce(author.iri, author.bnid, author.value) = 
coalesce(author2.iri, author2.bnid, author2.value) 
   RETURN coalesce(yr.iri, yr.bnid, yr.value), coalesce(name.iri, name.bnid, 
name.value), coalesce(document.iri, document.bnid, document.value), 
coalesce(author2.iri, author2.bnid, author2.value) $$) 
   AS (yr ag_catalog.agtype, name ag_catalog.agtype, document 
ag_catalog.agtype, author2 ag_catalog.agtype);
   ```
   
   Gives the following output as expected:
     ```txt
        yr   |        name        |                                document     
                            |                author2                 
     
--------+--------------------+-------------------------------------------------------------------------+----------------------------------------
      "1952" | "Paul Erdoes"      | 
"http://localhost/publications/inprocs/Proceeding1/1952/Inproceeding6";  | 
"http://localhost/persons/Paul_Erdoes";
      "1953" | "Matro Newell"     | 
"http://localhost/publications/inprocs/Proceeding1/1953/Inproceeding12"; | 
      "1952" | "Dirthe Kiewiet"   | 
"http://localhost/publications/inprocs/Proceeding1/1952/Inproceeding24"; | 
      "1950" | "Editta Servoss"   | 
"http://localhost/publications/inprocs/Proceeding1/1950/Inproceeding1";  | 
      "1950" | "Paul Erdoes"      | 
"http://localhost/publications/inprocs/Proceeding1/1950/Inproceeding1";  | 
      "1952" | "Gualtiero Hemken" | 
"http://localhost/publications/inprocs/Proceeding1/1952/Inproceeding6";  | 
      "1950" | "Bhoomika Secord"  | 
"http://localhost/publications/inprocs/Proceeding1/1950/Inproceeding1";  | 
     (7 rows)
     ```
   
   Query that works not as expected, added `AND NOT EXISTS ((author2))` to the 
`WHERE` clause to filter the first row of the matched pattern as shown in the 
output above:
   ```sql
   SELECT * FROM ag_catalog.cypher('spcustom', $$
   MATCH 
(class)-[{iri:'http://www.w3.org/2000/01/rdf-schema#subClassOf'}]->({iri:'http://xmlns.com/foaf/0.1/Document'})
   MATCH 
(document)-[{iri:'http://www.w3.org/1999/02/22-rdf-syntax-ns#type'}]->(class)
   MATCH (document)-[{iri:'http://purl.org/dc/terms/issued'}]->(yr)
   MATCH (document)-[{iri:'http://purl.org/dc/elements/1.1/creator'}]->(author)
   MATCH (author)-[{iri:'http://xmlns.com/foaf/0.1/name'}]->(name) 
   OPTIONAL MATCH 
(class2)-[{iri:'http://www.w3.org/2000/01/rdf-schema#subClassOf'}]->({iri:'http://xmlns.com/foaf/0.1/Document'}),
 
(document2)-[{iri:'http://www.w3.org/1999/02/22-rdf-syntax-ns#type'}]->(class2),
 (document2)-[{iri:'http://purl.org/dc/terms/issued'}]->(yr2), 
(document2)-[{iri:'http://purl.org/dc/elements/1.1/creator'}]->(author2) 
   WHERE coalesce(yr2.iri, yr2.bnid, yr2.value) < coalesce(yr.iri, yr.bnid, 
yr.value) 
     AND coalesce(author.iri, author.bnid, author.value) = 
coalesce(author2.iri, author2.bnid, author2.value) 
     AND NOT EXISTS ((author2)) 
   RETURN coalesce(yr.iri, yr.bnid, yr.value), coalesce(name.iri, name.bnid, 
name.value), coalesce(document.iri, document.bnid, document.value), 
coalesce(author2.iri, author2.bnid, author2.value) $$) 
   AS (yr ag_catalog.agtype, name ag_catalog.agtype, document 
ag_catalog.agtype, author2 ag_catalog.agtype);
   ```
   
   Gives the following output not as expected, where just the attribute 
`author2` has no value but the tuple still exists:
   
   ```txt
      yr   |        name        |                                document       
                          | author2 
   
--------+--------------------+-------------------------------------------------------------------------+---------
    "1953" | "Matro Newell"     | 
"http://localhost/publications/inprocs/Proceeding1/1953/Inproceeding12"; | 
    "1952" | "Dirthe Kiewiet"   | 
"http://localhost/publications/inprocs/Proceeding1/1952/Inproceeding24"; | 
    "1950" | "Editta Servoss"   | 
"http://localhost/publications/inprocs/Proceeding1/1950/Inproceeding1";  | 
    "1950" | "Paul Erdoes"      | 
"http://localhost/publications/inprocs/Proceeding1/1950/Inproceeding1";  | 
    "1952" | "Paul Erdoes"      | 
"http://localhost/publications/inprocs/Proceeding1/1952/Inproceeding6";  | 
    "1952" | "Gualtiero Hemken" | 
"http://localhost/publications/inprocs/Proceeding1/1952/Inproceeding6";  | 
    "1950" | "Bhoomika Secord"  | 
"http://localhost/publications/inprocs/Proceeding1/1950/Inproceeding1";  | 
   (7 rows)
   ```
   
   It is not neccessary to display the `author2`, I just returned that to 
illustrate the issue. 
   I'm on PG12 in this case.
   Can someone help me out here?
   
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to