-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
125 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
HELP.md | ||
target/ | ||
!.mvn/wrapper/maven-wrapper.jar | ||
!**/src/main/**/target/ | ||
!**/src/test/**/target/ | ||
|
||
### STS ### | ||
.apt_generated | ||
.classpath | ||
.factorypath | ||
.project | ||
.settings | ||
.springBeans | ||
.sts4-cache | ||
|
||
### IntelliJ IDEA ### | ||
.idea | ||
*.iws | ||
*.iml | ||
*.ipr | ||
|
||
### NetBeans ### | ||
/nbproject/private/ | ||
/nbbuild/ | ||
/dist/ | ||
/nbdist/ | ||
/.nb-gradle/ | ||
build/ | ||
!**/src/main/**/build/ | ||
!**/src/test/**/build/ | ||
|
||
### VS Code ### | ||
.vscode/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
./spark-submit --master local[3] --executor-memory 512m --class com.example.spark.WordCount ~/tools/jars/demo-spark-0.0.1-SNAPSHOT.jar |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
<modelVersion>4.0.0</modelVersion> | ||
|
||
<groupId>com.example.spark</groupId> | ||
<artifactId>demo-spark</artifactId> | ||
<version>0.0.1-SNAPSHOT</version> | ||
<name>demo-spark</name> | ||
<description>Demo project for Apache Spark</description> | ||
|
||
<properties> | ||
<java.version>22</java.version> | ||
<maven.compiler.source>1.8</maven.compiler.source> | ||
<maven.compiler.target>1.8</maven.compiler.target> | ||
</properties> | ||
|
||
|
||
<dependencies> | ||
<dependency> | ||
<groupId>org.apache.spark</groupId> | ||
<artifactId>spark-core_2.13</artifactId> | ||
<version>4.0.0-preview1</version> | ||
</dependency> | ||
</dependencies> | ||
|
||
<build> | ||
<plugins> | ||
<plugin> | ||
<groupId>org.scala-tools</groupId> | ||
<artifactId>maven-scala-plugin</artifactId> | ||
<version>2.12.1</version> | ||
<executions> | ||
<execution> | ||
<goals> | ||
<goal>compile</goal> | ||
</goals> | ||
</execution> | ||
</executions> | ||
<configuration> | ||
<scalaVersion>2.13.14</scalaVersion> | ||
</configuration> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
|
||
</project> |
26 changes: 26 additions & 0 deletions
26
oss/apache/spark/java/apps/app1/demo-spark/src/main/java/com/example/spark/WordCount.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package com.example.spark; | ||
|
||
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) { | ||
SparkConf sparkConf = new SparkConf().setAppName("spark-wordcount").setMaster("local"); | ||
JavaSparkContext sparkContext = new JavaSparkContext(sparkConf); | ||
|
||
JavaRDD<String> lines = sparkContext.textFile("/Users/user/Documents/github/software/oss/apache/spark/java/apps/app1/demo-spark/src/main/resources/data/data.txt"); | ||
JavaRDD<String> words = lines.flatMap(s -> Arrays.asList(s.split(" ")).iterator()); | ||
|
||
JavaPairRDD<String, Integer> wordsOnes = words.mapToPair(s -> new Tuple2(s, 1)); | ||
|
||
JavaPairRDD<String, Integer> wordsCounts = wordsOnes.reduceByKey((v1, v2) -> v1 + v2 ); | ||
wordsCounts.saveAsTextFile("/Users/user/Documents/github/software/oss/apache/spark/java/apps/app1/demo-spark/src/main/resources/out-data"); | ||
} | ||
} |
1 change: 1 addition & 0 deletions
1
oss/apache/spark/java/apps/app1/demo-spark/src/main/resources/application.properties
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
spring.application.name=demo-spark |
3 changes: 3 additions & 0 deletions
3
oss/apache/spark/java/apps/app1/demo-spark/src/main/resources/data/data.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
Hi, My name is anoymous informer. | ||
Nice to meet you. | ||
See you again later. |
Binary file added
BIN
+8 Bytes
oss/apache/spark/java/apps/app1/demo-spark/src/main/resources/out-data/._SUCCESS.crc
Binary file not shown.
Binary file added
BIN
+12 Bytes
oss/apache/spark/java/apps/app1/demo-spark/src/main/resources/out-data/.part-00000.crc
Binary file not shown.
Empty file.
14 changes: 14 additions & 0 deletions
14
oss/apache/spark/java/apps/app1/demo-spark/src/main/resources/out-data/part-00000
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
(later.,1) | ||
(is,1) | ||
(you,1) | ||
(anoymous,1) | ||
(name,1) | ||
(Nice,1) | ||
(meet,1) | ||
(to,1) | ||
(Hi,,1) | ||
(See,1) | ||
(you.,1) | ||
(again,1) | ||
(My,1) | ||
(informer.,1) |