Posts

DBMS EXERCISE - 3 TO 5

 DEPARTMENT  TABLE: CREATE TABLE DEPARTMENT (DNO VARCHAR(20) PRIMARY KEY, DNAME VARCHAR(20),MGRSTARTDATE DATE); EMPLOYEE TABLE: CREATE TABLE EMPLOYEE (FNAME VARCHAR(20), MNAME VARCHAR(20), LNAME VARCHAR(20), SSN VARCHAR (20) PRIMARY KEY, DOB DATE, ADDRESS VARCHAR (20), GENDER VARCHAR(10),  SALARY INTEGER, SUPERSSN VARCHAR(20) REFERENCES EMPLOYEE (SSN), DNO VARCHAR(20) REFERENCES DEPARTMENT (DNO)); NOTE: Once DEPARTMENT and EMPLOYEE tables are created we must alter department table to add foreign constraint MGRSSN using sql command ALTER TABLE DEPARTMENT ADD MGRSSN VARCHAR(20) REFERENCES EMPLOYEE (SSN); DEPENDENT TABLE: CREATE TABLE DEPENDENT (ESSN VARCHAR(20) REFERENCES EMPLOYEE(SSN), DEPENDENTNAME VARCHAR(20), GENDER VARCHAR(20), DOB DATE, RELATIONSHIP VARCHAR(20)); DLOCATION TABLE: CREATE TABLE DLOCATION(DLOC VARCHAR(20),DNO VARCHAR(20) REFERENCES DEPARTMENT(DNO), PRIMARY KEY(DNO, DLOC)); PROJECT TABLE: CREATE TABLE PROJECT (PNAME VARCHAR(20),PNO INTEGER PRIMARY KEY,...

DBMS Exercise - I

1) Create a table STUDENT with appropriate data types and perform the following queries.   Attributes         are Roll number, student name, date of birth, branch and year of study .  a) Insert 5 to 10 rows in a table? b) List all the students of all branches.  c) List student names whose name starts with ‘s‘.  d) List student names whose name contains ‘s as third literal.  e) List student names whose contains two ‘s‘ anywhere in the name  f) List students whose branch is NULL.  g) List students of CSE & ECE who born after 1980.  h) List all students in reverse order of their names.  i) Delete students of any branch whose name starts with ‘s‘.  j) Update the branch of CSE students to ECE.  k) Display student name padded with *‘after the name of all the students.

Hadoop Jars Link

 https://drive.google.com/file/d/1Fc8k625z5Y4KbG3VYUIAuNrsgwvubD8o/view?usp=sharing

Pig & Hive User Defined Functions Sample Code

Pig User Defined Function :  package com.hadoop;   import java.io.IOException;   import org.apache.pig.EvalFunc;   import org.apache.pig.data.Tuple;   public class TestUpper extends EvalFunc<String>   {       public String exec(Tuple input) throws IOException {             if (input == null || input.size() == 0)             return null;             try{                         String str = (String)input.get(0);             return str.toUpperCase();             }catch(Exception e){             throw new IOException("Caught exception processing input row ", e);                     }...

MapReduce Flights between Origin and Destination

MapReduce Flights between Origin and Destination: package com.lbrce.flight; import java.io.IOException; import java.util.Iterator; import org.apache.hadoop.fs.Path; import org.apache.hadoop.io.LongWritable; import org.apache.hadoop.io.Text; import org.apache.hadoop.mapreduce.lib.input.FileInputFormat; import org.apache.hadoop.mapreduce.lib.output.FileOutputFormat; import org.apache.hadoop.mapreduce.lib.output.TextOutputFormat; import org.apache.hadoop.mapreduce.lib.input.TextInputFormat; import org.apache.hadoop.mapreduce.Job; import org.apache.hadoop.mapreduce.Mapper; import org.apache.hadoop.mapreduce.Reducer; import org.apache.hadoop.conf.Configuration; public class Flight { public static class FlightMapper extends Mapper<LongWritable, Text, Text, Text> { public void map(LongWritable arg0, Text Value, Context context) throws IOException, InterruptedException { String line = Value.toString(); if (!(line.length() == 0)) { String fno = line.substring(0, 4); String origin=line.sub...

MapReduce Character Count

 Mapper Logic : 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 CharCountMapper extends Mapper<LongWritable, Text, Text, IntWritable> {   @Override   public void map(LongWritable key, Text value, Context con)       throws IOException, InterruptedException {     String line = value.toString();     char[] chars = line.toCharArray();     for(char c:chars) {     con.write(new Text("Total Characters"), new IntWritable(1));     }   } } Reducer Logic : import java.io.IOException; import org.apache.hadoop.io.IntWritable; import org.apache.hadoop.io.Text; import org.apache.hadoop.mapreduce.Reducer; public class CharCountReducer extends Reducer<Text, IntWritable, Text, IntWritable> {   /*    * bigdata   <1>   ...

MapReuce K-Mean Clustering

import java.io.IOException; import java.util.*; import java.io.*; import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.filecache.DistributedCache; import org.apache.hadoop.fs.FileSystem; import org.apache.hadoop.fs.Path; import org.apache.hadoop.io.*; import org.apache.hadoop.mapred.*; import org.apache.hadoop.mapred.Reducer;   @SuppressWarnings("deprecation") public class KMean {     public static String OUT = "outfile";     public static String IN = "inputlarger";     public static String CENTROID_FILE_NAME = "/centroid.txt";     public static String OUTPUT_FILE_NAME = "/part-00000";     public static String DATA_FILE_NAME = "/data.txt";     public static String JOB_NAME = "KMeans";     public static String SPLITTER = "t| ";     public static List<Double> mCenters = new ArrayList<Double>();     public static class Map extends MapReduceBase implements Mapper<Lo...