neo4j-rstats / neo4r

A Modern and Flexible Neo4J Driver
https://neo4j-rstats.github.io/user-guide/
Other
106 stars 29 forks source link

query only yielding single line results? #44

Closed ghost closed 5 years ago

ghost commented 5 years ago
call_neo4j("MATCH (n) RETURN distinct labels(n)", con)

yields a single line result, While on the admin webpage of the server I get a list of mulitple records. What am I doing wrong?

ColinFay commented 5 years ago

Thanks @ilpepe. This might be a parsing error.

If you want to get the labels, though, you can call directly con$get_labels() and it should return the correct answer.

Can you confirm you get the right answer with con$get_labels()?

ghost commented 5 years ago

Hi, I just that query just as an example. It actually is all the same for every query I do. con$get_labels() indeed gives me the right labels.

A true reprex is a bit hard for me, as the database is on the local network.

con = neo4j_api$new("xxx:7474/", 
                             user = username, 
                             password = password)
con$ping() = 200

con$get_schema()
con$get_labels()

call_neo4j("MATCH (s:S)--(p:P) WHERE p.name = 'AAA' RETURN s.name;", con)

ping gives me 200 (as expected, I guess) get_labels() gives me the right lables get_schema() yields Null data.table (0 rows and 0 cols)

and the query

$s.name
# A tibble: 1 x 1
  row       
  <chr>     
1 XXXXXXXXX

attr(,"class")
[1] "neo"  "neo"  "list"

XXX stand for an element of the list found via the admin page. And, I think, not by accident, the last element. This was exactly the same for the labels query as originally posted.

I hope this helps you a bit?

dfgitn4j commented 5 years ago

@ilpepe Seeing the same thing. Using the Movie example database:

r<-"MATCH (tom:Person {name: 'Tom Hanks'})-[:ACTED_IN]->(tomHanksMovies) RETURN tomHanksMovies;" 
    %>% call_neo4j(con, type = 'row')
r # will see only one row:
# $tomHanksMovies
# # A tibble: 1 x 3
#   tagline                                                                                               title                released
#   <chr>                                                                                                 <chr>                   <int>
# 1 A stiff drink. A little mascara. A lot of nerve. Who said they couldn't bring down the Soviet empire. Charlie Wilson's War     2007

j<-"MATCH (tom:Person {name: 'Tom Hanks'})-[:ACTED_IN]->(tomHanksMovies) RETURN tomHanksMovies;" 
    %>% call_neo4j(con, output = 'json')
j  # will see all data returned in json format
ColinFay commented 5 years ago

Ah, indeed, I can reproduce.

Looking into that right now.

ColinFay commented 5 years ago

@ilpepe @dfgitn4j

This is indeed a bug due to a last minute change in the API result parser. The latests commit should have fixed this, can you try and confirm?

remove.packages("neo4r")
if(!requireNamespace("remotes")){
  install.packages("remotes")
}
remotes::install_github("neo4j-rstats/neo4r")

Thanks

ghost commented 5 years ago

A true hero. Works!

I'm however not sure what type graph should give. Of a working query (type = r, output= json), I get this when using type = "graph"

[
  [
    {
      "graph": {
        "nodes": [],
        "relationships": []
      }
    },
    {
      "graph": {
        "nodes": [],
        "relationships": []
      }
    },
    {
      "graph": {
        "nodes": [],
        "relationships": []
      }
    },
    {
      "graph": {
        "nodes": [],
        "relationships": []
      }
    },
    {
      "graph": {
        "nodes": [],
        "relationships": []
      }
    }
  ]
] 

But maybe I missed a point here?

ColinFay commented 5 years ago

That would mean that your result is empty 🤔

Here is an example output :

library(neo4r)
con <- neo4j_api$new(url = "http://localhost:7474", 
                     user = "neo4j", password = "neo4j")

'MATCH (r:record) -[w:WAS_RECORDED] -> (b:Band) where b.formed = 1991 RETURN * LIMIT 2;' %>%
  call_neo4j(con, type = "row", output = "json")
