我们可以 运行 在 Apache-Spark 中编写 scala 代码的所有方法是什么?
What are All the ways we can run a scala code in Apache-Spark?
我知道 运行 Apache-Spark 中的 scala 代码有两种方法:
1- Using spark-shell
2- Making a jar file from our project and Use spark-submit to run it
有没有其他方法可以 运行 Apache-Spark 中的 scala 代码?例如,我可以直接在 Apache-Spark 中 运行 scala 对象(例如:object.scala)吗?
谢谢
1。使用火花-shell
2。从我们的项目制作一个 jar 文件并使用 spark-submit 到 运行 it
3。 运行 以编程方式启动作业
String sourcePath = "hdfs://hdfs-server:54310/input/*";
SparkConf conf = new SparkConf().setAppName("TestLineCount");
conf.setJars(new String[] { App.class.getProtectionDomain()
.getCodeSource().getLocation().getPath() });
conf.setMaster("spark://spark-server:7077");
conf.set("spark.driver.allowMultipleContexts", "true");
JavaSparkContext sc = new JavaSparkContext(conf);
JavaRDD<String> log = sc.textFile(sourcePath);
JavaRDD<String> lines = log.filter(x -> {
return true;
});
System.out.println(lines.count());
Scala 版本:
import org.apache.log4j.Logger
import org.apache.log4j.Level
import org.apache.spark.{SparkConf, SparkContext}
object SimpleApp {
def main(args: Array[String]) {
Logger.getLogger("org").setLevel(Level.OFF)
Logger.getLogger("okka").setLevel(Level.OFF)
val logFile = "/tmp/logs.txt"
val conf = new SparkConf()
.setAppName("Simple Application")
.setMaster("local")
val sc = new SparkContext(conf)
val logData = sc.textFile(logFile, 2).cache
println("line count: " + logData.count())
}
}
有关详细信息,请参阅 this blog post。
我知道 运行 Apache-Spark 中的 scala 代码有两种方法:
1- Using spark-shell
2- Making a jar file from our project and Use spark-submit to run it
有没有其他方法可以 运行 Apache-Spark 中的 scala 代码?例如,我可以直接在 Apache-Spark 中 运行 scala 对象(例如:object.scala)吗?
谢谢
1。使用火花-shell
2。从我们的项目制作一个 jar 文件并使用 spark-submit 到 运行 it
3。 运行 以编程方式启动作业
String sourcePath = "hdfs://hdfs-server:54310/input/*";
SparkConf conf = new SparkConf().setAppName("TestLineCount");
conf.setJars(new String[] { App.class.getProtectionDomain()
.getCodeSource().getLocation().getPath() });
conf.setMaster("spark://spark-server:7077");
conf.set("spark.driver.allowMultipleContexts", "true");
JavaSparkContext sc = new JavaSparkContext(conf);
JavaRDD<String> log = sc.textFile(sourcePath);
JavaRDD<String> lines = log.filter(x -> {
return true;
});
System.out.println(lines.count());
Scala 版本:
import org.apache.log4j.Logger
import org.apache.log4j.Level
import org.apache.spark.{SparkConf, SparkContext}
object SimpleApp {
def main(args: Array[String]) {
Logger.getLogger("org").setLevel(Level.OFF)
Logger.getLogger("okka").setLevel(Level.OFF)
val logFile = "/tmp/logs.txt"
val conf = new SparkConf()
.setAppName("Simple Application")
.setMaster("local")
val sc = new SparkContext(conf)
val logData = sc.textFile(logFile, 2).cache
println("line count: " + logData.count())
}
}
有关详细信息,请参阅 this blog post。