question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Problem in return graph query

See original GitHub issue

Hi, I’m trying to return graph in a simple query as below:

val myGraph = graph.cypher(
    s"""MATCH (n:Disease {name:"acne"})<-[r]-(m:Disease) 
    |CONSTRUCT
    |MERGE ALL n, m, r 
    |RETURN GRAPH""".stripMargin).graph

but I’m facing this error:

org.opencypher.v9_0.util.SyntaxException: Invalid input 'n': expected whitespace, comment, '=', node labels, MapLiteral, a parameter, a relationship pattern, ON, FROM GRAPH, CONSTRUCT, LOAD CSV, START, MATCH, UNWIND, MERGE, CREATE UNIQUE, CREATE, SET, DELETE, REMOVE, FOREACH, WITH, CALL, RETURN, UNION, ';' or end of input (line 3, column 11 (offset: 69))
	at org.opencypher.v9_0.parser.Base$$anonfun$parseOrThrow$1.apply(Base.scala:139)
	at org.opencypher.v9_0.parser.Base$$anonfun$parseOrThrow$1.apply(Base.scala:127)
	at scala.collection.immutable.List.map(List.scala:273)
	at org.opencypher.v9_0.parser.Base$class.parseOrThrow(Base.scala:127)
	at org.opencypher.v9_0.parser.CypherParser.parseOrThrow(CypherParser.scala:22)
	at org.opencypher.v9_0.parser.CypherParser.parse(CypherParser.scala:29)
	at org.opencypher.v9_0.frontend.phases.Parsing$.process(Parsing.scala:26)
	at org.opencypher.v9_0.frontend.phases.Parsing$.process(Parsing.scala:22)
	at org.opencypher.v9_0.frontend.phases.Phase$$anonfun$transform$1.apply(Phase.scala:35)
	at org.opencypher.v9_0.frontend.helpers.package$$anonfun$closing$1.apply(package.scala:23)
	at org.opencypher.v9_0.frontend.helpers.package$$anonfun$closing$1.apply(package.scala:23)
	at org.opencypher.v9_0.frontend.helpers.package$.using(package.scala:31)
	at org.opencypher.v9_0.frontend.helpers.package$.closing(package.scala:23)
	at org.opencypher.v9_0.frontend.phases.Phase$class.transform(Phase.scala:34)
	at org.opencypher.v9_0.frontend.phases.Parsing$.transform(Parsing.scala:22)
	at org.opencypher.v9_0.frontend.phases.PipeLine.transform(Transformer.scala:59)
	at org.opencypher.v9_0.frontend.phases.PipeLine.transform(Transformer.scala:59)
	at org.opencypher.v9_0.frontend.phases.PipeLine.transform(Transformer.scala:59)
	at org.opencypher.v9_0.frontend.phases.PipeLine.transform(Transformer.scala:59)
	at org.opencypher.v9_0.frontend.phases.PipeLine.transform(Transformer.scala:59)
	at org.opencypher.v9_0.frontend.phases.PipeLine.transform(Transformer.scala:59)
	at org.opencypher.v9_0.frontend.phases.PipeLine.transform(Transformer.scala:59)
	at org.opencypher.v9_0.frontend.phases.PipeLine.transform(Transformer.scala:59)
	at org.opencypher.v9_0.frontend.phases.PipeLine.transform(Transformer.scala:59)
	at org.opencypher.v9_0.frontend.phases.PipeLine.transform(Transformer.scala:59)
	at org.opencypher.v9_0.frontend.phases.PipeLine.transform(Transformer.scala:59)
	at org.opencypher.okapi.ir.impl.parse.CypherParser$class.process(CypherParser.scala:59)
	at org.opencypher.okapi.ir.impl.parse.CypherParser$.process(CypherParser.scala:39)
	at org.opencypher.okapi.relational.api.graph.RelationalCypherSession$$anonfun$3.apply(RelationalCypherSession.scala:138)
	at org.opencypher.okapi.relational.api.graph.RelationalCypherSession$$anonfun$3.apply(RelationalCypherSession.scala:138)
	at org.opencypher.okapi.relational.api.graph.RelationalCypherSession.time(RelationalCypherSession.scala:106)
	at org.opencypher.okapi.relational.api.graph.RelationalCypherSession.cypherOnGraph(RelationalCypherSession.scala:138)
	at org.opencypher.okapi.relational.api.graph.RelationalCypherSession.cypherOnGraph(RelationalCypherSession.scala:63)
	at org.opencypher.okapi.api.graph.PropertyGraph$class.cypher(PropertyGraph.scala:104)
	at org.opencypher.okapi.relational.impl.graph.ScanGraph.cypher(ScanGraph.scala:43)
	at Main$.delayedEndpoint$Main$1(Main.scala:58)
	at Main$delayedInit$body.apply(Main.scala:20)
	at scala.Function0$class.apply$mcV$sp(Function0.scala:34)
	at scala.runtime.AbstractFunction0.apply$mcV$sp(AbstractFunction0.scala:12)
	at scala.App$$anonfun$main$1.apply(App.scala:76)
	at scala.App$$anonfun$main$1.apply(App.scala:76)
	at scala.collection.immutable.List.foreach(List.scala:381)
	at scala.collection.generic.TraversableForwarder$class.foreach(TraversableForwarder.scala:35)
	at scala.App$class.main(App.scala:76)
	at Main$.main(Main.scala:20)
	at Main.main(Main.scala)

I couldn’t find a documentation to check correctness of my query. What part of my query is wrong? Thanks

CAPS version: 0.2.0 Spark Version: 2.2 Scala Version: 2.11.8

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:14 (7 by maintainers)

github_iconTop GitHub Comments

1reaction
DarthMaxcommented, Oct 10, 2018

Yes so one problem you seem to be encountering here is that the Sparks planning time is quite long at times - this happens irregardless of the data size. You can use PrintRelationalPlan.set() before running any query to print the relational plans that are compiled from the Cypher query.

Yes, you can simply try to run graph.cache, this will cache all the dataframes that make up the graph.

We are working on a real documentation which will be published soon 😃

Best, Max

1reaction
DarthMaxcommented, Oct 10, 2018

Hej Hamed,

you seem to be using a slightly wrong syntax. CAPS currently does not use the MERGE keyword to express graph construction.

To achieve what you want you could run the following query

val myGraph = graph.cypher(
    s"""MATCH (n:Disease {name:"acne"})<-[r]-(m:Disease) 
    |CONSTRUCT
    |  CREATE (m)-[COPY OF r]->(n) 
    |RETURN GRAPH""".stripMargin).graph

The CREATE keyword takes a pattern. Every node variable used in that pattern, that is already bound, is merged into the new graph, i.e. there will be exactly one instance of that node in the resulting graph. It is currently not allowed to merge relationships (because we would have to make sure that they are merged with their respective start and end nodes). Instead you can use the COPY OF keyword to create a copy of any bound relationship (copies type and properties).

We are currently working on a more comprehensive documentation. Meanwhile you can find lots of examples describing the CAPS specific Cypher syntax and our API at the examples folder: https://github.com/opencypher/cypher-for-apache-spark/tree/master/spark-cypher-examples

Read more comments on GitHub >

github_iconTop Results From Across the Web

Troubleshoot common errors - Azure Resource Graph
Learn how to troubleshoot issues with the various SDKs while querying Azure resources with Azure Resource Graph.
Read more >
Graph query on gremlin-console returns error "Unable to ...
Attempts to run a Graph query in the gremlin console returns an error about failure to create an OLAP (analytics) traversal source.
Read more >
az graph query ingores underlying API error and returns ...
The CLI command az graph query -q $query (in resource-graph extension) ignores the underlying error returned by the REST API and returns the ......
Read more >
SOLVED* The Graph Query Returns Page CSS Instead of ...
I am using the graphql module, the graph, to query the price of different tokens from different exchanges. Instead of returning the query...
Read more >
How Do You Know If a Graph Database Solves the Problem?
Queries, such as the first one below, will end up traversing a potentially-massive graph that has a variety of different types of information ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found