Skip to content
This repository has been archived by the owner on May 23, 2019. It is now read-only.

RNeo4j handling NA properties #39

Closed
JohnAbe opened this issue Sep 29, 2015 · 16 comments
Closed

RNeo4j handling NA properties #39

JohnAbe opened this issue Sep 29, 2015 · 16 comments
Assignees
Labels

Comments

@JohnAbe
Copy link

JohnAbe commented Sep 29, 2015

Hi Nicole,
Not sure if this is to be discussed in another forum.
For the label "User" with a constraint on field user_id_hash, if we try the following -

n=getOrCreateNode(g,"User",user_id_hash="john",age=NA,address="") #1
n=getOrCreateNode(g,"User",user_id_hash="john",address="") #2
Here the command #1 does not return any error, but it does not result in the creation of a node/vertex and hence n is NULL.
Whereas #2 creates a node with the two properties user_id_hash and address (value is empty for address).

1 will be encountered frequently if we are trying to create nodes/relationships from the data frame.

Is it expected to silently skip records if fields are NA? Because it would be convenient for troubleshooting if it throws an error related to NA.

Thanks for this package!,
John

@nicolewhite
Copy link
Owner

Does a User node already exist with a user_id_hash of "john" for the first example? Because getOrCreateNode uses the first key=value pair listed to find the unique node; if the node is found, then the remaining key=value pairs are ignored. getOrCreateNode is intended to be used with a single key=value pair and with a uniqueness constraint on that label and property. It is similar to the workflow that you'd use in Cypher with MERGE, where you'd MERGE on the unique property first and then SET additional properties:

MERGE (u:User {user_id_hash: "john"})
SET u.address = "123", u.age = 24

So you'd want to do it like this:

n = getOrCreateNode(g, "User", user_id_hash="john")
n = updateProp(n, age=24, address="123")

You also can't set properties to NULL or NA in Neo4j. You also wouldn't want to set it to an empty string; you just don't set it at all.

@JohnAbe
Copy link
Author

JohnAbe commented Sep 30, 2015

No there was no User node with user_id_hash already present.
There would be no issues if it skips that particular property which is NULL or NA or an empty string. As it is, it does not even create the node (equivalent to not executing the command and n becomes a NULL reference). That was what I was trying to point out. Hope it clears.

@nicolewhite
Copy link
Owner

Oh, I see. In that case I'd say this is a bug. I'll investigate soon.

@nicolewhite nicolewhite changed the title RNeo4j handling NA RNeo4j handling NA properties Sep 30, 2015
@nicolewhite nicolewhite self-assigned this Oct 2, 2015
@mjktfw
Copy link

mjktfw commented Oct 3, 2015

Hey Nicole,
the bug I've just came across concerns parsing variable types between R and neo4j, too. Didn't check the source, but maybe it's related somehow.
While querying for nodes containing empty arrays as properties, an error is raised:
Error in data[name][[1]][[1]] : subscript out of bounds

This results in an error:

cypherToList(dbNeo, 'CREATE (n:test {a:[]})')
cypherToList(dbNeo, 'MATCH (n:test {a:[]}) RETURN n')

@nicolewhite
Copy link
Owner

@JohnAbe I'm not able to reproduce your error. When I do:

neo4j = startGraph("http://localhost:7474/db/data/")
clear(neo4j, input=F)

addConstraint(neo4j, "User", "user_id_hash")

n = getOrCreateNode(neo4j, "User", user_id_hash="john", age=NA)

The node is created.

> n$user_id_hash
[1] "john"
> n$age
NULL

This is the intended behavior. Any properties set to NA or NULL are simply ignored.

@nicolewhite
Copy link
Owner

Hey @mjktfw, that seems like a separate problem. I've created #41 for it.

nicolewhite added a commit that referenced this issue Oct 5, 2015
@nicolewhite
Copy link
Owner

I'm closing this as I'm not able to reproduce the problem.

@JohnAbe
Copy link
Author

JohnAbe commented Oct 15, 2015

Hey,
Really sorry for a reply this late! I veered off this topic as my project ended.
If I try out the same code you shared, on my system, n returns NULL and
there is no Node created. Not sure why. I am using RNeo4j 1.6.0 and R
version 3.2.1

