how to use graphframes inside SPARK on HDInsight cluster - apache-spark

I have setup an SPARK cluster on HDInsight and was am trying to use GraphFrames using this tutorial.
I have already used the custom scripts during the cluster creation to enable the GraphX on the spark cluster as described here.
When I am running the notepad,
import org.apache.spark.sql._
import org.apache.spark.sql.functions._
import org.graphframes._
i get the following error
<console>:45: error: object graphframes is not a member of package org
import org.graphframes._
^
I tried to install the graphframes from the spark terminal via Jupyter using the following command:
$SPARK_HOME/bin/spark-shell --packages graphframes:graphframes:0.1.0-spark1.5
but Still I am unable to get it working. I am new to Spark and HDInsight so can someone please point out what else I need to install on this cluster to get this working.

Today, this works in spark-shell, but doesn't work in jupyter notebook. So when you run this:
$SPARK_HOME/bin/spark-shell --packages graphframes:graphframes:0.1.0-spark1.5
It works (at least on spark 1.6 cluster version) in the context of this spark-shell session.
But in jupyter there is currently no way to load packages. This feature is going to be added soon to jupyter notebooks in the clusters. In the meantime you can use spark-shell, or spark-submit, etc.

Once you upload or import graphframes libraries from Maven repository, you need to restart your cluster so as to attach the library.
So it works for me.

Related

using spark streaming from pyspark 2.4.4

I have a spark 2.4.4 version set up in a k8s container. I am trying to write a simple hello world for using spark streams like this:
from pyspark import SparkContext
from pyspark.sql import SparkSession
from pyspark.streaming import StreamingContext
from pyspark.streaming.kafka import KafkaUtils
spark = SparkSession.builder.appName("pyspark-kafka").getOrCreate()
sc.setLogLevel("WARN")
ssc = StreamingContext(sc, 60)
kafkaStream = KafkaUtils.createDirectStream(ssc, ['users-update'], {"metadata.broker.list":'pubsub-0.pubsub:9092,pubsub-1.pubsub:9092,pubsub-2.pubsub:9092'})
Note that pubsub-x.pubsub are kafka brokers that are visible to my container. (And a simple python program that directly uses the kafka-python client with the brokers and topic in my last line of pyspark code works just fine.)
I get this error message:
________________________________________________________________________________________________
Spark Streaming's Kafka libraries not found in class path. Try one of the following.
1. Include the Kafka library and its dependencies with in the
spark-submit command as
$ bin/spark-submit --packages org.apache.spark:spark-streaming-kafka-0-8:2.4.4 ...
2. Download the JAR of the artifact from Maven Central http://search.maven.org/,
Group Id = org.apache.spark, Artifact Id = spark-streaming-kafka-0-8-assembly, Version = 2.4.4.
Then, include the jar in the spark-submit command as
$ bin/spark-submit --jars <spark-streaming-kafka-0-8-assembly.jar> ...
________________________________________________________________________________________________
There are no version 2.4.4 kafka libraries anywhere on maven. https://search.maven.org/search?q=spark%20kafka shows that the last posted jars are with version 2.10 or 2.11.
I do have a spark-streaming_2.12-2.4.4.jar jar in my pyspark installation but it doesn't seem to have the right kafka classes.
Thanks for any pointers!
--Sridhar
Spark v2.4.4 is pre-built with scala v2.11. From spark download page:
Note that, Spark is pre-built with Scala 2.11 except version 2.4.2, which is pre-built with Scala 2.12.
So, basically 2.10 and 2.11 are the scala version that spark is built with and you should download the spark-streaming-kafka jar which is built with the same version of scala in your case 2.11.
I have checked in the jars folder in spark 2.4.4 and spark-streaming_2.11-2.4.4.jar jar is present there. So you should remove spark-streaming_2.12-2.4.4.jar if you have added this to the classpath externally or else you will get version mismatch.
You can download the spark-streaming-kafka-0-8-assembly.jar from here
And I think you also need to add kafka-clients jar from here as well.
I do have a spark-streaming_2.12-2.4.4.jar jar in my pyspark installation but it doesn't seem to have the right kafka classes.
That's the base Streaming packages for Spark alone. Spark does not come with Kafka classes
Spark Streaming is deprecated in favor of Spark Structured Streaming
You want this package for Spark with Scala 2.12
'org.apache.spark:spark-sql-kafka-0-10_2.12:2.4.4'
And you'd start like this including options for bootstrap servers
df = spark.readStream().format("kafka")

Jar conflicts between apache spark and hadoop