#> [
#>   [
#>     {
#>       "row": [
#>         {
#>           "name": ["Burzum"],
#>           "formed": [1991]
#>         },
#>         {
#>           "release": [1992],
#>           "name": ["Hvis lyset tar oss"]
#>         },
#>         {}
#>       ],
#>       "meta": [
#>         {
#>           "id": [12591],
#>           "type": ["node"],
#>           "deleted": [false]
#>         },
#>         {
#>           "id": [13608],
#>           "type": ["node"],
#>           "deleted": [false]
#>         },
#>         {
#>           "id": [21824],
#>           "type": ["relationship"],
#>           "deleted": [false]
#>         }
#>       ]
#>     },
#>     {
#>       "row": [
#>         {
#>           "name": ["Burzum"],
#>           "formed": [1991]
#>         },
#>         {
#>           "release": [1993],
#>           "name": ["Filosofem"]
#>         },
#>         {}
#>       ],
#>       "meta": [
#>         {
#>           "id": [12591],
#>           "type": ["node"],
#>           "deleted": [false]
#>         },
#>         {
#>           "id": [13613],
#>           "type": ["node"],
#>           "deleted": [false]
#>         },
#>         {
#>           "id": [21825],
#>           "type": ["relationship"],
#>           "deleted": [false]
#>         }
#>       ]
#>     }
#>   ]
#> ]

'MATCH (r:record) -[w:WAS_RECORDED] -> (b:Band) where b.formed = 1991 RETURN * LIMIT 2;' %>%
  call_neo4j(con, type = "graph", output = "json")
#> [
#>   [
#>     {
#>       "graph": {
#>         "nodes": [
#>           {
#>             "id": ["13608"],
#>             "labels": [
#>               ["record"]
#>             ],
#>             "properties": {
#>               "release": [1992],
#>               "name": ["Hvis lyset tar oss"]
#>             }
#>           },
#>           {
#>             "id": ["12591"],
#>             "labels": [
#>               ["Band"]
#>             ],
#>             "properties": {
#>               "name": ["Burzum"],
#>               "formed": [1991]
#>             }
#>           }
#>         ],
#>         "relationships": [
#>           {
#>             "id": ["21824"],
#>             "type": ["WAS_RECORDED"],
#>             "startNode": ["13608"],
#>             "endNode": ["12591"],
#>             "properties": {}
#>           }
#>         ]
#>       }
#>     },
#>     {
#>       "graph": {
#>         "nodes": [
#>           {
#>             "id": ["13613"],
#>             "labels": [
#>               ["record"]
#>             ],
#>             "properties": {
#>               "release": [1993],
#>               "name": ["Filosofem"]
#>             }
#>           },
#>           {
#>             "id": ["12591"],
#>             "labels": [
#>               ["Band"]
#>             ],
#>             "properties": {
#>               "name": ["Burzum"],
#>               "formed": [1991]
#>             }
#>           }
#>         ],
#>         "relationships": [
#>           {
#>             "id": ["21825"],
#>             "type": ["WAS_RECORDED"],
#>             "startNode": ["13613"],
#>             "endNode": ["12591"],
#>             "properties": {}
#>           }
#>         ]
#>       }
#>     }
#>   ]
#> ]

Created on 2019-01-30 by the reprex package (v0.2.1)

But I'm thinking about removing this feature, I wonder if it actually makes sense to give the possibility to use the JSON output

ghost commented 5 years ago

Well, it shouldn't be empty. The original query (row type) gave me hits. Switching it to graph messes it up. I think you can also see the query should give me 5 hits, as there are 5 json blocks there... I'm also unsure whether the json output has the biggest advantage.

However removing output, and just set type to "graph", doesn't work either :-(

No graph data found.
Either your call can't be converted to a graph 
or there is no data at all matching your call.
Verify your call or try type = "row".

But maybe I should test this on public database, to do some reprex (could always be that my database is crappy somehow). @dfgitn4j : you talk about a Movie database? Where can I find this one?

ghost commented 5 years ago

whoops. Found it. I used graph output in combination with something else then "RETURN " If I use RETURN it works. Sorry.