Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Could not initialize class org.opencypher. morpheus.impl.MorpheusFunctions #948

Open
lakshmanok opened this issue Jun 20, 2020 · 3 comments

Comments

@lakshmanok
Copy link

The following code, based on https://github.com/opencypher/morpheus/blob/0.4.2/morpheus-examples/src/main/scala/org/opencypher/morpheus/examples/CypherSQLRoundtripExample.scala :

val result = graph.cypher("""
  |MATCH
  | (t1:Trip)-[:CONTAINS]-(s1:Stop)
  |RETURN t1.id AS trip_id
""".stripMargin)
result.records.asMorpheus.df.toDF("trip_id").createOrReplaceTempView("results")

gives me this error:
error: value asMorpheus is not a member of result.Records

@lakshmanok
Copy link
Author

lakshmanok commented Jun 21, 2020

Looking at this further, it seems to be a problem with some dependency not being loaded. I'm running the program from the Spark Scala shell as folllows:

spark-shell --packages=org.opencypher:morpheus-spark-cypher:0.4.2

The output indicates that Morpheus is getting installed and I can use classes like MorpheusNodeTable without any problem.

However, doing "result.records" throws this initialization error:

java.lang.NoClassDefFoundError: Could not initialize class org.opencypher.
morpheus.impl.MorpheusFunctions$
  at org.opencypher.morpheus.impl.SparkSQLExprMapper$RichExpression.nullSa
feConversion(SparkSQLExprMapper.scala:66)
  at org.opencypher.morpheus.impl.SparkSQLExprMapper$RichExpression.asSpar
kSQLExpr(SparkSQLExprMapper.scala:97)
  at org.opencypher.morpheus.impl.table.SparkTable$DataFrameTable.$anonfun
$withColumns$2(SparkTable.scala:85)
  at scala.collection.LinearSeqOptimized.foldLeft(LinearSeqOptimized.scala
:126)
  at scala.collection.LinearSeqOptimized.foldLeft$(LinearSeqOptimized.scal
a:122)
  at scala.collection.immutable.List.foldLeft(List.scala:89)
  at org.opencypher.morpheus.impl.table.SparkTable$DataFrameTable.withColu
mns(SparkTable.scala:84)
  at org.opencypher.morpheus.impl.table.SparkTable$DataFrameTable.withColu
mns(SparkTable.scala:53)
  at org.opencypher.okapi.relational.impl.operators.AddInto._table$lzycomp
ute(RelationalOperator.scala:262)
  at org.opencypher.okapi.relational.impl.operators.AddInto._table(Relatio
nalOperator.scala:260)
...

I am able to do
import org.opencypher.morpheus.impl.MorpheusFunctions
so the problem is likely with some static initialization that this does, and is not captured in the Maven package ...

@lakshmanok lakshmanok changed the title Getting error: asMorpheus is not a member of result.Records Missing dependency in morpheus-spark-cypher:0.4.2 Jun 21, 2020
@MarcianoAvihay
Copy link

Hi ... i suggest not using the maven package, and instead using the FatJar latest release from this repository / building this repo ( i initially started with the fat jar and had no issues , and later switched to building myself - for adding spark 3 and solving some issues / bugs iv'e encountered)

@lakshmanok lakshmanok changed the title Missing dependency in morpheus-spark-cypher:0.4.2 Could not initialize class org.opencypher. morpheus.impl.MorpheusFunctions Jun 21, 2020
@lakshmanok
Copy link
Author

lakshmanok commented Jun 21, 2020

Okay, found the problem. The problem is with line 53 of the MorpheusFunctions initalizer:

https://github.com/opencypher/morpheus/blob/master/morpheus-spark-cypher/src/main/scala/org/opencypher/morpheus/impl/MorpheusFunctions.scala#L53

Start the shell with

spark-shell --packages=org.opencypher:morpheus-spark-cypher:0.4.2 --conf spark.sql.legacy.allowUntypedScalaUDF=True

to workaround this problem.

Another way to set this flag is to do:

spark.conf.set("spark.sql.legacy.allowUntypedScalaUDF", true)

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

No branches or pull requests

2 participants