1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
natka813 [3]
3 years ago
13

JAVA HADOOP MAPREDUCE

Engineering
1 answer:
taurus [48]3 years ago
3 0

Answer:

Explanation:

package PackageDemo;

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));

}

}

}

You might be interested in
Fibonacci sequence has many applications in Computer Science. Write a program to generate Fibonacci numbers as many as desired.
VikaD [51]

Answer:

The Python Code for Fibonacci Sequence is :

# Function for nth Fibonacci number  

def Fibonacci(n):  

if n<0:  

 print("Incorrect input")  

# First Fibonacci number is 0  

elif n==0:  

 return 0

# Second Fibonacci number is 1  

elif n==1:  

 return 1

else:  

 return Fibonacci(n-1)+Fibonacci(n-2)  

# Driver Program  

print(Fibonacci(9))  

Explanation:

The Fibonacci numbers are the numbers in the following integer sequence.

0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, ……..

In mathematical terms, the sequence Fn of Fibonacci numbers is defined by the recurrence relation

Fn = Fn-1 + Fn-2

with seed values

F0 = 0 and F1 = 1.

8 0
3 years ago
Read 2 more answers
According to the video, what are examples of systems that Stationary Engineers oversee? Check all that apply. electrical systems
garik1379 [7]

Answer:

electrial systems

fire systems

heating systems

air systems

Explanation:

3 0
3 years ago
Read 2 more answers
Should aircraft wings have infinite stiffness?
Colt1911 [192]

Answer:

No, they need to be somewhat flexible so that forces such as turbulance don't shear the wing off.

3 0
3 years ago
Read 2 more answers
C++A palindrome is a string such as "madam", "radar", "Dad", and "I", that reads the same forwards and backwards. The empty stri
jeka57 [31]

Answer:

See explaination

Explanation:

#include <iostream>

#include<string.h>

using namespace std;

bool isPalindrome(string str, int lower, int upper){

if(str.length() == 0 || lower>=upper){

return true;

}

else{

if(str.at(lower) == str.at(upper)){

return isPalindrome(str,lower+1,upper-1);

}

else{

return false;

}

}

}

int main(){

string input;

cout<<"Enter string: ";

cin>>input;

if(isPalindrome(input,0,input.length()-1)){

cout<<input<<" is a palindrome"<<endl;

}

else{

cout<<input<<" is NOT a palindrome"<<endl;

}

return 0;

}

5 0
3 years ago
Whats the best used for cable -stayed bridge
nalin [4]

Answer:

a cable -stayed bridge has, one or more towers,from which cable support the bridge deck.

7 0
3 years ago
Other questions:
  • Why is it reasonable to say that no system is 100% efficient?​
    6·1 answer
  • Which of the following is not one of the systems required to ensure the safe and correct operation of an engine?
    5·1 answer
  • The forming section of a plastics plant puts out a continuous sheet of plastic that is 1.2 m wide and 2 mm thick at a rate of 15
    5·1 answer
  • A BOD test is to be run on a sample of wastewater that has a five-day BOD of 230 mg/L. If the initial DO of a mix of distilled w
    15·1 answer
  • You can safely place a jack on a floor pan to keep a vehicle steady.
    5·2 answers
  • Leland wants to work in a Production career operating heavy machinery. Which type of education or training should Leland seek?
    9·2 answers
  • Which of the following is used in the electrical field?
    7·1 answer
  • A particle moving on a straight line has acceleration a = 5-3t, and its velocity is 7 at time t = 2. If s(t) is the distance fro
    7·1 answer
  • Which of these processes uses a die and a press to form parts?
    6·1 answer
  • You have three gear wheels a, b and c connected to each other,if you turn the first gear wheel "a" clockwise what will happen to
    7·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!