我不知道如何在向Apache Livy提交Spark作业时以编程方式传递SparkSession参数:
这是Test Spark工作:
class Test extends Job[Int]{
override def call(jc: JobContext): Int = {
val spark = jc.sparkSession()
// ...
}
}
这就是Spark职位提交给Livy的方式:
val client = new LivyClientBuilder()
.setURI(new URI(livyUrl))
.build()
try {
client.uploadJar(new File(testJarPath)).get()
client.submit(new Test())
} finally {
client.stop(true)
}
如何将以下配置参数传递给SparkSession?
.config("es.nodes","1localhost")
.config("es.port",9200)
.config("es.nodes.wan.only","true")
.config("es.index.auto.create","true")
答案 0 :(得分:2)
您可以通过LivyClientBuilder
轻松完成此操作:
val client = new LivyClientBuilder()
.setURI(new URI(livyUrl))
.setConf("es.nodes","1localhost")
.setConf("key", "value")
.build()
答案 1 :(得分:2)
可以使用
将配置参数设置为LivyClientBuilder
public LivyClientBuilder setConf(String key, String value)
以便您的代码以:
开头val client = new LivyClientBuilder()
.setURI(new URI(livyUrl))
.setConf("es.nodes","1localhost")
.setConf("es.port",9200)
.setConf("es.nodes.wan.only","true")
.setConf("es.index.auto.create","true")
.build()
答案 2 :(得分:0)
sort.in
无效。因为Livy将修改所有不以#include <bits/stdc++.h>
using namespace std;
int main(){
freopen("sort.in", "r", stdin);
freopen("output.out", "w", stdout);
int n, c, temp, arr[500000];
cin >> n;
c=n;
for(int i=0; i<n; i++){
cin >> arr[i];
}
while(n!=0){
for(int i=0; i<n-1; i++){
if(n)
if(arr[i]>arr[i+1]){
temp = arr[i+1];
arr[i+1] = arr[i];
arr[i] = temp;
}
}
n=n-1;
}
for(int i=0; i<c; i++){
cout << arr[i] << " ";
}
return 0;
}
开头的配置。并且Spark无法读取修改后的配置。 See here
LivyClientBuilder.setConf
答案很简单:像这样,将spark.
添加到所有es配置中,
private static File writeConfToFile(RSCConf conf) throws IOException {
Properties confView = new Properties();
for (Map.Entry<String, String> e : conf) {
String key = e.getKey();
if (!key.startsWith(RSCConf.SPARK_CONF_PREFIX)) {
key = RSCConf.LIVY_SPARK_PREFIX + key;
}
confView.setProperty(key, e.getValue());
}
...
}
不知道是弹性火花是否会执行兼容性工作或火花。就是这样。
PS:我已经尝试过REST API,并且可以使用。但不能使用Programmatic API。