neo4j-rstats / neo4r

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

`call_neo4j` doesn't execute a query that contains comments #67

Open SimonGoring opened 4 years ago

SimonGoring commented 4 years ago

I ran into this issue when I was running a fairly long query. The issue seems to be a result of clean_query() collapsing the code onto a single line. As a result, it seems like something like this:

MATCH (n:OBJECT) WHERE EXISTS(n.element)
// Just doing this for no reason
RETURN n

Which should be valid, fails, because the query turns into:

MATCH (n:OBJECT) WHERE EXISTS(n.element) // Just doing this for no reason RETURN n

Maybe comments need to be stripped?

SimonGoring commented 4 years ago

It's interesting. I'm looking at clean_query() and it looks like that's the intent of the first `gsub() command:

clean_query <- function(query) {
  res <- gsub("^\\/\\/.+$", "\n", query, perl = TRUE)
  res <- gsub("\n", " ", res)
  res <- gsub("\"", "'", res)
  res
}

I think that the fix is to change the first gsub() to: gsub("//.*", "\n", query, perl = TRUE) because it's looking for the beginning, not of the line, but of the entire string. . .