How to create SparkSession from existing SparkContext

前端 未结 6 996
时光取名叫无心
时光取名叫无心 2020-12-30 20:47

I have a Spark application which using Spark 2.0 new API with SparkSession. I am building this application on top of the another application which is using

6条回答
  •  执念已碎
    2020-12-30 21:32

    public JavaSparkContext getSparkContext() 
    {
            SparkConf conf = new SparkConf()
                        .setAppName("appName")
                        .setMaster("local[*]");
            JavaSparkContext jsc = new JavaSparkContext(conf);
            return jsc;
    }
    
    
    public  SparkSession getSparkSession()
    {
            sparkSession= new SparkSession(getSparkContext().sc());
            return sparkSession;
    }
    
    
    you can also try using builder  
    
    public SparkSession getSparkSession()
    {
            SparkConf conf = new SparkConf()
                            .setAppName("appName")
                            .setMaster("local");
    
           SparkSession sparkSession = SparkSession
                                       .builder()
                                       .config(conf)
                                      .getOrCreate();
            return sparkSession;
    }
    

提交回复
热议问题