Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Sign in
Toggle navigation
W
WordCount - Map Reduce
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
mohamadbashar.disoki
WordCount - Map Reduce
Commits
31c44a73
You need to sign in or sign up before continuing.
Commit
31c44a73
authored
Apr 29, 2024
by
Mohamad Bashar Desoki
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Word Count Map Reduce
parents
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
94 additions
and
0 deletions
+94
-0
pom.xml
pom.xml
+31
-0
WordCount.java
src/main/java/org/example/WordCount.java
+63
-0
No files found.
pom.xml
0 → 100644
View file @
31c44a73
<?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 http://maven.apache.org/xsd/maven-4.0.0.xsd"
>
<modelVersion>
4.0.0
</modelVersion>
<groupId>
org.example
</groupId>
<artifactId>
MapReduce
</artifactId>
<version>
1.0-SNAPSHOT
</version>
<properties>
<maven.compiler.source>
1.8
</maven.compiler.source>
<maven.compiler.target>
1.8
</maven.compiler.target>
<project.build.sourceEncoding>
UTF-8
</project.build.sourceEncoding>
</properties>
<dependencies>
<dependency>
<groupId>
org.apache.hadoop
</groupId>
<artifactId>
hadoop-common
</artifactId>
<version>
2.6.0
</version>
</dependency>
<dependency>
<groupId>
org.apache.hadoop
</groupId>
<artifactId>
hadoop-core
</artifactId>
<version>
1.2.1
</version>
</dependency>
</dependencies>
</project>
\ No newline at end of file
src/main/java/org/example/WordCount.java
0 → 100644
View file @
31c44a73
package
org
.
example
;
import
java.io.IOException
;
import
org.apache.hadoop.conf.Configuration
;
import
org.apache.hadoop.fs.Path
;
import
org.apache.hadoop.io.IntWritable
;
import
org.apache.hadoop.io.LongWritable
;
import
org.apache.hadoop.io.Text
;
import
org.apache.hadoop.mapreduce.Job
;
import
org.apache.hadoop.mapreduce.Mapper
;
import
org.apache.hadoop.mapreduce.Reducer
;
import
org.apache.hadoop.mapreduce.lib.input.FileInputFormat
;
import
org.apache.hadoop.mapreduce.lib.output.FileOutputFormat
;
import
org.apache.hadoop.util.GenericOptionsParser
;
public
class
WordCount
{
public
static
void
main
(
String
[]
args
)
throws
Exception
{
Configuration
c
=
new
Configuration
();
String
[]
files
=
new
GenericOptionsParser
(
c
,
args
).
getRemainingArgs
();
Path
input
=
new
Path
(
files
[
0
]);
Path
output
=
new
Path
(
files
[
1
]);
Job
j
=
new
Job
(
c
,
"wordcount"
);
j
.
setJarByClass
(
WordCount
.
class
);
j
.
setMapperClass
(
MapForWordCount
.
class
);
j
.
setReducerClass
(
ReduceForWordCount
.
class
);
j
.
setOutputKeyClass
(
Text
.
class
);
j
.
setOutputValueClass
(
IntWritable
.
class
);
FileInputFormat
.
addInputPath
(
j
,
input
);
FileOutputFormat
.
setOutputPath
(
j
,
output
);
System
.
exit
(
j
.
waitForCompletion
(
true
)?
0
:
1
);
}
public
static
class
MapForWordCount
extends
Mapper
<
LongWritable
,
Text
,
Text
,
IntWritable
>{
public
void
map
(
LongWritable
key
,
Text
value
,
Context
con
)
throws
IOException
,
InterruptedException
{
String
line
=
value
.
toString
();
String
[]
words
=
line
.
split
(
" "
);
for
(
String
word:
words
)
{
Text
outputKey
=
new
Text
(
word
.
toUpperCase
().
trim
());
IntWritable
outputValue
=
new
IntWritable
(
1
);
con
.
write
(
outputKey
,
outputValue
);
}
}
}
public
static
class
ReduceForWordCount
extends
Reducer
<
Text
,
IntWritable
,
Text
,
IntWritable
>
{
public
void
reduce
(
Text
word
,
Iterable
<
IntWritable
>
values
,
Context
con
)
throws
IOException
,
InterruptedException
{
int
sum
=
0
;
for
(
IntWritable
value
:
values
)
{
sum
+=
value
.
get
();
}
con
.
write
(
word
,
new
IntWritable
(
sum
));
}
}
}
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment