Search code examples
restapiapache-sparkamazon-s3spark-csv

Spark REST API: Failed to find data source: com.databricks.spark.csv


I have a pyspark file stored on s3. I am trying to run it using spark REST API.

I am running the following command:

curl -X POST http://<ip-address>:6066/v1/submissions/create --header "Content-Type:application/json;charset=UTF-8" --data '{
"action" : "CreateSubmissionRequest",
"appArgs" : [ "testing.py"],
"appResource" : "s3n://accessKey:secretKey/<bucket-name>/testing.py",
"clientSparkVersion" : "1.6.1",
"environmentVariables" : {
    "SPARK_ENV_LOADED" : "1"
},
"mainClass" : "org.apache.spark.deploy.SparkSubmit",
"sparkProperties" : {
"spark.driver.supervise" : "false",
"spark.app.name" : "Simple App",
"spark.eventLog.enabled": "true",
"spark.submit.deployMode" : "cluster",
"spark.master" : "spark://<ip-address>:6066",
"spark.jars" : "spark-csv_2.10-1.4.0.jar",
"spark.jars.packages" : "com.databricks:spark-csv_2.10:1.4.0"
}
}'

and the testing.py file has a code snippet:

myContext = SQLContext(sc)
format = "com.databricks.spark.csv"
dataFrame1 = myContext.read.format(format).option("header", "true").option("inferSchema", "true").option("delimiter",",").load(location1).repartition(1)
dataFrame2 = myContext.read.format(format).option("header", "true").option("inferSchema", "true").option("delimiter",",").load(location2).repartition(1)
outDataFrame = dataFrame1.join(dataFrame2, dataFrame1.values == dataFrame2.valuesId)
outDataFrame.write.format(format).option("header", "true").option("nullValue","").save(outLocation)

But on this line:

dataFrame1 = myContext.read.format(format).option("header", "true").option("inferSchema", "true").option("delimiter",",").load(location1).repartition(1)

I get exception:

java.lang.ClassNotFoundException: Failed to find data source: com.databricks.spark.csv. Please find packages at http://spark-packages.org
Caused by: java.lang.ClassNotFoundException: com.databricks.spark.csv.DefaultSource

I was trying different things out and one of those things was that I logged into the ip-address machine and ran this command:

./bin/spark-shell --packages com.databricks:spark-csv_2.10:1.4.0

so that It would download the spark-csv in .ivy2/cache folder. But that didn't solve the problem. What am I doing wrong?


Solution

  • (Posted on behalf of the OP).

    I first added spark-csv_2.10-1.4.0.jar on driver and worker machines. and added

    "spark.driver.extraClassPath" : "absolute/path/to/spark-csv_2.10-1.4.0.jar",
    "spark.executor.extraClassPath" : "absolute/path/to/spark-csv_2.10-1.4.0.jar",
    

    Then I got following error:

    java.lang.NoClassDefFoundError: org/apache/commons/csv/CSVFormat
    Caused by: java.lang.ClassNotFoundException: org.apache.commons.csv.CSVFormat
    

    And then I added commons-csv-1.4.jar on both machines and added:

    "spark.driver.extraClassPath" : "/absolute/path/to/spark-csv_2.10-1.4.0.jar:/absolute/path/to/commons-csv-1.4.jar",
    "spark.executor.extraClassPath" : "/absolute/path/to/spark-csv_2.10-1.4.0.jar:/absolute/path/to/commons-csv-1.4.jar",
    

    And that solved my problem.