Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to submit multiple jars to workers through sparkSession?

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?

like image 489
ABC Avatar asked Jan 03 '23 12:01

ABC


1 Answers

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();
like image 180
2 revs Avatar answered Jan 06 '23 03:01

2 revs