Support Questions
Find answers, ask questions, and share your expertise
Alert: Please see the Cloudera blog for information on the Cloudera Response to CVE-2021-4428

[HDP-2.3.4]Write to Phoenix from Spark using Scala

Rising Star


I used below code to insert data from Spark1.5.2 to Phoenix 4.4

                "zkUrl" -> "localhost:2181/hbase-unsecure",
                "table" -> "TEST")).save(); 

Spark job run parameters

spark-shell  --properties-file  /TestDivya/Spark/ --jars /usr/hdp/,/usr/hdp/  --driver-class-path /usr/hdp/,/usr/hdp/ --conf "spark.executor.extraClassPath=/usr/hdp/" --conf "spark.executor.extraClassPath=/usr/hdp/" --packages com.databricks:spark-csv_2.10:1.4.0  --master yarn-client -i /TestDivya/Spark/WriteToPheonix.scala

I am getting below error when I am running the spark job

org.apache.spark.SparkException: Job aborted due to stage failure: Task 0 in stage 3.0 failed 4 times, most recent failure: Lost task 0.3 in stage 3.0 (TID 411, ip-xxxxx-xx-xxx.ap-southeast-1.compute.internal): java.lang.RuntimeException: java.sql.SQLException: No suitable driver found for jdbc:phoenix:localhost:2181:/hbase-unsecure;
        at org.apache.phoenix.mapreduce.PhoenixOutputFormat.getRecordWriter(
        at org.apache.spark.rdd.PairRDDFunctions$anonfun$saveAsNewAPIHadoopDataset$1$anonfun$12.apply(PairRDDFunctions.scala:1030)
        at org.apache.spark.rdd.PairRDDFunctions$anonfun$saveAsNewAPIHadoopDataset$1$anonfun$12.apply(PairRDDFunctions.scala:1014)
        at org.apache.spark.scheduler.ResultTask.runTask(ResultTask.scala:66)
        at org.apache.spark.executor.Executor$
        at java.util.concurrent.ThreadPoolExecutor.runWorker(
        at java.util.concurrent.ThreadPoolExecutor$

Has any body face this issue ? Would really appreciate the help. Thanks


@Divya Gehlot - It's much easier to build a working uberjar than to fight class collisions that happen when using --jars argument for spark-submit.

See HiveToPhoenix for an example Scala Spark job with pom file for packaging into a single uber jar for spark-submit.