I am using spark 2.2.0. Below is the java code snippet which I am using as a job on spark:
SparkSession spark = SparkSession.builder()
.appName("MySQL Connection")
.master("spark://ip:7077")
.config("spark.jars", "/path/mysql.jar")
.getOrCreate();
Dataset dataset = spark.read().format("jdbc")
.option("url", "jdbc:mysql://ip:3306/mysql")
.option("user", "superadmin")
.option("password", "****")
.option("dbtable", "account")
.load();
The above code works perfectly but the problem is that if I need to submit 2 jars then I dont know how to submit it? The config() method accepts only one parameter in key('spark.jars') and one in value(path to jar). I know how to send multiple jars if used SparkConfig().setJars() but not of my use since I need to use SparkSession.
Can somebody help?
As explained in spark submit add multiple jars in classpath and Passing additional jars to Spark via spark-submit you should use comma separated list:
SparkSession spark = SparkSession.builder()
.appName("MySQL Connection")
.master("spark://ip:7077")
.config("spark.jars", "/path/mysql.jar,/path/to/another.jar")
.getOrCreate();
I know how to send multiple jars if used SparkConfig().setJars() but not of my use since I need to use SparkSession.
SparkConf
is still applicable for SparkSession
:
SparkConf conf;
...
SparkSession.builder().config(conf).getOrCreate();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With