Skip to content

Instantly share code, notes, and snippets.

@dgadiraju
dgadiraju / hadoop-hdfs-get-started
Last active January 19, 2017 01:46
Hadoop command to get started by copying files in local file system. Run this on shell
-- Create directory cards under home
mkdir cards
-- Copy largedeck.txt file to the gateway node and place it in cards directory under home directory
-- On lab file is placed under /data directory where any one can read
cp /data/cards/* ~/cards
-- If you want to copy other files you have to use scp/winscp from your PC to gateway
-- Confirm largedeck.txt is available under your home directory
ls -ltr ~/cards
--Login to mysql CLI
mysql -u retail_dba -h nn01.itversity.com -p
show databases;
use retail_db;
show tables;
select * from departments;
object hw {
def main(args: Array[String]) {
println("Hello World!")
}
}
//Immutable
val i = 10 //Smart enough to figure out the data type
val i: Int = 0 //Data type can be defined explicitly as well
//This does not work i = i + 1, as i is defined as immutable (val)
//Mutable
var j = 20
j = j + 1
//Creating functions
def addIntegers(i: Int, j: Int): Int = {
i + j
}
//Anonymous function assigned to a variable
val addIntegers = (i: Int, j: Int) => {
i + j
}
// closure example
def m2: Int => Int = {
val factor = 2
val multiplier = (i: Int) => i * factor
multiplier
}
for i in sc.textFile("/public/randomtextwriter/part-m-00000"). \
flatMap(lambda rec: rec.split(" ")). \
map(lambda rec: (rec, 1)). \
reduceByKey(lambda total, value: total + value). \
take(100):
print(i)
val conf = new SparkConf().
setAppName("Word Count).
setMaster("local")
dev.host = nn01.itversity.com
dev.port = 3306
dev.db = hr
dev.user = hr_ro
dev.pw = itversity
name := "wlabs"
version := "1.0"
scalaVersion := "2.11.8"
libraryDependencies += "mysql" % "mysql-connector-java" % "5.1.36"
libraryDependencies += "com.typesafe" % "config" % "1.3.1"