philippkueng / node-neo4j

Neo4j REST API wrapper for Node.js
MIT License
211 stars 44 forks source link

Multi-return issues #7

Closed brian-gates closed 10 years ago

brian-gates commented 11 years ago

There is a bug with the following query which I presume to be related to the multi-column return:

START r=relationship() MATCH (s)-[r]->(t) RETURN

curl -H "Content-type: application/json" "http://localhost:7474/db/data/ext/CypherPlugin/graphdb/execute_query" - '{"query": "START r=relationship(*) MATCH (s)-[r]->(t) RETURN s,r,t"}'

results in: http://pastie.org/private/cqdg2ci4uzqiurfwkmza

db.cypherQuery('START r=relationship() MATCH (s)-[r]->(t) RETURN ', function(err, result){ console.log(result); }

results in: http://pastie.org/private/qn6zkbnfr2io4kefq3m3vq

philippkueng commented 11 years ago

Thanks for the bug-report. Interesting.

What's getting returned if you define the lower cypher query as "START r=relationship(*) MATCH (s)-[r]->(t) RETURN s,r,t"

brian-gates commented 11 years ago

http://pastie.org/private/0i0jeqwyvf3bvfm3tongg

philippkueng commented 11 years ago

ok, got the misbehaving function it's addNodeId within main.js. on it. ...should be fixed within an hour. are you using the version from github or the one from npm? ...just asking wether i should publish an update afterwards.

brian-gates commented 11 years ago

I'm using the one from NPM

brian-gates commented 11 years ago

This may actually be an issue with the requests are constructed.

Check this out:

https://gist.github.com/Zaxnyd/8e12b7e17cefe29d8dca

philippkueng commented 11 years ago

nice. it works because it's not matching the replace function in addNodeId. It's a helper method to extract the node or relationship id from the self attribute. By removing the http, it just does nothing, and hence works. But a fix is underway, just need to make sure all the other tests are passing.

brian-gates commented 11 years ago

Actually, did you see the second response? It's returning two objects....

brian-gates commented 11 years ago

This was the issue:

/conf/neo4j-server.properties:org.neo4j.rest.stream=true

philippkueng commented 11 years ago

thanks. for head's up. will have to deactivate that. will aim at fixing the first bug, the second one has to wait for another day, it's already getting late in my TZ.

philippkueng commented 11 years ago

which version of neo4j are you using?

brian-gates commented 11 years ago

community 1.8.2

brian-gates commented 11 years ago

Are you sure there's two issues? I think my only issue was due to streaming.

brian-gates commented 11 years ago

Scratch that, I believe you're correct. Even with streaming disabled, it still doesn't seem to behave correctly.

brian-gates commented 11 years ago

Yeah I think I jumped the gun on my conclusions. Streaming seems to be irrelevant. But it's still strange to me that the response contains two objects.

{ columns: [ 'r', 's', 't' ], data: [ ... ] } { "columns" : [ "r", "s", "t" ], "data" : [ [ .. ]] }

brian-gates commented 11 years ago

I'm so sorry. I had another console output in my code. I'm just confusing the issue here.

philippkueng commented 11 years ago

ok, np. i'm fighting with npm right now, the new version should be up within the next 5 minutes.

brian-gates commented 11 years ago

Thanks man. No terrible rush here :)

philippkueng commented 11 years ago

ok, it's on npm. let me know if it fixes your problem. ...if not could you alter the unit test with your github name in it to better model your situation.

brian-gates commented 11 years ago

Thanks, I'll take a look and let you know if there's anything further :)

brian-gates commented 11 years ago

Data looks great now. Good work!

brian-gates commented 11 years ago

Again, I speak too soon. If you have multiple results, it doesn't return all of the values.

If I request columns [r, s, t] I should get a multi-dimensional array as follows:

[ 
  [r, s, t],
  [r1, s1, t1],
  ...
  [rn, sn, tn]
]

If I get some free time I'll see if I can update your unit test, but it may be a couple days.

philippkueng commented 11 years ago

thanks for the info @Zaxnyd. ...if you find time to edit the unit test that'd be great. personally i won't have time until the next weekend, but i'll have some time then to fix it.

eudaimos commented 11 years ago

Has there been any updates on this?

I'm using it from NPM and have version 0.2.20 and still having this issue.

Using the example above of columns/return set of r,s,t and a query like this:

db.cypherQuery('START r=node(1) MATCH (r)-[s]->(t) RETURN r,s.t', function (err, result) {

what I see in the results are:

{ 
  columns: ["r", "s", "t"],
  data: [
    { .., id: "1", data: { /* props defined on r */ }, ... },
    { .., id: "1", data: { /* props defined on r */ }, ... },
  ...]
}

Excluded in my representation of the data array items replaced by ellipses (...) are properties containing links for the traversal api REST addresses, all of which are /node/1

data does not include anything for s or t

philippkueng commented 11 years ago

Hi @eudaimos i haven't had the time to check on it. Will look into it on friday afternoon/evening.

philippkueng commented 11 years ago

Hi @Zaxnyd and @eudaimos,

After reading into the code again, sorry i forgot about the issue. I found out that while you're providing different return variables it's always outputting a single list.

However, this single list always returns one answer at a time, meaning if you have the return variables RETURN r, s, t the first element in data will be r1 then the second s1 and the third t1. ...Then it goes on to the next record which is from the next result set, so the fourth element is r2 again.

Now i've been thinking wether I should implement some regex magic against the cypher query to figure out how many return variables one has and what they're called and then split the resultset up into pieces would be worth the effort.

What do you guys think? Would you use it or have you already switched to some other library? Also this is definitely a 2.x feature since it'll break the current cypher query implementation.

brian-gates commented 11 years ago

I've moved on to node-neo4j.

On Friday, July 5, 2013, Philipp Küng wrote:

Hi @Zaxnyd https://github.com/Zaxnyd and @eudaimoshttps://github.com/eudaimos ,

After reading into the code again, sorry i forgot about the issue. I found out that while you're providing different return variables it's always outputting a single list.

However, this single list always returns one answer at a time, meaning if you have the return variables RETURN r, s, t the first element in data will be r1 then the second s1 and the third t1. ...Then it goes on to the next record which is from the next result set, so the fourth element is r2again.

Now i've been thinking wether I should implement some regex magic against the cypher query to figure out how many return variables one has and what they're called and then split the resultset up into pieces would be worth the effort.

What do you guys think? Would you use it or have you already switched to some other library? Also this is definitely a 2.x feature since it'll break the current cypher query implementation.

— Reply to this email directly or view it on GitHubhttps://github.com/philippkueng/node-neo4j/issues/7#issuecomment-20509621 .