I try to setup and run a Spark cluster running on top of YARN and using HDFS.
I first set up Hadoop for HDFS using hadoop-3.1.0.
Then I configured YARN and started both.
I was able to upload data to the HDFS and yarn also seems to work fine.
Then I installed spark-2.3.0-bin-without-hadoop on my master only and tried to submit an application.
Since it is spark without Hadoop I had to modify spark-env.sh, adding the following line like mentioned in the documentation:
export SPARK_DIST_CLASSPATH=$(/usr/local/hadoop/bin/hadoop classpath)
Using only this line I got the following exception:
Error: Could not find or load main class org.apache.spark.deploy.yarn.ApplicationMaster
Which I guess means that he does not find the Spark-libraries. So I added the spark jars to the classpath:
export SPARK_DIST_CLASSPATH=$(/usr/local/hadoop/bin/hadoop classpath):/usr/local/spark/jars/*
But now I get the following Exception:
com.fasterxml.jackson.databind.JsonMappingException: Incompatible Jackson version: 2.7.8
As it turns out, Hadoop 3.1.0 provides Jackson 2.7.8 while Spark 2.3.0 provides Jackson 2.6.7. As I see it, both are now in the classpath resulting in a conflict.
Since it seems I really need both the Hadoop and Spark libraries to submit anything, I do not know how to get around that problem.
How is Hadoop-3.0.0 's compatibility with older versions of Hive, Pig, Sqoop and Spark
there was answer from #JacekLaskowski that spark is not supported on hadoop 3. As far as I know, nothing changed for last 6 month in that area.

(Zeppelin + Livy) SparkUI.appUIAddress(), something must be wrong

I'm trying to configure livy with Zeppelin following this docs:
https://zeppelin.apache.org/docs/0.7.3/interpreter/livy.html
However when I run:
%livy.spark
sc.version
I got the following error:
java.lang.RuntimeException: No result can be extracted from 'java.lang.NoSuchMethodException: org.apache.spark.ui.SparkUI.appUIAddress()', something must be wrong
I use Zeppelin 0.7.3, Spark 2.2.1, and Livy 0.4.0.
Spark running on YARN (hadoop 2.9.0). This is vanilla install, I don't use distribution like cloudera/HDP. All these software runs on one server.
I can run example org.apache.spark.examples.SparkPi in spark-shell with --master yarn without any problem. So I confirm that spark is running well on YARN.
Any help would be appreciated.
Thanks,
yusata.
This problem results from a method depreciation in spark 2.2.The appUiAddress no longer exist in spark 2.2.
As you can see in this PR https://github.com/apache/zeppelin/pull/2231.
This issue is already solved.
Somehow you still encounter the problem. I think either downgrade Spark or use a newer version of Zeppelin could solve the problem.

how to list spark-packages added to the spark context?

Is it possible to list what spark packages have been added to the spark session?
The class org.apache.spark.deploySparkSubmitArguments has a variable for the packages:
var packages: String = null
Assuming this is a list of the spark packages, is this available via SparkContext or somewhere else?
I use the following method to retrieve that information: spark.sparkContext.listJars
For example:
$ spark-shell --packages elsevierlabs-os:spark-xml-utils:1.4.0
scala> spark.sparkContext.listJars.foreach(println)
spark://192.168.0.255:51167/jars/elsevierlabs-os_spark-xml-utils-1.4.0.jar
spark://192.168.0.255:51167/jars/commons-io_commons-io-2.4.jar
spark://192.168.0.255:51167/jars/commons-logging_commons-logging-1.2.jar
spark://192.168.0.255:51167/jars/org.apache.commons_commons-lang3-3.4.jar
spark://192.168.0.255:51167/jars/net.sf.saxon_Saxon-HE-9.6.0-7.jar
In this case, I loaded the spark-xml-utils package, and the other jars were loaded as dependencies.

Will zeppelin 0.6.0 work with Spark 1.4.1?

I have installed zeppelin 0.6.0 on my cluster which has spark 1.4.1 (HDP 2.3). As per the release notes I see that it supports spark 1.6 but not sure if it is backward compatible.
When I try to run sc.version in the notebook, I can see that spark job is submitted in yarn but it is failing right away with the following error in application log Error: Could not find or load main class org.apache.spark.deploy.yarn.ExecutorLauncher
My SPARK_HOME path is correct. So zeroing on the incompatibility issue
export MASTER=yarn-client
export SPARK_YARN_JAR=/usr/hdp/current/spark-client/lib/spark-assembly-1.4.1.2.3.2.0-2950-hadoop2.7.1.2.3.2.0-2950.jar
export SPARK_HOME=/usr/hdp/current/spark-client
Finally found solution for this. Zeppelin 0.6 works with Spark 1.4.1. This was happening due to interpreter. The logs zeppelin-zeppelin-servername.log and .out files were helpful to resolve this. I had added highcharts artifact into the spark interpreter and it was not able to find that jar file. After providing correct path, I was able to run highcharts and resolve this issue as well.

Resources