Beruflich Dokumente
Kultur Dokumente
a)
Data structures in Java- Stack
DESCRIPTION:
PROGRAM:
importjava.util.*;
public class stackpro {
public static void main(String[] args) {
Stack<Integer> s=new Stack<Integer>();
Scanner sc=new Scanner(System.in);
inti;
do{
System.out.println("1:push");
System.out.println("2:pop");
System.out.println("3:peek");
System.out.println("4:search");
System.out.println("5:isEmpty");
System.out.println("Enter the choice");
i=sc.nextInt();
switch(i)
{
case 1:
System.out.println("Enter the element:");
int x=sc.nextInt();
s.push(x);
System.out.println("stack is "+s);
break;
case 2:
int y=s.pop();
System.out.println("the value popedis"+y);
break;
case 3:
int z=s.peek();
System.out.println("The peek element is"+z);
break;
case 4:
System.out.println("Enter the element to be searched");
int b=sc.nextInt();
int a=s.search(b);
if(a==-1)
System.out.println("Element is not available");
else
System.out.println("Element is available in index "+a);
break;
case 5:
System.out.println("The stack is empty: "+s.empty());
1
break;
case 6:
System.exit(0);
}
}while(i<=6);
}
}
OUTPUT:
1:push
2:pop
3:peek
4:search
5:isEmpty
Enter the choice
1
Enter the element:
10
stack is [10]
1:push
2:pop
3:peek
4:search
5:isEmpty
Enter the choice
1
Enter the element:
20
stack is [10, 20]
1:push
2:pop
3:peek
4:search
5:isEmpty
Enter the choice
1
Enter the element:
30
stack is [10, 20, 30]
1:push
2:pop
3:peek
4:search
5:isEmpty
Enter the choice
3
The peek element is30
1:push
2:pop
3:peek
4:search
5:isEmpty
Enter the choice
2
the value poped is30
1:push
2:pop
3:peek
4:search
5:isEmpty
Enter the choice
4
Enter the element to be searched
2
20
The index is 1
1:push
2:pop
3:peek
4:search
5:isEmpty
Enter the choice
5
The stack is empty: false
1:push
2:pop
3:peek
4:search
5:isEmpty
Enter the choice
6
VIVA QUESTIONS:
3
Ex.No: 1.b)
LinkedList
DESCRIPTION:
The The LinkedList class extends AbstractSequentialList and implements the List
interface. It provides a linked-list data structure.
PROGRAM:
import java.util.*;
public class LinkedListDemo {
VIVA QUESTIONS:
5
Ex.No: 1.c)
SET
DESCRIPTION:
PROGRAM:
OUTPUT:
[pratyusha, bindu, aruna]
[anuradha, praneeth, pratyusha]
[10, 18, 90, 100]
[jyothsna, vineela, anuradha, srinivas, bindu, pratyusha]
true
95
VIVA QUESTIONS:
7
Ex.No: 1.d)
Map
DESCRIPTION:
Map contains values on the basis of key i.e. key and value pair. Each key and value
pair is known as an entry. Map contains only unique keys.Map is useful if you have
to search, update or delete elements on the basis of key.
PROGRAM:
importjava.util.*;
public class map {
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
9
VIVA QUESTIONS:
10
3. Synchronized. Only Hashtable is synchronized, others are not. Therefore, "if a
thread-safe implementation is not needed, it is recommended to use HashMap in
place of Hashtable."
11
Ex.No: 1.e)
GENERIC PROGRAMMING
DESCRIPTION:
Java Generic methods and generic classes enable programmers to specify, with a
single method declaration, a set of related methods, or with a single class declaration,
a set of related types, respectively. Generics also provide compile-time type safety
that allows programmers to catch invalid types at compile time.
Example.
PROGRAM:
Class A<T>
{
T x;
void add(T x)
{
this.x=x;
}
T get()
{
return x;
}
}
public class gen
{
public static void main(String[] args) {
A<Integer> o=new A<Integer>();
o.add(2);
System.out.println(o.get());
12
A<String> o1=new A<String>();
o1.add(“neelima”);
System.out.println(o1.get());
}
}
OUTPUT:
2
Neelima
VIVA QUESTIONS:
Ans:Generics are used to create Generic Classes and Generic methods which
can work with different Types(Classes).
class MyListGeneric<T>
Java Type can be used a type for this class. If we would want to restrict the types
allowed for a Generic Type, we can use a Generic Restrictions.
13
Ex.No: 1.f)
Serialization
DESCRIPTION:
After a serialized object has been written into a file, it can be read from the file and
deserialized that is, the type information and bytes that represent the object and its
data can be used to recreate the object in memory.
PROGRAM:
Student.java:
import java.io.*;
public class Student implements Serializable
{
int no;
String name;
}
SeriEx.java:
import java.io.*;
public class SeriEx
{
Public static voidmain(String args[])throws Exception
{
Student S1=new Student();
S1.no=12;
S1.name=”CSEA”;
Objectoutputstream out=new objectoutputStream(new
14
FileOutputStream(“D:/serex.ser”));
Out.writeobject(S1);
}
}
Deser.java:
import java.io.*;
public class Deser
{
Public static void main(String[] args)throws Exception
{
Student S1=null;
FileInputStream fileIn=new FileIutputStream(“D:/serex.ser”);
ObjectInputStream in=new ObjectInputStream(fileIn);
S1=(Student)in.readobject();
System.out.println(“Deserialization student……”);
System.out.println(“Name:”+S1.name);
System.out.println(“Number:”+S1.no);
}}
OUTPUT:
12
CSEA
VIVA QUESTIONS:
15
Ex.No: 1.g)
Queue
DESCRIPTION:
PROGRAM:
import java.util.*;
class TestCollection12{
public static void main(String args[]){
PriorityQueue<String> queue=new PriorityQueue<String>();
queue.add("Amit");
queue.add("Vijay");
16
queue.add("Karan");
queue.add("Jai");
queue.add("Rahul");
System.out.println("head:"+queue.element());
System.out.println("head:"+queue.peek());
System.out.println("iterating the queue elements:");
Iterator itr=queue.iterator();
while(itr.hasNext()){
System.out.println(itr.next()); }
queue.remove();
queue.poll();
System.out.println("after removing two elements:");
Iterator<String> itr2=queue.iterator();
while(itr2.hasNext()){
System.out.println(itr2.next());
} } }
OUTPUT:
head:Amit
head:Amit
iterating the queue elements:
Amit
Jai
Karan
Vijay
Rahul
after removing two elements:
Karan
Rahul
Vijay
VIVA QUESTIONS:
17
Ex.No: 1.h)
Wrapper Classes
DESCRIPTION:
Wrapper class in java provides the mechanism to convert primitive into object and
object into primitive.
Since J2SE 5.0, autoboxing and unboxing feature converts primitive into object and
object into primitive automatically. The automatic conversion of primitive into object
is known and autoboxing and vice-versa unboxing.
PROGRAM:
OUTPUT:
20 20 20
VIVA QUESTIONS:
19
Ex.No: 2
Perform setting up and Installing Hadoop
DESCRIPTION:
Standalone Mode
20
Different Nodes will be used as Master Node / Data Node / Job Tracker / Task
Tracker
PROGRAM:
Installation of Hadoop
Java must be installed on your system before installing Hive. Let us verify java
installation using the following command:
$ java –version
If Java is already installed on your system, you get to see the following response:
If java is not installed in your system, then follow the steps given below for installing
java.
Installing Java
Step I:
Download java (JDK <latest version> - X64.tar.gz) by visiting the following link
http://www.oracle.com/technetwork/java/javase/downloads/jdk7-downloads-
1880260.html.
Then jdk-7u71-linux-x64.tar.gz will be downloaded onto your system.
Step II:
Generally you will find the downloaded java file in the Downloads folder. Verify it
and extract the jdk-7u71-linux-x64.gz file using the following commands.
$ cd Downloads/
$ ls
jdk-7u71-linux-x64.gz
$ ls
jdk1.7.0_71 jdk-7u71-linux-x64.gz
21
Step III:
To make java available to all the users, you have to move it to the location
“/usr/local/”. Open root, and type the following commands.
$ su
password:
# mv jdk1.7.0_71 /usr/local/
# exit
Step IV:
For setting up PATH and JAVA_HOME variables, add the following commands to
~/.bashrc file.
export JAVA_HOME=/usr/local/jdk1.7.0_71
export PATH=$PATH:$JAVA_HOME/bin
Now apply all the changes into the current running system.
$ source ~/.bashrc
Step V:
Now verify the installation using the command java -version from the terminal as
explained above.
Hadoop must be installed on your system before installing Hive. Let us verify the
Hadoop installation using the following command:
$ hadoop version
$ su
password:
# cd /usr/local
# wget http://apache.claz.org/hadoop/common/hadoop-2.4.1/
hadoop-2.4.1.tar.gz
# tar xzf hadoop-2.4.1.tar.gz
# mv hadoop-2.4.1/* to hadoop/
# exit
The following steps are used to install Hadoop 2.4.1 in pseudo distributed mode.
You can set Hadoop environment variables by appending the following commands to
~/.bashrc file.
export HADOOP_HOME=/usr/local/hadoop
export HADOOP_MAPRED_HOME=$HADOOP_HOME
export HADOOP_COMMON_HOME=$HADOOP_HOME
export HADOOP_HDFS_HOME=$HADOOP_HOME
export YARN_HOME=$HADOOP_HOME
export HADOOP_COMMON_LIB_NATIVE_DIR=$HADOOP_HOME/lib/native
export
PATH=$PATH:$HADOOP_HOME/sbin:$HADOOP_HOME/bin
Now apply all the changes into the current running system.
$ source ~/.bashrc
23
Step II: Hadoop Configuration
You can find all the Hadoop configuration files in the location
“$HADOOP_HOME/etc/hadoop”. You need to make suitable changes in those
configuration files according to your Hadoop infrastructure.
$ cd $HADOOP_HOME/etc/Hadoop
In order to develop Hadoop programs using java, you have to reset the java
environment variables in hadoop-env.sh file by replacing JAVA_HOME value with
the location of java in your system.
export JAVA_HOME=/usr/local/jdk1.7.0_71
Given below are the list of files that you have to edit to configure Hadoop.
core-site.xml
The core-site.xml file contains information such as the port number used for Hadoop
instance, memory allocated for the file system, memory limit for storing the data, and
the size of Read/Write buffers.
Open the core-site.xml and add the following properties in between the
<configuration> and </configuration> tags.
<configuration>
<property>
<name>fs.default.name</name>
<value>hdfs://localhost:9000</value>
</property>
</configuration>
hdfs-site.xml
The hdfs-site.xml file contains information such as the value of replication data, the
namenode path, and the datanode path of your local file systems. It means the place
where you want to store the Hadoop infra.
Open this file and add the following properties in between the <configuration>,
24
</configuration> tags in this file.
<configuration>
<property>
<name>dfs.replication</name>
<value>1</value>
</property>
<property>
<name>dfs.name.dir</name>
<value>file:///home/hadoop/hadoopinfra/hdfs/namenode </value>
</property>
<property>
<name>dfs.data.dir</name>
<value>file:///home/hadoop/hadoopinfra/hdfs/datanode </value >
</property>
</configuration>
Note: In the above file, all the property values are user-defined and you can make
changes according to your Hadoop infrastructure.
yarn-site.xml
This file is used to configure yarn into Hadoop. Open the yarn-site.xml file and add
the following properties in between the <configuration>, </configuration> tags in this
file.
<configuration>
<property>
<name>yarn.nodemanager.aux-services</name>
<value>mapreduce_shuffle</value>
</property>
</configuration>
mapred-site.xml
This file is used to specify which MapReduce framework we are using. By default,
Hadoop contains a template of yarn-site.xml. First of all, you need to copy the file
from mapred-site,xml.template to mapred-site.xml file using the following command.
$ cp mapred-site.xml.template mapred-site.xml
Open mapred-site.xml file and add the following properties in between the
<configuration>, </configuration> tags in this file.
<configuration>
<property>
<name>mapreduce.framework.name</name>
<value>yarn</value>
</property>
</configuration>
http://localhost:8088/All
Application
26
VIVA QUESTIONS
28
Ex.No: 3)
File Management Tasks in Hadoop
DESCRIPTION:
The File System (FS) shell includes various shell-like commands that directly interact
with the Hadoop Distributed File System (HDFS) as well as other file systems that
Hadoop supports, such as Local FS, HFTP FS, S3 FS, and others.The following
commands are used for interacting with HDFS.
cat
Example:
Exit Code:
chgrp
Change group association of files. The user must be the owner of files, or else a super-
user. Additional information is in the Permissions Guide.
Options
The -R option will make the change recursively through the directory structure.
chmod
29
Change the permissions of files. With -R, make the change recursively through the
directory structure. The user must be the owner of the file, or else a super-user.
Additional information is in the Permissions Guide.
Options
The -R option will make the change recursively through the directory structure.
chown
Change the owner of files. The user must be a super-user. Additional information is in
the Permissions Guide.
Options
The -R option will make the change recursively through the directory structure.
copyFromLocal
Similar to put command, except that the source is restricted to a local file reference.
Options:
copyToLocal
Similar to get command, except that the destination is restricted to a local file reference.
count
Count the number of directories, files and bytes under the paths that match the specified
file pattern. The output columns with -count are: DIR_COUNT, FILE_COUNT,
CONTENT_SIZE FILE_NAME
30
Example:
Exit Code:
cp
Copy files from source to destination. This command allows multiple sources as well in
which case the destination must be a directory.
Options:
Example:
Exit Code:
ponny@ubuntu:~$ ls
AirPassengers.csv Pictures
big.txt protobuf-2.4.1
classes protobuf-2.4.1.tar.gz
core protobuf-2.5.0
cseaa protobuf-2.5.0.tar.gz
cseblearners Public
31
data10.txt PVP College
Data1.txt R
ponny@ubuntu:~$ clear
ponny@ubuntu:~/Dps$ cd\
ponny@ubuntu:~$ cd Dps
ponny@ubuntu:~/Dps$ cd train
ponny@ubuntu:~/Dps/train$ cd\
ponny@ubuntu:~$ ls
AirPassengers.csv pa.txt~
big.txt Pictures
classes protobuf-2.4.1
core protobuf-2.4.1.tar.gz
cseaa protobuf-2.5.0
cseblearners protobuf-2.5.0.tar.gz
data10.txt Public
Data1.txt PVP College
ponny@ubuntu:~$ clear
ponny@ubuntu:~$ cd Dps
ponny@ubuntu:~/Dps$ ls
train
ponny@ubuntu:~/Dps$ cd\
ponny@ubuntu:~$ jps
4520
4662 FsShell
3660 TaskTracker
2832 NameNode
4698 Jps
32
3328 SecondaryNameNode
3412 JobTracker
3079 DataNode
Found 2 items
-rw-r--r-- 1 ponny supergroup 15 2016-08-19 10:32
/user/ponny/hadooplab
drwxr-xr-x - ponny supergroup 0 2016-08-18 15:38
/user/ponny/training
ponny@ubuntu:~$
1.create "training" file in local system and copy that file to hdfs directory using
"put" cmd
ponny@ubuntu:~$ cat >training
Hello Welcome to the world of Bigdata
3.create ece directory in Hdfs and copy training bigdata file from cse hdfs direct
to ece hdfs directory
ponny@ubuntu:~$ hadoop fs -mkdir ECE
Warning: $HADOOP_HOME is deprecated.
mv command:
4.Copy training bigdata file from ECE HDFS Desktop(local file system)
35
Warning: $HADOOP_HOME is deprecated.
Deleted hdfs://localhost:54310/user/ponny/IT
VIVA QUESTIONS:
36
Ex.No: 4)
Word Count Map Reduce program
DESCRIPTION:
PROGRAM
Driver code:
importorg.apache.hadoop.fs.Path;
importorg.apache.hadoop.io.IntWritable;
importorg.apache.hadoop.io.Text;
37
importorg.apache.hadoop.mapreduce.Job;
importorg.apache.hadoop.mapreduce.lib.input.FileInputFormat;
importorg.apache.hadoop.mapreduce.lib.output.FileOutputFormat;
publicclassWordCountDriver {
publicstaticvoid main(String[] args) throws Exception {
// Set input and output Path, note that we use the default input format
// which is TextInputFormat (each record is a line of input)
FileInputFormat.addInputPath(job, newPath(input));
FileOutputFormat.setOutputPath(job, newPath(output));
System.exit(job.waitForCompletion(true) ? 0 : 1);
}
}
Mapper Class:
import java.io.IOException;
import org.apache.hadoop.io.IntWritable;
import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Mapper;
public class WordCountMapper
extends Mapper<LongWritable, Text, Text, IntWritable>{
private static final IntWritable one = new IntWritable(1);
private Text word = new Text();
protected void map(LongWritable key, Text value, Context context)
throws IOException, InterruptedException
{
String line = value.toString();
38
String[] words = line.split(" ");
for (String w : words) {
word.set(w);
context.write(word, one);
}
}}
Reducer:
import java.io.IOException;
import java.util.Iterator;
import org.apache.hadoop.io.IntWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Reducer;
public class WordCountReducer
extends Reducer<Text, IntWritable, Text, IntWritable>{
protected void reduce(Text key, Iterable<IntWritable> values,
Context context)
throws IOException, InterruptedException {
int sum = 0;
for(IntWritable value:values)
{
sum value.get();
}
context.write(key, new IntWritable(sum));
}
}
OUT PUT:
Input File:
Welcome every1.
Welcome to Hadoop lab.
Today we are going to work on Hadoop MapReduce concept.
Output File:
MapReduce 1
Today 1
Welcome 2
are 1
concept. 1
every1 1.
going 1
Hadoop 2
lab. 1
on 1
to 2
we 1
work 1
39
VIVA QUESTIONS:
Ex.No: 5)
Matrix Multiplication using Map Reduce Approach
DESCRIPTION:
In the map function each input from the dataset is organized to produce a key value
pair such that reducer can do the entire computation of the corresponding output cell.
PROGRAM
Driver code:
importorg.apache.hadoop.fs.Path;
importorg.apache.hadoop.io.IntWritable;
importorg.apache.hadoop.io.Text;
importorg.apache.hadoop.mapreduce.Job;
importorg.apache.hadoop.mapreduce.lib.input.FileInputFormat;
importorg.apache.hadoop.mapreduce.lib.output.FileOutputFormat;
publicclassMatrix {
publicstaticvoid main(String[] args) throws Exception {
40
// Create a new job
Job job = newJob();
// Set input and output Path, note that we use the default input format
// which is TextInputFormat (each record is a line of input)
FileInputFormat.addInputPath(job, newPath(input));
FileOutputFormat.setOutputPath(job, newPath(output));
System.exit(job.waitForCompletion(true) ? 0 : 1);
}
}
Mapper Class:
Reducer:
@Override
protected void reduce
(Text key, Iterable<Text> values, Context context)
throws IOException, InterruptedException {
0,0 11878
0,1 14044
0,2 16031
0,3 5964
0,4 15874
1,0 4081
1,1 6914
1,2 8282
1,3 7479
1,4 9647
2,0 6844
2,1 9880
2,2 10636
2,3 6973
2,4 8873
3,0 10512
3,1 12037
3,2 10587
3,3 2934
3,4 5274
4,0 11182
4,1 14591
4,2 10954
4,3 1660
4,4 9981
VIVA QUESTIONS:
43
Ex.No: 6)
Mines Weather Data using Map Reduce
DESCRIPTION:
Sensors senses weather data in big text format containing station ID, year, date, time,
temperature, quality etc. from each sensor and store it in single line. Suppose
thousands of data sensors are their, then we have thousands of records with no
particular order. We require only year and maximum tempertaure of particular
quality in that year.
For example:
0029029070999991902010720004+64333+023450FM-12+
000599999V0202501N027819999999N0000001N9-00331+
99999098351ADDGF102991999999999999999999
44
0033 is temperature
Here each mapper takes input key as "byte offset of line" and value as "one weather
sensor read i.e one line". and parse each line and produce intermediate key is "year"
and intermediate value as "temperature of certain measurement qualities" for that
year.
PROGRAM
Driver code:
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.Text;
import org.apache.hadoop.mapred.FileOutputFormat;
import org.apache.hadoop.mapred.JobConf;
import org.apache.hadoop.mapred.TextOutputFormat;
import org.apache.hadoop.mapreduce.Job;
import org.apache.hadoop.mapreduce.lib.input.FileInputFormat;
Mapper Class
class MaxTemperatureMapper
extends Mapper {
@Override
int airTemperature;
46
// 87 to 92 for temperature comparision we needn't required "+ve" sign
if (line.charAt(87) == '+') {
} else {
//so make substring of one character to get temp. quality and matches //it with our
required qualities
//If it matches,then we write perticular year as key and temp. as value //to context
output
if (quality.matches("[01459]")) {
47
}
Reducer:
import java.io.IOException;
import org.apache.hadoop.io.IntWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Reducer;
VIVA QUESTIONS:
Ans:Math.min()
48
Ex.No: 7
OBJECTIVE: To Implement Install and Run Pig then write Pig Latin scripts to sort,
group, join, project, and filter your data.
DESCRIPTION:
Apache Pig is a platform for analyzing large data sets that consists of a high-level
language for expressing data analysis programs, coupled with infrastructure for
evaluating these programs. The salient property of Pig programs is that their
49
structure is amenable to substantial parallelization, which in turns enables them to
handle very large data sets.At the present time, Pig's infrastructure layer consists of
a compiler that produces sequences of Map-Reduce programs, for which large-scale
parallel implementations already exist (e.g., the Hadoop subproject). Pig's language
layer currently consists of a textual language called Pig Latin, which has the following
key properties:
Step 1
Create a directory with the name Pig in the same directory where the
installation directories of Hadoop, Java, and other software were
installed. (In our tutorial, we have created the Pig directory in the user
named Hadoop).
$ mkdir Pig
Step 2
Extract the downloaded tar files as shown below.
$ cd Downloads/
$ tar zxvf pig-0.15.0-src.tar.gz
$ tar zxvf pig-0.15.0.tar.gz
Step 3
Move the content of pig-0.15.0- src.tar.gz file to the Pig directory
created earlier as shown below.
$ mv pig-0.15.0-src.tar.gz/* /home/Hadoop/Pig/
Configure Apache Pig
After installing Apache Pig, we have to configure it. To configure, we
need to edit two files − bashrc and pig.properties.
.bashrc file
PigLatin Script.
50
DUMP B;
(John)
(Mary)
(Bill)
(Joe)
customers.txt
1,Ramesh,32,Ahmedabad,2000.00
2,Khilan,25,Delhi,1500.00
3,kaushik,23,Kota,2000.00
4,Chaitali,25,Mumbai,6500.00
5,Hardik,27,Bhopal,8500.00
6,Komal,22,MP,4500.00
7,Muffy,24,Indore,10000.00
orders.txt
102,2009-10-08 00:00:00,3,3000
100,2009-10-08 00:00:00,3,1500
101,2009-11-20 00:00:00,2,1560
103,2008-05-20 00:00:00,4,2060
Self – join
Self-join is used to join a table with itself as if the table were two relations,
temporarily renaming at least one relation.
Verify the relation customers3 using the DUMP operator as shown below.
(1,Ramesh,32,Ahmedabad,2000,1,Ramesh,32,Ahmedabad,2000)
(2,Khilan,25,Delhi,1500,2,Khilan,25,Delhi,1500)
(3,kaushik,23,Kota,2000,3,kaushik,23,Kota,2000)
(4,Chaitali,25,Mumbai,6500,4,Chaitali,25,Mumbai,6500)
(5,Hardik,27,Bhopal,8500,5,Hardik,27,Bhopal,8500)
(6,Komal,22,MP,4500,6,Komal,22,MP,4500)
(7,Muffy,24,Indore,10000,7,Muffy,24,Indore,10000)
Inner Join
Inner Join is used quite frequently; it is also referred to as equijoin. An inner join
returns rows when there is a match in both tables.
inner join operation on the two relations customers and orders as shown below.
(2,Khilan,25,Delhi,1500,101,2009-11-20 00:00:00,2,1560)
(3,kaushik,23,Kota,2000,100,2009-10-08 00:00:00,3,1500)
(3,kaushik,23,Kota,2000,102,2009-10-08 00:00:00,3,3000)
(4,Chaitali,25,Mumbai,6500,103,2008-05-20 00:00:00,4,2060)
Note −
Outer Join: Unlike inner join, outer join returns all the rows from at least one of the
relations. An outer join operation is carried out in three ways −
52
(1,Ramesh,32,Ahmedabad,2000,,,,)
(2,Khilan,25,Delhi,1500,101,2009-11-20 00:00:00,2,1560)
(3,kaushik,23,Kota,2000,100,2009-10-08 00:00:00,3,1500)
(3,kaushik,23,Kota,2000,102,2009-10-08 00:00:00,3,3000)
(4,Chaitali,25,Mumbai,6500,103,2008-05-20 00:00:00,4,2060)
(5,Hardik,27,Bhopal,8500,,,,)
(6,Komal,22,MP,4500,,,,)
(7,Muffy,24,Indore,10000,,,,)
Right Outer Join
The right outer join operation returns all rows from the right table, even if there are
no matches in the left table.
Let us perform right outer join operation on the two relations customers and orders as
shown below.
(2,Khilan,25,Delhi,1500,101,2009-11-20 00:00:00,2,1560)
(3,kaushik,23,Kota,2000,100,2009-10-08 00:00:00,3,1500)
(3,kaushik,23,Kota,2000,102,2009-10-08 00:00:00,3,3000)
(4,Chaitali,25,Mumbai,6500,103,2008-05-20 00:00:00,4,2060)
Full Outer Join
The full outer join operation returns rows when there is a match in one of the
relations.
(1,Ramesh,32,Ahmedabad,2000,,,,)
(2,Khilan,25,Delhi,1500,101,2009-11-20 00:00:00,2,1560)
(3,kaushik,23,Kota,2000,100,2009-10-08 00:00:00,3,1500)
53
(3,kaushik,23,Kota,2000,102,2009-10-08 00:00:00,3,3000)
(4,Chaitali,25,Mumbai,6500,103,2008-05-20 00:00:00,4,2060)
(5,Hardik,27,Bhopal,8500,,,,)
(6,Komal,22,MP,4500,,,,)
(7,Muffy,24,Indore,10000,,,,)
VIVA QUESTIONS
1)what is pig in Hadoop?
Ans:Apache open source project which is run on hadoop,provides engine for data
flow in parallel on hadoop.It includes language called pig latin,which is for
expressing these data flow.It includes different operations like joins,sort,filter ..etc
and also ability to write UserDefine Functions(UDF) for proceesing and reaing and
writing.pig uses both HDFS and MapReduce i,e storing and processing.
54
and know data flows ans also early to find the error checking.pig Latin is much lower
cost to write and maintain thanJava code for MapReduce.
Ex.No: 8
Use Hive to Manage Databases, Tables and Views
OBJECTIVE: Install and Run Hive then use Hive to create, alter, and drop databases, tables,
views, functions, and indexes
DESCRIPTION:
Hive is a data warehouse infrastructure tool to process structured data in
Hadoop. It resides on top of Hadoop to summarize Big Data, and makes
querying and analyzing easy.
OK
1 A 101 laptop
2 B 102 cd
3 C 103 pendrive
4 D 104 dd
NULL NULL 105 ddd
VIVA QUESTIONS:
1. What is Hive?
59