Prerequisite: Extends Databricks – Spark ML – Linear Regression. Problem statement: Predict the house prices by land area in square feet, house condition as in “Bad”, “Average”, and “Good”, and house locality as in “Sydney”, … Read more ›...
Prerequisite: Extends Databricks – Spark ML – Linear Regression. Problem statement: Predict the house prices by land area in square feet, house condition as in “Bad”, “Average”, and “Good”, and house locality as in “Sydney”, … Read more ›...
The “etc” (i.e etcetera) folder is mainly for configuration files. It’s purpose is to host various configuration files. For instance, to add a new hard drive to your system and have Linux auto-mount it on boot, you’d have to edit /etc/fstab. Key “Hadoop Cluster Configuration” files are:
|
1 2 3 4 5 6 7 8 9 10 11 |
[root@quickstart /]# ls -ltr /etc/hadoop/conf/ total 40 -rwxr-xr-x 1 root root 2375 Feb 23 2016 yarn-site.xml -rwxr-xr-x 1 root root 1104 Feb 23 2016 README -rwxr-xr-x 1 root root 2890 Feb 23 2016 hadoop-metrics.properties -rwxr-xr-x 1 root root 1366 Feb 23 2016 hadoop-env.sh -rwxr-xr-x 1 root root 11291 Mar 23 2016 log4j.properties -rw-rw-r-- 1 root root 1546 Apr 5 2016 mapred-site.xml -rw-rw-r-- 1 root root 3739 Apr 5 2016 hdfs-site.xml -rw-rw-r-- 1 root root 1915 Apr 5 2016 core-site.xml |
hadoop-env.sh
This file specifies environment variables that affect the JDK used by Hadoop Daemon (i.e.
…
Pre-requisite: Docker is installed on your machine for Mac OS X (E.g. $ brew cask install docker) or Windows 10. Docker interview Q&As. This extends setting up Apache Zeppelin Notebook. Step 1: Pull this from the docker hub, … Read more ›...
This extends the Spark streaming with “textFileStream” simple tutorial to use fileStream(…) and PortableDataStream. The pom.xml file is same as the previous Spark streaming tutorial. Step 1: Using “fileStream(…)”.
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
package com.mytutorial; import java.io.DataInputStream; import java.nio.file.Files; import java.nio.file.Paths; import java.util.List; import org.apache.hadoop.fs.Path; import org.apache.spark.SparkConf; import org.apache.spark.api.java.function.Function; import org.apache.spark.input.PortableDataStream; import org.apache.spark.input.StreamInputFormat; import org.apache.spark.streaming.Seconds; import org.apache.spark.streaming.api.java.JavaPairInputDStream; import org.apache.spark.streaming.api.java.JavaStreamingContext; import scala.Tuple2; public class SparkSimpleStreaming { public static void main(String[] args) { SparkConf sparkConf = new SparkConf().setAppName("Streaming HDFS path").setMaster("local[2]"); sparkConf.set("spark.serializer", "org.apache.spark.serializer.KryoSerializer"); JavaStreamingContext jstreamCtxt = new JavaStreamingContext(sparkConf, Seconds.apply(5)); //every 5 seconds JavaPairInputDStream<String, PortableDataStream> fileStream = jstreamCtxt.fileStream( "file:///home/user/stream", String.class, PortableDataStream.class, StreamInputFormat.class); fileStream.foreachRDD(x -> { List<Tuple2<String, PortableDataStream>> dataWithFileNames = x.collect(); for (Tuple2<String, PortableDataStream> dataAndFileNm : dataWithFileNames) { String filePath = dataAndFileNm._1.split(":")[1]; PortableDataStream data = dataAndFileNm._2; DataInputStream dis = data.open(); byte[] bs = new byte[dis.available()]; dis.readFully(bs); System.out.println("###### file " + filePath); System.out.println("###### data " + new String(bs)); Files.deleteIfExists(Paths.get(filePath)); } }); jstreamCtxt.start(); jstreamCtxt.awaitTermination(); jstreamCtxt.close(); } } |
What if you want to process the files already in the folder when the streaming job started?… Read more ›...
Step 1: Read the XML snippet in between the tags “<Record>”. Upload this file to HDFS “/user/cloudera/xml/orders.xml”.
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
<?xml version="1.0" encoding="UTF-8"?> <Message xmlns="http://com.mytut"> <Header> <MsgId>01-01-2017T22:00:30</MsgId> <MsgTimestamp>01-01-2017T22:00:30</MsgTimestamp> </Header> <Record> <OrderId>123</OrderId> <OrderName></OrderName> </Record> </Message> |
Step 2: You need the XmlInputFormat class as shown below. You can find this in the Mahout library. … Read more ›...
Prerequisite: Extends Databricks – Spark ML – Categorical Features – Linear Regression. Problem statement: Predict the house prices by land area in square feet, house color as in “White”, “Grey”, and “Cream”, and house locality as in “Eastwood”, … Read more ›...
This extends Docker Tutorial: BigData on Cloudera quickstart via Docker. Step 1: Run the container on a command line.
|
1 2 3 4 |
~/projects/docker-hadoop]$ docker run --hostname=quickstart.cloudera \ --privileged=true -t -i -v /Users/arulkumarankumaraswamipillai/projects/docker-hadoop:/src \ --publish-all=true -p 8888:8888 -p 80:80 -p 7180:7180 \ cloudera/quickstart /usr/bin/docker-quickstart |
Step 2: Create a text file “simple.txt” in the local file system.
|
1 2 3 |
[root@quickstart /]# touch simple.txt [root@quickstart /]# vi simple.txt |
|
1 |
A big brown fox jumped over a big brown fence. |
Step 3: Copy this file onto HDFS file system. … Read more ›...
Q98. What is Hive? A98. Hive is used for accessing and analyzing data in Hadoop using SQL syntax. It is known as the HiveQL. Q99. What is the difference between Hive internal tables & external tables? A99. … Read more ›...
RDD inner join via JavaPairRDD Here is an inner join displaying all the orders with line items.
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
package com.mytutorial; import java.util.Arrays; import java.util.List; 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 SparkRddJoins { public static void main(String[] args) { SparkConf conf = new SparkConf().setAppName("Spark Rdd joins") .setMaster("local[3]"); List<Order> orders = Arrays.asList(new Order("123", "John"), new Order("456", "Smith"), new Order("789", "Samuel")); List<LineItem> items = Arrays.asList(new LineItem("123", "Pen"), new LineItem("456", "Pencil")); try (JavaSparkContext sc = new JavaSparkContext(conf);) { JavaRDD<Order> rddOrders = sc.parallelize(orders); JavaRDD<LineItem> rddLineItems = sc.parallelize(items); JavaPairRDD<String, Order> pairRddOrders = rddOrders.mapToPair(x -> { return new Tuple2<String, Order>(x.getOrderId(), x); }); JavaPairRDD<String, LineItem> pairRddLineItems = rddLineItems.mapToPair(x -> { return new Tuple2<String, LineItem>(x.getOrderId(), x); }); JavaPairRDD<String, Tuple2<Order, LineItem>> joinedRdd = pairRddOrders.join(pairRddLineItems); joinedRdd.foreach(x -> { Tuple2<Order, LineItem> orderAndLineItems = x._2(); System.out.println("Order= " + orderAndLineItems._1() ); System.out.println("LineItems= " + orderAndLineItems._2() ); }); } } } |
Outputs:
|
1 2 3 4 5 6 |
Order= Order [orderId=456, orderName=Smith] LineItems= LineItem [orderId=456, productName=Pencil] Order= Order [orderId=123, orderName=John] LineItems= LineItem [orderId=123, productName=Pen] |
RDD left outer join with filtering via JavaPairRDD Here is a left outer join with filtering to display all the orders without any line items. … Read more ›...
Pre-requisite: Docker is installed on your machine for Mac OS X (E.g. $ brew cask install docker) or Windows 10. Docker interview Q&As. This extends setting up Apache Zeppelin Notebook. Step 1: Pull this from the docker hub, … Read more ›...
Prerequisite: Extends Databricks – Spark ML – Linear Regression Categorical Features. Problem statement: Predict the house prices by land area in square feet, house condition as in “Bad”, “Average”, and “Good”, and house locality as in “Sydney”, … Read more ›...
This extends Docker Tutorial: BigData on Cloudera quickstart via Docker. Step 1: Run the container on a command line.
|
1 2 3 |
~/projects/docker-hadoop]$ docker run --hostname=quickstart.cloudera \ --privileged=true -t -i -v /Users/arulkumarankumaraswamipillai/projects/docker-hadoop:/src \ --publish-all=true -p 8888:8888 -p 80:80 -p 7180:7180 cloudera/quickstart /usr/bin/docker-quickstart |
Step 2: Create a csv file “employee.csv” in the local file system.
|
1 2 3 |
[root@quickstart /]# touch employee.csv [root@quickstart /]# vi employee.csv |
|
1 2 3 |
John, Samuel, IT Peter, Smith, Finance Sean, Mendis, Marketing |
Step 3: Copy this file onto HDFS file system. … Read more ›...
This extends the last tutorial where Spark inner & outer joins in Java with JavaPairRDDs. In this tutorial let’s read the orders via a Hive table using SQLContext & Dataframe. RDD left outer join with filtering via JavaPairRDD Here is a left outer join with filtering to display all the...