py4j / py4j

Py4J enables Python programs to dynamically access arbitrary Java objects

Home Page:https://www.py4j.org

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Failed to use a custom method, reporting an error that method does not exist in the JVM

weichi-ys opened this issue · comments

about information:
py4j version:0.10.9
python version:3.8

error information:
py4j.protocol.Py4JError: org.apache.kyuubi.engine.spark.SparkSQLEngine.getSparkSession does not exist in the JVM

@weichi-ys it should work I believe. Do you have a reproducer?

Looks like you're trying to access SparkSQLEngine companion object (https://github.com/apache/kyuubi/blob/8e8d8be8d2bd6b00570143602367573d56fb7825/externals/kyuubi-spark-sql-engine/src/main/scala/org/apache/kyuubi/engine/spark/SparkSQLEngine.scala#L152).

Scala creates a different class for JVM to use in this case. You should be able to access it via:

getattr(getattr(jvm.org.apache.kyuubi.engine.spark, "SparkSQLEngine$"), "MODULE$").getSparkSession()

I tried this method you said, but there is an error:
截屏2023-02-07 20 36 51

My solution comes from:#364