
パラメータ | 説明 |
sparkプログラムのzipパッケージ | ユーザーは作成したsparkプログラムのコードファイルを直接アップロードします。jarにパッケージ化した後、すべてのカスタム依存関係を1つのzipファイルにパッケージ化してください。ディレクトリをパッケージ化せず、ファイル自体を直接パッケージ化してください。 |
実行パラメータ | sparkプログラムの実行パラメータです。ユーザーがspark-submitを記述する必要はなく、送信ユーザーを指定する必要もなく、送信キューを指定する必要もなく、送信モードを指定する必要もありません(デフォルトはyarn)。パラメータ形式は、--class mainClass run.jar argsまたはwordcount.py input outputのようになります。 |
アプリケーションパラメータ | sparkのアプリケーションパラメータです。 |
# mavenプロジェクトを生成します。ideで操作することもできます。mvn archetype:generate -DgroupId=com.example -DartifactId=my-spark -DarchetypeArtifactId=maven-archetype-quickstart

# pom.xmlでspark依存関係を導入します。<dependencies><dependency><groupId>org.apache.spark</groupId><artifactId>spark-core_2.11</artifactId><version>2.4.7</version><scope>provided</scope></dependency></dependencies>
package com.example;import java.util.Arrays;import org.apache.spark.SparkConf;import org.apache.spark.api.java.JavaPairRDD;import org.apache.spark.api.java.JavaRDD;import org.apache.spark.api.java.JavaSparkContext;import scala.Tuple2;public class WordCount {public static void main(String[] args) {// create SparkConf objectSparkConf conf = new SparkConf().setAppName("WordCount");// create JavaSparkContext objectJavaSparkContext sc = new JavaSparkContext(conf);// read input file to RDDJavaRDD<String> lines = sc.textFile(args[0]);// split each line into wordsJavaRDD<String> words = lines.flatMap(line -> Arrays.asList(line.split(" ")).iterator());// count the occurrence of each wordJavaPairRDD<String, Integer> wordCounts = words.mapToPair(word -> new Tuple2<>(word, 1)).reduceByKey((x, y) -> x + y);// save the word counts to output filewordCounts.saveAsTextFile(args[1]);}}
<build><plugins><plugin><groupId>org.apache.maven.plugins</groupId><artifactId>maven-compiler-plugin</artifactId><configuration><source>1.8</source><target>1.8</target><encoding>utf-8</encoding></configuration></plugin><plugin><artifactId>maven-assembly-plugin</artifactId><configuration><descriptorRefs><descriptorRef>jar-with-dependencies</descriptorRef></descriptorRefs></configuration><executions><execution><id>make-assembly</id><phase>package</phase><goals><goal>single</goal></goals></execution></executions></plugin></plugins></build>
mvn package
zip spark-wordcount.zip my-spark-1.0-SNAPSHOT-jar-with-dependencies.jar




--class mainClass run.jar args
wordcount.py input output
--class com.example.WordCount my-spark-1.0-SNAPSHOT-jar-with-dependencies.jar cosn://wedata-demo-1314991481/wordcount.txtcosn://wedata-demo-1314991481/result/output
hello WeDatahello Sparkhello Scalahello PySparkhello Hive


フィードバック