当我启动spark-shell时,它会创建一个SparkSession实例。然而,我应该按以下方式创建它:
val spark = SparkSession.builder()
.config("es.nodes",elasticHost)
.config("es.port",elasticPort)
.config("es.nodes.wan.only","true")
.appName("Test")
.getOrCreate()我如何更新spark-shell中现有的spark-shell,或者如上面所示创建新的?
发布于 2018-01-06 17:50:42
可以使用SparkSession.conf.set设置配置属性,也可以使用SparkSession.newSession创建另一个SparkSession实例,然后设置属性。
set(key: String,value: String):Unit设置给定的火花运行时配置属性。 newSession():SparkSession使用隔离的配置、临时表、注册函数启动新会话,但共享底层SparkContext和缓存数据。
这两种方法的工作原理(几乎)相同,可以暂时将属性设置为新值,并同时使用两个SparkSession。
// hello property is not set
scala> spark.conf.getOption("hello")
res1: Option[String] = None
scala> spark.conf.set("hello", "world")
// hello property is set
scala> spark.conf.getOption("hello")
res3: Option[String] = Some(world)
// create a new SparkSession (so you'll have two at the same time)
val ns = spark.newSession
// hello is not set in a new session
scala> ns.conf.getOption("hello")
res4: Option[String] = None
ns.conf.set("hello", "hello in another session")
scala> ns.conf.getOption("hello")
res8: Option[String] = Some(hello in another session)
// the value of hello in the initial SparkSession remains unchanged
scala> spark.conf.getOption("hello")
res9: Option[String] = Some(world)https://stackoverflow.com/questions/48114340
复制相似问题