isl75lab 1.0.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- isl75lab-1.0.0/PKG-INFO +52 -0
- isl75lab-1.0.0/README.md +45 -0
- isl75lab-1.0.0/pyproject.toml +17 -0
- isl75lab-1.0.0/setup.cfg +4 -0
- isl75lab-1.0.0/src/isl75lab/__init__.py +1 -0
- isl75lab-1.0.0/src/isl75lab/__main__.py +4 -0
- isl75lab-1.0.0/src/isl75lab/cli.py +55 -0
- isl75lab-1.0.0/src/isl75lab/data/guide.txt +67 -0
- isl75lab-1.0.0/src/isl75lab/data/hadoop.txt +17 -0
- isl75lab-1.0.0/src/isl75lab/data/java.txt +11 -0
- isl75lab-1.0.0/src/isl75lab/data/parta1.txt +82 -0
- isl75lab-1.0.0/src/isl75lab/data/parta2.txt +68 -0
- isl75lab-1.0.0/src/isl75lab/data/parta3.txt +58 -0
- isl75lab-1.0.0/src/isl75lab/data/parta4.txt +101 -0
- isl75lab-1.0.0/src/isl75lab/data/parta5.txt +59 -0
- isl75lab-1.0.0/src/isl75lab/data/parta6.txt +63 -0
- isl75lab-1.0.0/src/isl75lab/data/partb1.txt +28 -0
- isl75lab-1.0.0/src/isl75lab/data/partb2.txt +16 -0
- isl75lab-1.0.0/src/isl75lab/data/partb3.txt +21 -0
- isl75lab-1.0.0/src/isl75lab/data/partb4.txt +19 -0
- isl75lab-1.0.0/src/isl75lab/data/partb5.txt +17 -0
- isl75lab-1.0.0/src/isl75lab/data/partb6.txt +28 -0
- isl75lab-1.0.0/src/isl75lab/data/pig.txt +19 -0
- isl75lab-1.0.0/src/isl75lab/data/spark.txt +16 -0
- isl75lab-1.0.0/src/isl75lab.egg-info/PKG-INFO +52 -0
- isl75lab-1.0.0/src/isl75lab.egg-info/SOURCES.txt +27 -0
- isl75lab-1.0.0/src/isl75lab.egg-info/dependency_links.txt +1 -0
- isl75lab-1.0.0/src/isl75lab.egg-info/entry_points.txt +2 -0
- isl75lab-1.0.0/src/isl75lab.egg-info/top_level.txt +1 -0
isl75lab-1.0.0/PKG-INFO
ADDED
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: isl75lab
|
|
3
|
+
Version: 1.0.0
|
|
4
|
+
Summary: Print ISL75 Big Data Laboratory programs and setup instructions by question.
|
|
5
|
+
Requires-Python: >=3.9
|
|
6
|
+
Description-Content-Type: text/markdown
|
|
7
|
+
|
|
8
|
+
# ISL75 Big Data Laboratory
|
|
9
|
+
|
|
10
|
+
Look up any of the 12 programs from the ISL75 lab manual by part and question number. All source listings and the installation guide are bundled in the package, so lookups work offline.
|
|
11
|
+
|
|
12
|
+
## Installation
|
|
13
|
+
|
|
14
|
+
Use Python 3.9 or newer. To install a downloaded wheel, run this in the folder containing it:
|
|
15
|
+
|
|
16
|
+
```shell
|
|
17
|
+
python -m pip install ./isl75lab-1.0.0-py3-none-any.whl
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
Once the release is on PyPI, install it on another machine with `python -m pip install isl75lab`.
|
|
21
|
+
|
|
22
|
+
## Question lookup
|
|
23
|
+
|
|
24
|
+
```shell
|
|
25
|
+
isl75lab src
|
|
26
|
+
isl75lab src parta1
|
|
27
|
+
isl75lab src partb6
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
The first command lists all questions. Replace the part and number to print a program. The spaced form `isl75lab src parta 1` also works. If your shell cannot find the command, use `python -m isl75lab src parta1`.
|
|
31
|
+
|
|
32
|
+
| Question | Part A · Java MapReduce | Part B · Spark or Pig |
|
|
33
|
+
| --- | --- | --- |
|
|
34
|
+
| 1 | Word count | Lines and word lengths |
|
|
35
|
+
| 2 | Odd and even numbers | Weather reports |
|
|
36
|
+
| 3 | Employee statistics | Insurance statistics |
|
|
37
|
+
| 4 | Titanic passengers | Crop production |
|
|
38
|
+
| 5 | Earthquake statistics | Olympic athletes and hosts |
|
|
39
|
+
| 6 | Sales records | Online retail |
|
|
40
|
+
|
|
41
|
+
Part A prints the Java files together under the manual's filenames, with sample input where supplied alongside the code. Part B prints the Python or Pig source. The listings preserve the code as printed in the manual, including its syntax and typography. For example, the word-length expression in Part B question 1 contains a misplaced backslash in the original.
|
|
42
|
+
|
|
43
|
+
## Installation guide
|
|
44
|
+
|
|
45
|
+
```shell
|
|
46
|
+
isl75lab src howtorun
|
|
47
|
+
isl75lab src howtorun java
|
|
48
|
+
isl75lab src howtorun python
|
|
49
|
+
isl75lab src howtorun pig
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
The first command prints the complete installation guide. The Java selection covers Java and Hadoop. The Python selection adds the guide's Spark steps, and the Pig selection includes Java, Hadoop and Pig. These commands display the Linux setup instructions for you to follow on your lab machine.
|
isl75lab-1.0.0/README.md
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
# ISL75 Big Data Laboratory
|
|
2
|
+
|
|
3
|
+
Look up any of the 12 programs from the ISL75 lab manual by part and question number. All source listings and the installation guide are bundled in the package, so lookups work offline.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
Use Python 3.9 or newer. To install a downloaded wheel, run this in the folder containing it:
|
|
8
|
+
|
|
9
|
+
```shell
|
|
10
|
+
python -m pip install ./isl75lab-1.0.0-py3-none-any.whl
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
Once the release is on PyPI, install it on another machine with `python -m pip install isl75lab`.
|
|
14
|
+
|
|
15
|
+
## Question lookup
|
|
16
|
+
|
|
17
|
+
```shell
|
|
18
|
+
isl75lab src
|
|
19
|
+
isl75lab src parta1
|
|
20
|
+
isl75lab src partb6
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
The first command lists all questions. Replace the part and number to print a program. The spaced form `isl75lab src parta 1` also works. If your shell cannot find the command, use `python -m isl75lab src parta1`.
|
|
24
|
+
|
|
25
|
+
| Question | Part A · Java MapReduce | Part B · Spark or Pig |
|
|
26
|
+
| --- | --- | --- |
|
|
27
|
+
| 1 | Word count | Lines and word lengths |
|
|
28
|
+
| 2 | Odd and even numbers | Weather reports |
|
|
29
|
+
| 3 | Employee statistics | Insurance statistics |
|
|
30
|
+
| 4 | Titanic passengers | Crop production |
|
|
31
|
+
| 5 | Earthquake statistics | Olympic athletes and hosts |
|
|
32
|
+
| 6 | Sales records | Online retail |
|
|
33
|
+
|
|
34
|
+
Part A prints the Java files together under the manual's filenames, with sample input where supplied alongside the code. Part B prints the Python or Pig source. The listings preserve the code as printed in the manual, including its syntax and typography. For example, the word-length expression in Part B question 1 contains a misplaced backslash in the original.
|
|
35
|
+
|
|
36
|
+
## Installation guide
|
|
37
|
+
|
|
38
|
+
```shell
|
|
39
|
+
isl75lab src howtorun
|
|
40
|
+
isl75lab src howtorun java
|
|
41
|
+
isl75lab src howtorun python
|
|
42
|
+
isl75lab src howtorun pig
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
The first command prints the complete installation guide. The Java selection covers Java and Hadoop. The Python selection adds the guide's Spark steps, and the Pig selection includes Java, Hadoop and Pig. These commands display the Linux setup instructions for you to follow on your lab machine.
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["setuptools>=68"]
|
|
3
|
+
build-backend = "setuptools.build_meta"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "isl75lab"
|
|
7
|
+
version = "1.0.0"
|
|
8
|
+
description = "Print ISL75 Big Data Laboratory programs and setup instructions by question."
|
|
9
|
+
readme = "README.md"
|
|
10
|
+
requires-python = ">=3.9"
|
|
11
|
+
dependencies = []
|
|
12
|
+
|
|
13
|
+
[project.scripts]
|
|
14
|
+
isl75lab = "isl75lab.cli:main"
|
|
15
|
+
|
|
16
|
+
[tool.setuptools.package-data]
|
|
17
|
+
isl75lab = ["data/*.txt"]
|
isl75lab-1.0.0/setup.cfg
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"""ISL75 Big Data Laboratory reference."""
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import argparse
|
|
2
|
+
from importlib.resources import files
|
|
3
|
+
import re
|
|
4
|
+
import sys
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
QUESTIONS = {
|
|
8
|
+
"a": ("Word count", "Odd and even numbers", "Employee statistics",
|
|
9
|
+
"Titanic passengers", "Earthquake statistics", "Sales records"),
|
|
10
|
+
"b": ("Lines and word lengths", "Weather reports", "Insurance statistics",
|
|
11
|
+
"Crop production", "Olympic athletes and hosts", "Online retail"),
|
|
12
|
+
}
|
|
13
|
+
GUIDES = {
|
|
14
|
+
"all": ("guide",),
|
|
15
|
+
"java": ("java", "hadoop"),
|
|
16
|
+
"python": ("java", "hadoop", "spark"),
|
|
17
|
+
"pig": ("java", "hadoop", "pig"),
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
def read(name):
|
|
22
|
+
return files("isl75lab").joinpath("data").joinpath(name + ".txt").read_text(encoding="utf-8")
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
def main():
|
|
26
|
+
parser = argparse.ArgumentParser(prog="isl75lab", description="Browse the ISL75 Big Data Laboratory.")
|
|
27
|
+
commands = parser.add_subparsers(dest="command", required=True)
|
|
28
|
+
src = commands.add_parser("src", help="print a program, setup guide or question index")
|
|
29
|
+
src.add_argument("selection", nargs="*", metavar="ITEM",
|
|
30
|
+
help="parta1 to partb6, or howtorun [java|python|pig|all]")
|
|
31
|
+
args = parser.parse_args()
|
|
32
|
+
parts = [word.lower() for word in args.selection]
|
|
33
|
+
|
|
34
|
+
if not parts:
|
|
35
|
+
for part, titles in QUESTIONS.items():
|
|
36
|
+
for number, title in enumerate(titles, 1):
|
|
37
|
+
print(f"part{part}{number} {title}")
|
|
38
|
+
print("\nhowtorun [java|python|pig|all]")
|
|
39
|
+
return
|
|
40
|
+
|
|
41
|
+
if parts[0] == "howtorun":
|
|
42
|
+
topic = parts[1] if len(parts) > 1 else "all"
|
|
43
|
+
if len(parts) > 2 or topic not in GUIDES:
|
|
44
|
+
src.error("choose howtorun java, python, pig or all")
|
|
45
|
+
output = "\n".join(read(section) for section in GUIDES[topic])
|
|
46
|
+
else:
|
|
47
|
+
if len(parts) == 2 and parts[0] in ("parta", "partb"):
|
|
48
|
+
parts = ["".join(parts)]
|
|
49
|
+
if len(parts) != 1 or not re.fullmatch(r"part[ab][1-6]", parts[0]):
|
|
50
|
+
src.error("use parta1 through parta6 or partb1 through partb6; run 'isl75lab src' for the index")
|
|
51
|
+
output = read(parts[0])
|
|
52
|
+
|
|
53
|
+
if not sys.stdout.isatty() and hasattr(sys.stdout, "reconfigure"):
|
|
54
|
+
sys.stdout.reconfigure(encoding="utf-8", newline="\n")
|
|
55
|
+
sys.stdout.write(output)
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
Instruction Guide
|
|
2
|
+
JAVA
|
|
3
|
+
1. Verify whether you have JAVA installed on your system using the following command.
|
|
4
|
+
$ javac --version
|
|
5
|
+
2. If not, to install JDK in Linux, use the following command.
|
|
6
|
+
$ sudo apt install default-jdk
|
|
7
|
+
3. Then, the JRE File of Java will be installed using the following command.
|
|
8
|
+
$ sudo apt install default-jre
|
|
9
|
+
4. To verify the installation, the following command you can use. It will prompt the Java version used there.
|
|
10
|
+
$ javac --version
|
|
11
|
+
5. Create a new folder named <1MS23SCS/SCN**> and navigate inside the folder using the following command.
|
|
12
|
+
$ cd <1MS23SCS/SCN**>
|
|
13
|
+
|
|
14
|
+
Hadoop
|
|
15
|
+
1. Now download the hadoop tar file to install using the given url.
|
|
16
|
+
2. Once you have downloaded hadoop-3.2.2.tar.gz, extract this file with the below command (make sure to check your tar filename).
|
|
17
|
+
$ tar xvzf hadoop-3.2.2.tar.gz
|
|
18
|
+
3. Now navigate inside the folder using the below command.
|
|
19
|
+
$ cd hadoop-3.2.2/
|
|
20
|
+
4. Create and open a new bash.sh file inside the directory.
|
|
21
|
+
$ gedit bash.sh
|
|
22
|
+
5. We configure the file, copy the below command inside this file and save it.
|
|
23
|
+
export JAVA_HOME=$(readlink -f $(which javac) | awk 'BEGIN {FS="/bin"} {print $1}')
|
|
24
|
+
export PATH=$(echo $PATH):$(pwd)/bin
|
|
25
|
+
export CLASSPATH=$(hadoop classpath)
|
|
26
|
+
6. Execute the bash.sh File using following command
|
|
27
|
+
$ source bash.sh
|
|
28
|
+
7. Verify JAVA_HOME variable to be set to Java Path and PATH variable has your Hadoop Folder.
|
|
29
|
+
8. Verify Hadoop is Installed or not by executing hadoop command. If command gives Information about Hadoop command, then Hadoop is Successfully Installed.
|
|
30
|
+
$ hadoop
|
|
31
|
+
|
|
32
|
+
Spark
|
|
33
|
+
1. Verify that hadoop is installed and running in your system.
|
|
34
|
+
$ hadoop
|
|
35
|
+
2. Download Apache Spark from the given url inside your folder.
|
|
36
|
+
3. Now we extract this tar file with the help of below command (make sure to check your tar filename).
|
|
37
|
+
$ tar xvzf spark-3.5.2-bin-hadoop3.tgz
|
|
38
|
+
4. Now navigate inside the folder using the below command.
|
|
39
|
+
$ cd spark-3.5.2-bin-hadoop3/
|
|
40
|
+
5. Create a new file named bash.sh inside your folder by using any text editor.
|
|
41
|
+
$ gedit bash.sh
|
|
42
|
+
6. Copy below code and paste inside bash.sh file
|
|
43
|
+
export PATH=$(echo $PATH):$(pwd)/bin
|
|
44
|
+
7. In terminal, execute bash.sh file using the following command.
|
|
45
|
+
$ source bash.sh
|
|
46
|
+
8. Verify spark version with the below command.
|
|
47
|
+
$ spark-shell --version
|
|
48
|
+
|
|
49
|
+
PIG
|
|
50
|
+
1. Verify that hadoop is installed and running in your system.
|
|
51
|
+
$ hadoop
|
|
52
|
+
2. Download Apache Pig from the given url inside your folder.
|
|
53
|
+
3. Now we extract this tar file with the help of below command (make sure to check your tar filename).
|
|
54
|
+
$ tar -xvf pig-0.17.0.tar.gz
|
|
55
|
+
4. Now navigate inside the folder using the below command.
|
|
56
|
+
$ cd pig-0.17.0/
|
|
57
|
+
5. Create and open a new bash.sh file inside the directory.
|
|
58
|
+
$ gedit bash.sh
|
|
59
|
+
6. We configure file, copy the below command inside this file and save it.
|
|
60
|
+
export PIG_INSTALL=$(pwd)
|
|
61
|
+
export PATH=$PATH:$(pwd)/bin
|
|
62
|
+
7. Execute the bash.sh File using following command
|
|
63
|
+
$ source bash.sh
|
|
64
|
+
8. You can check your pig version with the below command.
|
|
65
|
+
$ pig -version
|
|
66
|
+
9. Once you get it correct that’s it we have successfully install pig to our Hadoop single node setup, now we start pig with below pig command.
|
|
67
|
+
$ pig
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
Hadoop
|
|
2
|
+
1. Now download the hadoop tar file to install using the given url.
|
|
3
|
+
2. Once you have downloaded hadoop-3.2.2.tar.gz, extract this file with the below command (make sure to check your tar filename).
|
|
4
|
+
$ tar xvzf hadoop-3.2.2.tar.gz
|
|
5
|
+
3. Now navigate inside the folder using the below command.
|
|
6
|
+
$ cd hadoop-3.2.2/
|
|
7
|
+
4. Create and open a new bash.sh file inside the directory.
|
|
8
|
+
$ gedit bash.sh
|
|
9
|
+
5. We configure the file, copy the below command inside this file and save it.
|
|
10
|
+
export JAVA_HOME=$(readlink -f $(which javac) | awk 'BEGIN {FS="/bin"} {print $1}')
|
|
11
|
+
export PATH=$(echo $PATH):$(pwd)/bin
|
|
12
|
+
export CLASSPATH=$(hadoop classpath)
|
|
13
|
+
6. Execute the bash.sh File using following command
|
|
14
|
+
$ source bash.sh
|
|
15
|
+
7. Verify JAVA_HOME variable to be set to Java Path and PATH variable has your Hadoop Folder.
|
|
16
|
+
8. Verify Hadoop is Installed or not by executing hadoop command. If command gives Information about Hadoop command, then Hadoop is Successfully Installed.
|
|
17
|
+
$ hadoop
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
JAVA
|
|
2
|
+
1. Verify whether you have JAVA installed on your system using the following command.
|
|
3
|
+
$ javac --version
|
|
4
|
+
2. If not, to install JDK in Linux, use the following command.
|
|
5
|
+
$ sudo apt install default-jdk
|
|
6
|
+
3. Then, the JRE File of Java will be installed using the following command.
|
|
7
|
+
$ sudo apt install default-jre
|
|
8
|
+
4. To verify the installation, the following command you can use. It will prompt the Java version used there.
|
|
9
|
+
$ javac --version
|
|
10
|
+
5. Create a new folder named <1MS23SCS/SCN**> and navigate inside the folder using the following command.
|
|
11
|
+
$ cd <1MS23SCS/SCN**>
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
driver.java
|
|
2
|
+
package wordcount;
|
|
3
|
+
import java.io.*;
|
|
4
|
+
import java.util.*;
|
|
5
|
+
import org.apache.hadoop.mapred.*;
|
|
6
|
+
import org.apache.hadoop.io.*;
|
|
7
|
+
import org.apache.hadoop.fs.Path;
|
|
8
|
+
public class driver
|
|
9
|
+
{
|
|
10
|
+
public static void main(String args[]) throws IOException
|
|
11
|
+
{
|
|
12
|
+
JobConf conf=new JobConf(driver.class);
|
|
13
|
+
conf.setMapperClass(mapper.class);
|
|
14
|
+
conf.setReducerClass(reducer.class);
|
|
15
|
+
conf.setOutputKeyClass(Text.class);
|
|
16
|
+
conf.setOutputValueClass(IntWritable.class);
|
|
17
|
+
FileInputFormat.addInputPath(conf, new Path(args[0]));
|
|
18
|
+
FileOutputFormat.setOutputPath(conf,new Path(args[1]));
|
|
19
|
+
JobClient.runJob(conf);
|
|
20
|
+
}
|
|
21
|
+
mapper.java
|
|
22
|
+
package wordcount;
|
|
23
|
+
import java.io.*;
|
|
24
|
+
import java.util.*;
|
|
25
|
+
import org.apache.hadoop.mapred.*;
|
|
26
|
+
import org.apache.hadoop.io.*;
|
|
27
|
+
public class mapper extends MapReduceBase implements Mapper<LongWritable, Text, Text, IntWritable> {
|
|
28
|
+
|
|
29
|
+
// Static final variable for the count of 1
|
|
30
|
+
private final static IntWritable one = new IntWritable(1);
|
|
31
|
+
|
|
32
|
+
// Reusable Text object to hold each word
|
|
33
|
+
private Text word = new Text();
|
|
34
|
+
|
|
35
|
+
// The map function
|
|
36
|
+
public void map(LongWritable key, Text value, OutputCollector<Text, IntWritable> output, Reporter reporter)
|
|
37
|
+
throws IOException {
|
|
38
|
+
|
|
39
|
+
// Convert the input value (line of text) to a string
|
|
40
|
+
String line = value.toString();
|
|
41
|
+
|
|
42
|
+
// Tokenize the line into words
|
|
43
|
+
StringTokenizer tokenizer = new StringTokenizer(line);
|
|
44
|
+
|
|
45
|
+
// Iterate through the tokens (words)
|
|
46
|
+
while (tokenizer.hasMoreTokens()) {
|
|
47
|
+
// Set the current word into the Text object
|
|
48
|
+
word.set(tokenizer.nextToken());
|
|
49
|
+
|
|
50
|
+
// Collect the word and emit (word, 1) as key-value pairs
|
|
51
|
+
output.collect(word, one);
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
reducer.java
|
|
56
|
+
package wordcount;
|
|
57
|
+
import java.io.*;
|
|
58
|
+
import java.util.*;
|
|
59
|
+
import org.apache.hadoop.mapred.*;
|
|
60
|
+
|
|
61
|
+
import org.apache.hadoop.io.*;
|
|
62
|
+
|
|
63
|
+
public class reducer extends MapReduceBase implements Reducer<Text, IntWritable, Text, IntWritable> {
|
|
64
|
+
|
|
65
|
+
public void reduce(Text key, Iterator<IntWritable> values, OutputCollector<Text, IntWritable> output,
|
|
66
|
+
Reporter reporter) throws IOException {
|
|
67
|
+
|
|
68
|
+
int sum = 0;
|
|
69
|
+
|
|
70
|
+
// Sum up the counts for each word
|
|
71
|
+
while (values.hasNext()) {
|
|
72
|
+
sum += values.next().get();
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
// Emit the word with the total count
|
|
76
|
+
output.collect(key, new IntWritable(sum));
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
input.txt
|
|
80
|
+
Goodbye Hadoop
|
|
81
|
+
Hadoop
|
|
82
|
+
Hello
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
driver.java
|
|
2
|
+
package oddeven;
|
|
3
|
+
import java.io.*;
|
|
4
|
+
import java.util.*;
|
|
5
|
+
import org.apache.hadoop.mapred.*;
|
|
6
|
+
import org.apache.hadoop.io.*;
|
|
7
|
+
import org.apache.hadoop.fs.Path;
|
|
8
|
+
|
|
9
|
+
public class driver
|
|
10
|
+
{
|
|
11
|
+
public static void main(String args[]) throws IOException
|
|
12
|
+
{
|
|
13
|
+
JobConf conf=new JobConf(driver.class);
|
|
14
|
+
conf.setMapperClass(mapper.class);
|
|
15
|
+
conf.setReducerClass(reducer.class);
|
|
16
|
+
|
|
17
|
+
conf.setOutputKeyClass(Text.class);
|
|
18
|
+
conf.setOutputValueClass(IntWritable.class);
|
|
19
|
+
FileInputFormat.addInputPath(conf, new Path(args[0]));
|
|
20
|
+
FileOutputFormat.setOutputPath(conf,new Path(args[1]));
|
|
21
|
+
JobClient.runJob(conf);
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
mapper.java
|
|
25
|
+
package oddeven;
|
|
26
|
+
import java.io.*;
|
|
27
|
+
import java.util.*;
|
|
28
|
+
import org.apache.hadoop.mapred.*;
|
|
29
|
+
import org.apache.hadoop.io.*;
|
|
30
|
+
|
|
31
|
+
public class mapper extends MapReduceBase implements Mapper<LongWritable , Text , Text , IntWritable>
|
|
32
|
+
{
|
|
33
|
+
public void map(LongWritable key,Text value,OutputCollector<Text,IntWritable> output,Reporter r) throws IOException
|
|
34
|
+
{
|
|
35
|
+
String[] line=value.toString().split(" ");
|
|
36
|
+
for(String num:line){
|
|
37
|
+
int number=Integer.parseInt(num);
|
|
38
|
+
if(number%2==0) {
|
|
39
|
+
output.collect(new Text("even"),new IntWritable(number));
|
|
40
|
+
}
|
|
41
|
+
else{
|
|
42
|
+
output.collect(new Text("odd"),new IntWritable(number));
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
reducer.java
|
|
48
|
+
package oddeven;
|
|
49
|
+
import java.io.*;
|
|
50
|
+
import java.util.*;
|
|
51
|
+
import org.apache.hadoop.mapred.*;
|
|
52
|
+
import org.apache.hadoop.io.*;
|
|
53
|
+
public class reducer extends MapReduceBase implements Reducer<Text,IntWritable,Text,IntWritable>
|
|
54
|
+
{
|
|
55
|
+
public void reduce(Text key,Iterator<IntWritable> value,OutputCollector<Text,IntWritable> output ,Reporter r) throws IOException
|
|
56
|
+
{
|
|
57
|
+
int sum=0,count=0;
|
|
58
|
+
while(value.hasNext()){
|
|
59
|
+
sum+=value.next().get();
|
|
60
|
+
count++;
|
|
61
|
+
}
|
|
62
|
+
output.collect(new Text("Sum of "+key+" Numbers"),new IntWritable(sum));
|
|
63
|
+
output.collect(new Text(key+" Number count"),new IntWritable(count));
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
input.txt
|
|
68
|
+
1 2 3 4 5 6 7 8 9 10
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
driver.java
|
|
2
|
+
package employee;
|
|
3
|
+
import java.io.*;
|
|
4
|
+
import java.util.*;
|
|
5
|
+
import org.apache.hadoop.mapred.*;
|
|
6
|
+
import org.apache.hadoop.io.*;
|
|
7
|
+
import org.apache.hadoop.fs.Path;
|
|
8
|
+
public class driver
|
|
9
|
+
{
|
|
10
|
+
public static void main(String args[]) throws IOException
|
|
11
|
+
{
|
|
12
|
+
JobConf conf=new JobConf(driver.class);
|
|
13
|
+
conf.setMapperClass(mapper.class);
|
|
14
|
+
conf.setReducerClass(reducer.class);
|
|
15
|
+
conf.setOutputKeyClass(Text.class);
|
|
16
|
+
conf.setOutputValueClass(DoubleWritable.class);
|
|
17
|
+
FileInputFormat.addInputPath(conf,new Path(args[0]));
|
|
18
|
+
FileOutputFormat.setOutputPath(conf,new Path(args[1]));
|
|
19
|
+
|
|
20
|
+
JobClient.runJob(conf);
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
mapper.java
|
|
24
|
+
package employee;
|
|
25
|
+
import java.io.*;
|
|
26
|
+
import java.util.*;
|
|
27
|
+
import org.apache.hadoop.mapred.*;
|
|
28
|
+
import org.apache.hadoop.io.*;
|
|
29
|
+
class mapper extends MapReduceBase implements Mapper<LongWritable , Text , Text , DoubleWritable> {
|
|
30
|
+
|
|
31
|
+
public void map(LongWritable key, Text value, OutputCollector<Text,DoubleWritable> output ,Reporter r) throws IOException
|
|
32
|
+
{
|
|
33
|
+
String[] line=value.toString().split("\\t");
|
|
34
|
+
Double salary=Double.parseDouble(line[8]);
|
|
35
|
+
output.collect(new Text(line[3]), new DoubleWritable(salary));
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
}
|
|
39
|
+
reducer.java
|
|
40
|
+
package employee;
|
|
41
|
+
import java.io.*;
|
|
42
|
+
import java.util.*;
|
|
43
|
+
import org.apache.hadoop.mapred.*;
|
|
44
|
+
import org.apache.hadoop.io.*;
|
|
45
|
+
class reducer extends MapReduceBase implements Reducer<Text,DoubleWritable,Text,DoubleWritable> {
|
|
46
|
+
public void reduce(Text key,Iterator<DoubleWritable> value , OutputCollector<Text,DoubleWritable> output ,Reporter r) throws IOException
|
|
47
|
+
{
|
|
48
|
+
int count=0;
|
|
49
|
+
|
|
50
|
+
Double sum=0.0;
|
|
51
|
+
while(value.hasNext()){
|
|
52
|
+
sum+=value.next().get();
|
|
53
|
+
count+=1;
|
|
54
|
+
}
|
|
55
|
+
output.collect(new Text(key+" Average"), new DoubleWritable(sum/count));
|
|
56
|
+
output.collect(new Text(key+" Count"), new DoubleWritable(count));
|
|
57
|
+
}
|
|
58
|
+
}
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
driver.java
|
|
2
|
+
package titanic;
|
|
3
|
+
import org.apache.hadoop.conf.Configuration;
|
|
4
|
+
import org.apache.hadoop.fs.Path;
|
|
5
|
+
import org.apache.hadoop.io.*;
|
|
6
|
+
import org.apache.hadoop.mapreduce.*;
|
|
7
|
+
import org.apache.hadoop.mapreduce.lib.input.FileInputFormat;
|
|
8
|
+
import org.apache.hadoop.mapreduce.lib.output.FileOutputFormat;
|
|
9
|
+
public class TitanicDriver {
|
|
10
|
+
public static void main(String[] args) throws Exception {
|
|
11
|
+
Configuration conf = new Configuration();
|
|
12
|
+
Job job = Job.getInstance(conf, "Titanic Analysis");
|
|
13
|
+
job.setJarByClass(TitanicDriver.class);
|
|
14
|
+
// Set Mapper and Reducer classes
|
|
15
|
+
job.setMapperClass(TitanicMapper.class);
|
|
16
|
+
job.setReducerClass(TitanicReducer.class);
|
|
17
|
+
// Set output types
|
|
18
|
+
job.setOutputKeyClass(Text.class);
|
|
19
|
+
job.setOutputValueClass(IntWritable.class);
|
|
20
|
+
// Set input and output paths
|
|
21
|
+
FileInputFormat.addInputPath(job, new Path(args[0])); // Input path (CSV file)
|
|
22
|
+
FileOutputFormat.setOutputPath(job, new Path(args[1])); // Output path (results)
|
|
23
|
+
// Wait for job to complete
|
|
24
|
+
System.exit(job.waitForCompletion(true) ? 0 : 1);
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
mapper.java
|
|
28
|
+
package titanic;
|
|
29
|
+
import org.apache.hadoop.io.*;
|
|
30
|
+
import org.apache.hadoop.mapreduce.*;
|
|
31
|
+
import java.io.IOException;
|
|
32
|
+
public class TitanicMapper extends Mapper<LongWritable, Text, Text, IntWritable> {
|
|
33
|
+
private final static IntWritable ageWritable = new IntWritable();
|
|
34
|
+
private final static IntWritable countWritable = new IntWritable(1);
|
|
35
|
+
private Text outputKey = new Text();
|
|
36
|
+
public void map(LongWritable key, Text value, Context context) throws IOException, InterruptedException {
|
|
37
|
+
// Split the CSV row into fields
|
|
38
|
+
String[] fields = value.toString().split(",");
|
|
39
|
+
if (fields.length >= 9) {
|
|
40
|
+
try {
|
|
41
|
+
String survived = fields[1].trim(); // 1: Survived (0 or 1)
|
|
42
|
+
String sex = fields[4].trim(); // 4: Sex (male or female)
|
|
43
|
+
String ageStr = fields[5].trim(); // 5: Age
|
|
44
|
+
int pclass = Integer.parseInt(fields[2].trim()); // 2: Pclass (1, 2, or 3)
|
|
45
|
+
|
|
46
|
+
// Task 1: If the person died (survived == 0), emit their age based on gender
|
|
47
|
+
if ("0".equals(survived) && !ageStr.isEmpty()) {
|
|
48
|
+
int age = (int) Double.parseDouble(ageStr);
|
|
49
|
+
outputKey.set(sex); // Use "male" or "female" as the key
|
|
50
|
+
ageWritable.set(age);
|
|
51
|
+
context.write(outputKey, ageWritable);
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
// Task 2: If the person survived (survived == 1), emit the class number with count
|
|
55
|
+
if ("1".equals(survived)) {
|
|
56
|
+
outputKey.set("SurvivorClass " + pclass); // Key is "SurvivorClass <pclass>"
|
|
57
|
+
context.write(outputKey, countWritable);
|
|
58
|
+
}
|
|
59
|
+
} catch (NumberFormatException e) {
|
|
60
|
+
|
|
61
|
+
// Handle invalid data or missing age
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
reducer.java
|
|
67
|
+
package titanic;
|
|
68
|
+
import org.apache.hadoop.io.*;
|
|
69
|
+
import org.apache.hadoop.mapreduce.*;
|
|
70
|
+
import java.io.IOException;
|
|
71
|
+
public class TitanicReducer extends Reducer<Text, IntWritable, Text, DoubleWritable> {
|
|
72
|
+
|
|
73
|
+
private DoubleWritable result = new DoubleWritable();
|
|
74
|
+
public void reduce(Text key, Iterable<IntWritable> values, Context context) throws IOException, InterruptedException {
|
|
75
|
+
// Case 1: Calculating the average age of those who died (key = "male" or "female")
|
|
76
|
+
if ("male".equals(key.toString()) || "female".equals(key.toString())) {
|
|
77
|
+
int sum = 0;
|
|
78
|
+
int count = 0;
|
|
79
|
+
|
|
80
|
+
for (IntWritable val : values) {
|
|
81
|
+
sum += val.get();
|
|
82
|
+
count++;
|
|
83
|
+
}
|
|
84
|
+
if (count > 0) {
|
|
85
|
+
result.set((double) sum / count); // Compute average
|
|
86
|
+
context.write(new Text("Average Age of Died " + key), result);
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
// Case 2: Counting survivors in each class (key = "SurvivorClass <class>")
|
|
91
|
+
else if (key.toString().startsWith("SurvivorClass")) {
|
|
92
|
+
int sum = 0;
|
|
93
|
+
for (IntWritable val : values) {
|
|
94
|
+
sum += val.get(); // Count how many survivors in this class
|
|
95
|
+
}
|
|
96
|
+
result.set(sum); // Total survivors in this class
|
|
97
|
+
|
|
98
|
+
context.write(new Text(key), result);
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
driver.java
|
|
2
|
+
package earthquake;
|
|
3
|
+
import java.util.*;
|
|
4
|
+
import java.io.*;
|
|
5
|
+
import org.apache.hadoop.mapred.*;
|
|
6
|
+
import org.apache.hadoop.io.*;
|
|
7
|
+
|
|
8
|
+
import org.apache.hadoop.fs.Path;
|
|
9
|
+
|
|
10
|
+
public class driver
|
|
11
|
+
{
|
|
12
|
+
public static void main(String args[]) throws IOException
|
|
13
|
+
{
|
|
14
|
+
JobConf conf=new JobConf(driver.class);
|
|
15
|
+
conf.setMapperClass(mapper.class);
|
|
16
|
+
conf.setReducerClass(reducer.class);
|
|
17
|
+
conf.setOutputKeyClass(Text.class);
|
|
18
|
+
conf.setOutputValueClass(DoubleWritable.class);
|
|
19
|
+
FileInputFormat.addInputPath(conf, new Path(args[0]));
|
|
20
|
+
FileOutputFormat.setOutputPath(conf,new Path(args[1]));
|
|
21
|
+
JobClient.runJob(conf);
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
mapper.java
|
|
25
|
+
package earthquake;
|
|
26
|
+
import java.util.*;
|
|
27
|
+
import java.io.*;
|
|
28
|
+
import org.apache.hadoop.mapred.*;
|
|
29
|
+
import org.apache.hadoop.io.*;
|
|
30
|
+
public class mapper extends MapReduceBase implements Mapper<LongWritable, Text,Text,DoubleWritable>
|
|
31
|
+
{
|
|
32
|
+
public void map(LongWritable key , Text value , OutputCollector<Text,DoubleWritable> output, Reporter r) throws IOException
|
|
33
|
+
{
|
|
34
|
+
String[] line=value.toString().split(",");
|
|
35
|
+
Double longi=Double.parseDouble(line[7]);
|
|
36
|
+
output.collect(new Text(line[11]), new DoubleWritable(longi));
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
reducer.java
|
|
41
|
+
package earthquake;
|
|
42
|
+
import java.util.*;
|
|
43
|
+
import java.io.*;
|
|
44
|
+
import org.apache.hadoop.mapred.*;
|
|
45
|
+
import org.apache.hadoop.io.*;
|
|
46
|
+
class reducer extends MapReduceBase implements Reducer<Text,DoubleWritable,Text,DoubleWritable> {
|
|
47
|
+
|
|
48
|
+
public void reduce(Text key, Iterator<DoubleWritable> value, OutputCollector<Text,DoubleWritable> output, Reporter r) throws IOException
|
|
49
|
+
{
|
|
50
|
+
Double max=-9999.0;
|
|
51
|
+
while(value.hasNext())
|
|
52
|
+
{
|
|
53
|
+
Double temp=value.next().get();
|
|
54
|
+
max=Math.max(max,temp);
|
|
55
|
+
}
|
|
56
|
+
output.collect(new Text(key), new DoubleWritable(max));
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
}
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
driver.java
|
|
2
|
+
package sales;
|
|
3
|
+
import java.io.*;
|
|
4
|
+
import java.util.*;
|
|
5
|
+
import org.apache.hadoop.mapred.*;
|
|
6
|
+
import org.apache.hadoop.io.*;
|
|
7
|
+
import org.apache.hadoop.fs.Path;
|
|
8
|
+
|
|
9
|
+
public class driver
|
|
10
|
+
{
|
|
11
|
+
public static void main(String args[]) throws IOException
|
|
12
|
+
{
|
|
13
|
+
JobConf conf=new JobConf(driver.class);
|
|
14
|
+
conf.setMapperClass(mapper.class);
|
|
15
|
+
conf.setReducerClass(reducer.class);
|
|
16
|
+
conf.setOutputKeyClass(Text.class);
|
|
17
|
+
conf.setOutputValueClass(IntWritable.class);
|
|
18
|
+
FileInputFormat.addInputPath(conf, new Path(args[0]));
|
|
19
|
+
FileOutputFormat.setOutputPath(conf,new Path(args[1]));
|
|
20
|
+
JobClient.runJob(conf);
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
mapper.java
|
|
25
|
+
package sales;
|
|
26
|
+
import java.io.*;
|
|
27
|
+
import java.util.*;
|
|
28
|
+
import org.apache.hadoop.mapred.*;
|
|
29
|
+
import org.apache.hadoop.io.*;
|
|
30
|
+
|
|
31
|
+
public class mapper extends MapReduceBase implements Mapper<LongWritable , Text , Text , IntWritable>
|
|
32
|
+
{
|
|
33
|
+
public void map(LongWritable key,Text value,OutputCollector<Text,IntWritable> output,Reporter r) throws IOException
|
|
34
|
+
{
|
|
35
|
+
String[] line=value.toString().split(",");
|
|
36
|
+
int price=Integer.parseInt(line[2]);
|
|
37
|
+
String cardtype=line[3];
|
|
38
|
+
String Country=line[7];
|
|
39
|
+
output.collect(new Text("Country "+Country),new IntWritable(price));
|
|
40
|
+
output.collect(new Text("CardType "+cardtype),new IntWritable(1));
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
reducer.java
|
|
45
|
+
package sales;
|
|
46
|
+
|
|
47
|
+
import java.io.*;
|
|
48
|
+
import java.util.*;
|
|
49
|
+
import org.apache.hadoop.mapred.*;
|
|
50
|
+
import org.apache.hadoop.io.*;
|
|
51
|
+
|
|
52
|
+
public class reducer extends MapReduceBase implements Reducer<Text,IntWritable,Text,IntWritable>
|
|
53
|
+
{
|
|
54
|
+
public void reduce(Text key,Iterator<IntWritable> value,OutputCollector<Text,IntWritable> output ,Reporter r) throws IOException
|
|
55
|
+
{
|
|
56
|
+
int sum=0;
|
|
57
|
+
while(value.hasNext())
|
|
58
|
+
{
|
|
59
|
+
sum+=value.next().get();
|
|
60
|
+
}
|
|
61
|
+
output.collect(new Text(key),new IntWritable(sum));
|
|
62
|
+
}
|
|
63
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
from pyspark import SparkContext
|
|
2
|
+
|
|
3
|
+
# Initialize SparkContext
|
|
4
|
+
sc = SparkContext("local", "Word Character Count")
|
|
5
|
+
|
|
6
|
+
paragraph = """
|
|
7
|
+
This is the first line.
|
|
8
|
+
And this is the second line.
|
|
9
|
+
Here comes the third line.
|
|
10
|
+
"""
|
|
11
|
+
|
|
12
|
+
# Create an RDD (Resilient Distributed Dataset) from the paragraph
|
|
13
|
+
rdd = sc.parallelize(paragraph.split("\n"))
|
|
14
|
+
|
|
15
|
+
# Count the number of lines
|
|
16
|
+
num_lines = rdd.count()
|
|
17
|
+
print(f"Number of lines: {num_lines}")
|
|
18
|
+
|
|
19
|
+
# To count the number of characters for each word in the paragraph
|
|
20
|
+
# First, split the lines into words and then map each word to its length
|
|
21
|
+
word_lengths = rdd.flatMap(lambda line: line.split()) \ map(lambda word: (word, len(word)))
|
|
22
|
+
|
|
23
|
+
# Collect the results and print
|
|
24
|
+
word_lengths_result = word_lengths.collect()
|
|
25
|
+
for word, length in word_lengths_result:
|
|
26
|
+
print(f"Word: {word}, Length: {length}")
|
|
27
|
+
|
|
28
|
+
sc.stop()
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import sys
|
|
2
|
+
if(len(sys.argv)!=4):
|
|
3
|
+
print("Provide Input File and Output Directory")
|
|
4
|
+
sys.exit(0)
|
|
5
|
+
|
|
6
|
+
from pyspark import SparkContext
|
|
7
|
+
sc =SparkContext()
|
|
8
|
+
f = sc.textFile(sys.argv[1])
|
|
9
|
+
|
|
10
|
+
temp=f.map(lambda x: (int(x[15:19]),int(x[87:92])))
|
|
11
|
+
|
|
12
|
+
mini=temp.reduceByKey(lambda a,b:a if a<b else b)
|
|
13
|
+
mini.saveAsTextFile(sys.argv[2])
|
|
14
|
+
|
|
15
|
+
maxi=temp.reduceByKey(lambda a,b:a if a>b else b)
|
|
16
|
+
maxi.saveAsTextFile(sys.argv[3])
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import sys
|
|
2
|
+
from pyspark import SparkContext
|
|
3
|
+
|
|
4
|
+
if(len(sys.argv)!=4):
|
|
5
|
+
print("Provide Input File and Output Directory")
|
|
6
|
+
sys.exit(0)
|
|
7
|
+
|
|
8
|
+
sc =SparkContext()
|
|
9
|
+
f = sc.textFile(sys.argv[1])
|
|
10
|
+
|
|
11
|
+
# Construction building or Count of building
|
|
12
|
+
temp=f.map(lambda x: (x.split(',')[16],1))
|
|
13
|
+
data=temp.countByKey()
|
|
14
|
+
dd=sc.parallelize(data.items())
|
|
15
|
+
dd.saveAsTextFile(sys.argv[2])
|
|
16
|
+
|
|
17
|
+
# County name and its frequency
|
|
18
|
+
temp=f.map(lambda x: (x.split(',')[2],1))
|
|
19
|
+
data=temp.countByKey()
|
|
20
|
+
dd=sc.parallelize(data.items())
|
|
21
|
+
dd.saveAsTextFile(sys.argv[3])
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
crop_prod = LOAD 'Datasets/crop_production.csv' USING PigStorage(',') AS (State_Name:chararray, District_Name:chararray, Crop_Year:int, Season:chararray, Crop:chararray, Area:float, Production:float);
|
|
2
|
+
DESCRIBE crop_prod;
|
|
3
|
+
|
|
4
|
+
total_production = GROUP crop_prod BY Crop;
|
|
5
|
+
sum_production = FOREACH total_production GENERATE group AS Crop, SUM(crop_prod.Production) AS Total_Production;
|
|
6
|
+
DUMP sum_production;
|
|
7
|
+
|
|
8
|
+
grouped_by_crop_year = GROUP crop_prod BY (Crop, Crop_Year);
|
|
9
|
+
average_production = FOREACH grouped_by_crop_year GENERATE group.Crop AS Crop, group.Crop_Year AS Crop_Year, AVG(crop_prod.Production) AS Avg_Production;
|
|
10
|
+
DUMP average_production;
|
|
11
|
+
|
|
12
|
+
specific_state = FILTER crop_prod BY State_Name == ‘Karnataka’;
|
|
13
|
+
unique_crops = GROUP specific_state BY Crop;
|
|
14
|
+
DUMP unique_crops;
|
|
15
|
+
|
|
16
|
+
specific_year = FILTER crop_prod BY Crop_Year == 2010;
|
|
17
|
+
total_area = GROUP specific_year BY Crop;
|
|
18
|
+
sum_area = FOREACH total_area GENERATE group AS Crop, SUM(specific_year.Area) AS Total_Area;
|
|
19
|
+
DUMP sum_area;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
athletes = LOAD 'olympic_athletes.csv' USING PigStorage(',') AS (athlete_url: chararray, athlete_full_name: chararray, games_participations: int, first_game: chararray, athlete_year_birth: float, athlete_medals: chararray, bio: chararray);
|
|
2
|
+
hosts = LOAD 'olympic_hosts.csv' USING PigStorage(',') AS (game_slug: chararray, game_end_date: chararray, game_start_date: chararray, game_location: chararray, game_name: chararray, game_season: chararray, game_year: int);
|
|
3
|
+
DESCRIBE athletes;
|
|
4
|
+
DESCRIBE hosts;
|
|
5
|
+
|
|
6
|
+
tokyo_2020_athletes = FILTER athletes BY first_game == ‘Tokyo 2020’;
|
|
7
|
+
DUMP tokyo_2020_athletes;
|
|
8
|
+
|
|
9
|
+
games_in_china = FILTER hosts BY game_location == 'China';
|
|
10
|
+
DUMP games_in_china;
|
|
11
|
+
|
|
12
|
+
grouped_by_season = GROUP hosts BY game_season;
|
|
13
|
+
counted_by_season = FOREACH grouped_by_season GENERATE group AS game_season, COUNT(hosts) AS num_games;
|
|
14
|
+
DUMP counted_by_season;
|
|
15
|
+
|
|
16
|
+
games_after_2000 = FILTER hosts BY game_year > 2000;
|
|
17
|
+
DUMP games_after_2000;
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
raw_data = LOAD 'online-retail.csv' USING PigStorage(',')
|
|
2
|
+
AS (InvoiceNo:chararray, StockCode:chararray, Description:chararray,
|
|
3
|
+
Quantity:int, InvoiceDate:chararray, UnitPrice:float,
|
|
4
|
+
CustomerID:chararray, Country:chararray);
|
|
5
|
+
|
|
6
|
+
filtered_data = FILTER raw_data BY Country == 'United Kingdom';
|
|
7
|
+
unique_customers = DISTINCT (FOREACH filtered_data GENERATE CustomerID);
|
|
8
|
+
total_unique_customers = FOREACH (GROUP unique_customers ALL) GENERATE
|
|
9
|
+
COUNT(unique_customers) AS TotalUniqueCustomers;
|
|
10
|
+
DUMP total_unique_customers;
|
|
11
|
+
|
|
12
|
+
filtered_data = FILTER raw_data BY InvoiceDate == '2009';
|
|
13
|
+
grouped_by_invoice = GROUP filtered_data BY InvoiceNo;
|
|
14
|
+
total_invoices = FOREACH (GROUP grouped_by_invoice ALL) GENERATE
|
|
15
|
+
COUNT(grouped_by_invoice) AS TotalInvoices;
|
|
16
|
+
DUMP total_invoices;
|
|
17
|
+
|
|
18
|
+
france_data = FILTER raw_data BY Country == 'France';
|
|
19
|
+
france_revenue = FOREACH france_data GENERATE (Quantity * UnitPrice) AS Revenue;
|
|
20
|
+
total_revenue = FOREACH (GROUP france_revenue ALL) GENERATE SUM(france_revenue.Revenue) AS TotalRevenue;
|
|
21
|
+
DUMP total_revenue;
|
|
22
|
+
|
|
23
|
+
grouped_by_country = GROUP raw_data BY Country;
|
|
24
|
+
country_totals = FOREACH grouped_by_country GENERATE group AS Country,
|
|
25
|
+
SUM(raw_data.Quantity) AS TotalQuantity;
|
|
26
|
+
sorted_totals = ORDER country_totals BY TotalQuantity DESC;
|
|
27
|
+
max_country = LIMIT sorted_totals 1;
|
|
28
|
+
DUMP max_country;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
PIG
|
|
2
|
+
1. Verify that hadoop is installed and running in your system.
|
|
3
|
+
$ hadoop
|
|
4
|
+
2. Download Apache Pig from the given url inside your folder.
|
|
5
|
+
3. Now we extract this tar file with the help of below command (make sure to check your tar filename).
|
|
6
|
+
$ tar -xvf pig-0.17.0.tar.gz
|
|
7
|
+
4. Now navigate inside the folder using the below command.
|
|
8
|
+
$ cd pig-0.17.0/
|
|
9
|
+
5. Create and open a new bash.sh file inside the directory.
|
|
10
|
+
$ gedit bash.sh
|
|
11
|
+
6. We configure file, copy the below command inside this file and save it.
|
|
12
|
+
export PIG_INSTALL=$(pwd)
|
|
13
|
+
export PATH=$PATH:$(pwd)/bin
|
|
14
|
+
7. Execute the bash.sh File using following command
|
|
15
|
+
$ source bash.sh
|
|
16
|
+
8. You can check your pig version with the below command.
|
|
17
|
+
$ pig -version
|
|
18
|
+
9. Once you get it correct that’s it we have successfully install pig to our Hadoop single node setup, now we start pig with below pig command.
|
|
19
|
+
$ pig
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
Spark
|
|
2
|
+
1. Verify that hadoop is installed and running in your system.
|
|
3
|
+
$ hadoop
|
|
4
|
+
2. Download Apache Spark from the given url inside your folder.
|
|
5
|
+
3. Now we extract this tar file with the help of below command (make sure to check your tar filename).
|
|
6
|
+
$ tar xvzf spark-3.5.2-bin-hadoop3.tgz
|
|
7
|
+
4. Now navigate inside the folder using the below command.
|
|
8
|
+
$ cd spark-3.5.2-bin-hadoop3/
|
|
9
|
+
5. Create a new file named bash.sh inside your folder by using any text editor.
|
|
10
|
+
$ gedit bash.sh
|
|
11
|
+
6. Copy below code and paste inside bash.sh file
|
|
12
|
+
export PATH=$(echo $PATH):$(pwd)/bin
|
|
13
|
+
7. In terminal, execute bash.sh file using the following command.
|
|
14
|
+
$ source bash.sh
|
|
15
|
+
8. Verify spark version with the below command.
|
|
16
|
+
$ spark-shell --version
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: isl75lab
|
|
3
|
+
Version: 1.0.0
|
|
4
|
+
Summary: Print ISL75 Big Data Laboratory programs and setup instructions by question.
|
|
5
|
+
Requires-Python: >=3.9
|
|
6
|
+
Description-Content-Type: text/markdown
|
|
7
|
+
|
|
8
|
+
# ISL75 Big Data Laboratory
|
|
9
|
+
|
|
10
|
+
Look up any of the 12 programs from the ISL75 lab manual by part and question number. All source listings and the installation guide are bundled in the package, so lookups work offline.
|
|
11
|
+
|
|
12
|
+
## Installation
|
|
13
|
+
|
|
14
|
+
Use Python 3.9 or newer. To install a downloaded wheel, run this in the folder containing it:
|
|
15
|
+
|
|
16
|
+
```shell
|
|
17
|
+
python -m pip install ./isl75lab-1.0.0-py3-none-any.whl
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
Once the release is on PyPI, install it on another machine with `python -m pip install isl75lab`.
|
|
21
|
+
|
|
22
|
+
## Question lookup
|
|
23
|
+
|
|
24
|
+
```shell
|
|
25
|
+
isl75lab src
|
|
26
|
+
isl75lab src parta1
|
|
27
|
+
isl75lab src partb6
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
The first command lists all questions. Replace the part and number to print a program. The spaced form `isl75lab src parta 1` also works. If your shell cannot find the command, use `python -m isl75lab src parta1`.
|
|
31
|
+
|
|
32
|
+
| Question | Part A · Java MapReduce | Part B · Spark or Pig |
|
|
33
|
+
| --- | --- | --- |
|
|
34
|
+
| 1 | Word count | Lines and word lengths |
|
|
35
|
+
| 2 | Odd and even numbers | Weather reports |
|
|
36
|
+
| 3 | Employee statistics | Insurance statistics |
|
|
37
|
+
| 4 | Titanic passengers | Crop production |
|
|
38
|
+
| 5 | Earthquake statistics | Olympic athletes and hosts |
|
|
39
|
+
| 6 | Sales records | Online retail |
|
|
40
|
+
|
|
41
|
+
Part A prints the Java files together under the manual's filenames, with sample input where supplied alongside the code. Part B prints the Python or Pig source. The listings preserve the code as printed in the manual, including its syntax and typography. For example, the word-length expression in Part B question 1 contains a misplaced backslash in the original.
|
|
42
|
+
|
|
43
|
+
## Installation guide
|
|
44
|
+
|
|
45
|
+
```shell
|
|
46
|
+
isl75lab src howtorun
|
|
47
|
+
isl75lab src howtorun java
|
|
48
|
+
isl75lab src howtorun python
|
|
49
|
+
isl75lab src howtorun pig
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
The first command prints the complete installation guide. The Java selection covers Java and Hadoop. The Python selection adds the guide's Spark steps, and the Pig selection includes Java, Hadoop and Pig. These commands display the Linux setup instructions for you to follow on your lab machine.
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
README.md
|
|
2
|
+
pyproject.toml
|
|
3
|
+
src/isl75lab/__init__.py
|
|
4
|
+
src/isl75lab/__main__.py
|
|
5
|
+
src/isl75lab/cli.py
|
|
6
|
+
src/isl75lab.egg-info/PKG-INFO
|
|
7
|
+
src/isl75lab.egg-info/SOURCES.txt
|
|
8
|
+
src/isl75lab.egg-info/dependency_links.txt
|
|
9
|
+
src/isl75lab.egg-info/entry_points.txt
|
|
10
|
+
src/isl75lab.egg-info/top_level.txt
|
|
11
|
+
src/isl75lab/data/guide.txt
|
|
12
|
+
src/isl75lab/data/hadoop.txt
|
|
13
|
+
src/isl75lab/data/java.txt
|
|
14
|
+
src/isl75lab/data/parta1.txt
|
|
15
|
+
src/isl75lab/data/parta2.txt
|
|
16
|
+
src/isl75lab/data/parta3.txt
|
|
17
|
+
src/isl75lab/data/parta4.txt
|
|
18
|
+
src/isl75lab/data/parta5.txt
|
|
19
|
+
src/isl75lab/data/parta6.txt
|
|
20
|
+
src/isl75lab/data/partb1.txt
|
|
21
|
+
src/isl75lab/data/partb2.txt
|
|
22
|
+
src/isl75lab/data/partb3.txt
|
|
23
|
+
src/isl75lab/data/partb4.txt
|
|
24
|
+
src/isl75lab/data/partb5.txt
|
|
25
|
+
src/isl75lab/data/partb6.txt
|
|
26
|
+
src/isl75lab/data/pig.txt
|
|
27
|
+
src/isl75lab/data/spark.txt
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
isl75lab
|