Skip to content

Commit

Permalink
#44 add resource
Browse files Browse the repository at this point in the history
  • Loading branch information
tanakaryo committed Sep 3, 2024
1 parent 8fa6216 commit c37e41c
Show file tree
Hide file tree
Showing 10 changed files with 125 additions and 0 deletions.
33 changes: 33 additions & 0 deletions oss/apache/spark/java/apps/app1/demo-spark/.gitignore
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/
1 change: 1 addition & 0 deletions oss/apache/spark/java/apps/app1/demo-spark/exec.sh
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
47 changes: 47 additions & 0 deletions oss/apache/spark/java/apps/app1/demo-spark/pom.xml
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>
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");
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
spring.application.name=demo-spark
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 not shown.
Binary file not shown.
Empty file.
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)

0 comments on commit c37e41c

Please sign in to comment.