apache / apache/age

Error on relationship when source vertex in EXISTS() has alias

Open
#339 11 comments 0 reactions 0 assignees View on GitHub
bug
Dominant language
C
Stars
4.8k
Forks
523
Avg merge
1d 2h
Merged PRs (30d)
9

Description

**Describe the bug**

Given the basic data set up:
`CREATE (:A)-[:incs]->(:C)`

The following succeeds:
`MATCH (a:A) WITH a OPTIONAL MATCH (a)-[:incs]->(c) WHERE EXISTS((c)<-[:incs]-()) RETURN a,c`

But simply adding an alias for the source vertex makes the query fail:
`MATCH (a:A) WITH a OPTIONAL MATCH (a)-[:incs]->(c) WHERE EXISTS((c)<-[:incs]-(a)) RETURN a,c`

With the following error:
`pq: attribute 1 of type test.incs has wrong type`

I have confirmed that both matches succeed with identical output in Neo4j sandbox.

**How are you accessing AGE (Command line, driver, etc.)?**
- Command line
- Golang driver

**What data setup do we need to do?**

Either run the above commands in psql, or try the following short test golang program:
```go
package main

import (
"database/sql"
"fmt"

_ "github.com/lib/pq"
"github.com/rhizome-ai/apache-age-go/age"
)

func main() {
dsn := "postgres://postgres:postgres@127.0.0.1:5434/postgres?sslmode=disable"
db, err := sql.Open("postgres", dsn)
if err != nil {
panic(err)
}

graphName := "test"

_, err = age.GetReady(db, graphName)
if err != nil {
panic(err)
}

tx, err := db.Begin()
if err != nil {
panic(err)
}

var row []age.Entity

cursor, err := age.ExecCypher(tx, graphName, 0, "CREATE (:A)-[:incs]->(:C)")
if err != nil {
panic(err)
}

cursor, err = age.ExecCypher(tx, graphName, 2, "MATCH (a:A) WITH a OPTIONAL MATCH (a)-[:incs]->(c) WHERE EXISTS((c)<-[:incs]-()) RETURN a,c")
if err != nil {
panic(err)
}

for cursor.Next() {
row, err = cursor.GetRow()

for rowIdx, v := range row {
fmt.Println(rowIdx, len(row), v)
}
}
fmt.Printf("\n")

cursor, err = age.ExecCypher(tx, graphName, 2, "MATCH (a:A) WITH a OPTIONAL MATCH (a)-[:incs]->(c) WHERE EXISTS((c)<-[:incs]-(a)) RETURN a,c")
if err != nil {
panic(err)
}
for cursor.Next() {
row, err = cursor.GetRow()

for rowIdx, v := range row {
fmt.Println(rowIdx, len(row), v)
}
}

_, err = tx.Exec(fmt.Sprintf("SELECT drop_graph('%s', true);", graphName))
if err != nil {
panic(err)
}
tx.Commit()
}
```

**What is the necessary configuration info needed?**
- N/A

**What is the command that caused the error?**
```pgsql
SELECT * from cypher('test', $$
MATCH (a:A) WITH a OPTIONAL MATCH (a)-[:incs]->(c) WHERE EXISTS((c)<-[:incs]-(a)) RETURN a,c
$$) as (a agtype, c agtype);
```
```
ERROR: attribute 1 of type test.incs has wrong type
```

**Expected behavior**
The two queries should return the same result, without error.

**Environment (please complete the following information):**
- Version: 1.0.0

**Additional context**
N/A

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.