This is the snippet:
from pyspark import SparkContext
from pyspark.sql.session import SparkSession
sc = SparkContext()
spark = SparkSession(sc)
d = spark.read.format("csv").option("header", True).option("inferSchema", True).load('file.csv')
d.show()
After this runs into the error:
An error occurred while calling o163.showString. Trace:
py4j.Py4JException: Method showString([class java.lang.Integer, class java.lang.Integer, class java.lang.Boolean]) does not exist
All the other methods work well. Tried researching alot but in vain. Any lead will be highly appreciated
On spark-shell console, enter the variable name and see the data type. As an alternative, you can tab twice after variable named. and it will show necessary function which could be applied. Example of a DataFrame object.
This is an indicator of a Spark version mismatch. Before Spark 2.3
show
method took only two arguments:since 2.3 it takes three arguments:
In your case Python client seems to invoke the latter one, while the JVM backend uses the older version.
Since
SparkContext
initialization undergone significant changes in 2.4, which would cause failure onSparkContext.__init__
, you're likely using:You can confirm that by checking versions directly from your session, Python:
vs. JVM:
Problems like this, are usually a result of misconfigured
PYTHONPATH
(either directly, or by usingpip
installedPySpark
on top per-existing Spark binaries) orSPARK_HOME
.