> neo4j = startGraph("http://localhost:7474/db/data/
http://localhost:7474/db/data/")

> clear(neo4j, input=F)
> addConstraint(neo4j, "User", "user_id_hash")
> n = getOrCreateNode(neo4j, "User", user_id_hash="john", age=NA)
> n
NULL

On 10 October 2015 at 06:36, Nicole White notifications@github.com wrote:

Closed #39 #39.


Reply to this email directly or view it on GitHub
#39 (comment).

John Abraham

@nicolewhite
Copy link
Owner

This is my experience with RNeo4j 1.6.0 and R 3.2.1:

> library(RNeo4j)
> neo4j = startGraph("http://localhost:7474/db/data/")
> clear(neo4j, input=F)
> addConstraint(neo4j, "User", "user_id_hash")
> n = getOrCreateNode(neo4j, "User", user_id_hash="john", age=NA)
> n
< Node > 
User

$user_id_hash
[1] "john"

What operating system are you on? And what version of Neo4j are you using?

@JohnAbe
Copy link
Author

JohnAbe commented Oct 15, 2015

Windows 7 Enterprise and Neo4j 2.2.3

On 16 October 2015 at 01:31, Nicole White notifications@github.com wrote:

This is my experience with RNeo4j 1.6.0 and R 3.2.1:

library(RNeo4j)
neo4j = startGraph("http://localhost:7474/db/data/")
clear(neo4j, input=F)
addConstraint(neo4j, "User", "user_id_hash")
n = getOrCreateNode(neo4j, "User", user_id_hash="john", age=NA)
n
< Node >
User

$user_id_hash
[1] "john"

What operating system are you on? And what version of Neo4j are you using?


Reply to this email directly or view it on GitHub
#39 (comment).

John Abraham

@nicolewhite
Copy link
Owner

I'll grab a copy of 2.2.3 and see if I can reproduce.

@JohnAbe
Copy link
Author

JohnAbe commented Oct 15, 2015

Oh please do not bother if it is a deprecated version. I did not know that
a newer version was out. Will check with 2.2.6 and update you about the
results
Thanks,

On 16 October 2015 at 02:40, Nicole White notifications@github.com wrote:

I'll grab a copy of 2.2.3 and see if I can reproduce.


Reply to this email directly or view it on GitHub
#39 (comment).

John Abraham

@nicolewhite
Copy link
Owner

It is not deprecated. I will check it out.

@nicolewhite
Copy link
Owner

I'm still not able to reproduce.

> library(RNeo4j)
> neo4j = startGraph("http://localhost:7474/db/data/")
> neo4j
< Graph > 
$version
[1] "2.2.3"

> clear(neo4j, input=F)
> addConstraint(neo4j, "User", "user_id_hash")
> n = getOrCreateNode(neo4j, "User", user_id_hash="john", age=NA)
> n
< Node > 
User

$user_id_hash
[1] "john"

@JohnAbe
Copy link
Author

JohnAbe commented Oct 15, 2015

Thanks for checking.

> neo4j = startGraph("http://localhost:7474/db/data/
http://localhost:7474/db/data/")

> clear(neo4j, input=F)
> addConstraint(neo4j, "User", "user_id_hash")
> n = getOrCreateNode(neo4j, "User", user_id_hash="john", age=NA)
> n
NULL

I tried with Neo4j 2.2.6 and it is still giving the above result. Strange
enough!

On 16 October 2015 at 03:17, Nicole White notifications@github.com wrote:

I'm still not able to reproduce.

library(RNeo4j)
neo4j = startGraph("http://localhost:7474/db/data/")
neo4j
< Graph >
$version
[1] "2.2.3"

clear(neo4j, input=F)
addConstraint(neo4j, "User", "user_id_hash")
n = getOrCreateNode(neo4j, "User", user_id_hash="john", age=NA)
n
< Node >
User

$user_id_hash
[1] "john"


Reply to this email directly or view it on GitHub
#39 (comment).

John Abraham

@nicolewhite
Copy link
Owner

Hmm. I suppose I will boot up my Windows machine. Stay tuned!

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

3 participants