TropicalPenguin opened a new issue, #330:
URL: https://github.com/apache/age/issues/330
**Describe the bug**
After setting up the following data:
`CREATE (a:A)-[:incs]->(:C), (a)-[:incs]->(:C) RETURN a`
The node labelled A has two outgoing edges, each going to a node labelled C.
With AGE, I can successfully match these two nodes with the following query,
substituting for 0 the ID of a:
`MATCH (a:A) WHERE ID(a)=0 WITH a OPTIONAL MATCH (a)-[:incs]->(c) RETURN c`.
_However_, with the slightly more complex query (again substituting the
generated ID as needed), to capture only the C's which have one or zero 'incs'
edges, AGE is giving an invalid result:
`MATCH (a:A) WHERE ID(a)=0 WITH a OPTIONAL MATCH
(a)-[:incs]->(c)-[d:incs]-() WITH a,c,COUNT(d) AS deps WHERE deps<=1 RETURN
c,deps`
**How are you accessing AGE (Command line, driver, etc.)?**
- Golang Driver, Command Line
**What data setup do we need to do?**
Try running the following Go 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:[email protected]: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)
}
cursor, err := age.ExecCypher(tx, graphName, 0, "MATCH (n) DETACH
DELETE n")
if err != nil {
panic(err)
}
cursor, err = age.ExecCypher(tx, graphName, 1, "CREATE
(a:A)-[:incs]->(:C), (a)-[:incs]->(:C) RETURN a")
if err != nil {
panic(err)
}
var row []age.Entity
if cursor.Next() {
row, err = cursor.GetRow()
aid := row[0].(*age.Vertex).Id()
tx.Commit()
tx, err = db.Begin()
if err != nil {
panic(err)
}
// This query can work with AGE, returning each of the two
nodes with label 'C':
//q := fmt.Sprintf("MATCH (a:A) WHERE ID(a)=%d WITH a OPTIONAL
MATCH (a)-[:incs]->(c) RETURN c", aid)
// Whereas this returns a single row, with a null and a 0
// Expected: Should return the each node labelled C, each with
a value 1 for 'deps'
q := fmt.Sprintf("MATCH (a:A) WHERE ID(a)=%d WITH a OPTIONAL
MATCH (a)-[:incs]->(c)-[d:incs]-() WITH a,c,COUNT(d) AS deps WHERE deps<=1
RETURN c,deps", aid)
fmt.Println("Test query:", q)
cursor, err = age.ExecCypher(tx, graphName, 2, q)
if err == nil {
for cursor.Next() {
row, err = cursor.GetRow()
for rowIdx, v := range row {
fmt.Println(rowIdx, len(row), v)
}
}
} else {
fmt.Println("ERROR:", err)
}
} else {
tx.Commit()
tx, err = db.Begin()
if err != nil {
panic(err)
}
}
_, 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?**
```go
q := fmt.Sprintf("MATCH (a:A) WHERE ID(a)=%d WITH a OPTIONAL
MATCH (a)-[:incs]->(c)-[d:incs]-() WITH a,c,COUNT(d) AS deps WHERE deps<=1
RETURN c,deps", aid)
cursor, err = age.ExecCypher(tx, graphName, 2, q)
```
When the cursor is traversed in the following lines, this gives the output
```
0 2 <nil>
1 2 0
```
**Expected behavior**
Whereas it is expected to print something more like:
```
0 2 V{id:1407374883553283, label:C, props:map[]}
1 2 1
0 2 V{id:1407374883553284, label:C, props:map[]}
1 2 1
```
**Environment (please complete the following information):**
- Version: 1.0.0
**Additional context**
N/A
--
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]