bd-lab-1339 0.1.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.
- bd_lab_1339-0.1.0/PKG-INFO +80 -0
- bd_lab_1339-0.1.0/README.md +73 -0
- bd_lab_1339-0.1.0/pyproject.toml +27 -0
- bd_lab_1339-0.1.0/setup.cfg +4 -0
- bd_lab_1339-0.1.0/src/bd_lab_1339.egg-info/PKG-INFO +80 -0
- bd_lab_1339-0.1.0/src/bd_lab_1339.egg-info/SOURCES.txt +31 -0
- bd_lab_1339-0.1.0/src/bd_lab_1339.egg-info/dependency_links.txt +1 -0
- bd_lab_1339-0.1.0/src/bd_lab_1339.egg-info/entry_points.txt +2 -0
- bd_lab_1339-0.1.0/src/bd_lab_1339.egg-info/top_level.txt +1 -0
- bd_lab_1339-0.1.0/src/isl75_big_data_lab/__init__.py +1 -0
- bd_lab_1339-0.1.0/src/isl75_big_data_lab/__main__.py +44 -0
- bd_lab_1339-0.1.0/src/isl75_big_data_lab/lab/Dataset/A3. EmpDataset.csv +3 -0
- bd_lab_1339-0.1.0/src/isl75_big_data_lab/lab/Dataset/A4. Titanic.csv +6 -0
- bd_lab_1339-0.1.0/src/isl75_big_data_lab/lab/Dataset/B2. Weather.txt +3 -0
- bd_lab_1339-0.1.0/src/isl75_big_data_lab/lab/Dataset/B4. Crop_Production.csv +5 -0
- bd_lab_1339-0.1.0/src/isl75_big_data_lab/lab/Dataset/B5. olympic_athletes.csv +3 -0
- bd_lab_1339-0.1.0/src/isl75_big_data_lab/lab/Dataset/B5. olympic_host.csv +4 -0
- bd_lab_1339-0.1.0/src/isl75_big_data_lab/lab/Dataset/B6. online-retail.csv +5 -0
- bd_lab_1339-0.1.0/src/isl75_big_data_lab/lab/Dataset/numbers.txt +2 -0
- bd_lab_1339-0.1.0/src/isl75_big_data_lab/lab/Dataset/paragraph.txt +2 -0
- bd_lab_1339-0.1.0/src/isl75_big_data_lab/lab/Dataset/words.txt +2 -0
- bd_lab_1339-0.1.0/src/isl75_big_data_lab/lab/RUN.md +55 -0
- bd_lab_1339-0.1.0/src/isl75_big_data_lab/lab/hadoop/A1/WordCount.java +38 -0
- bd_lab_1339-0.1.0/src/isl75_big_data_lab/lab/hadoop/A2/OddEven.java +44 -0
- bd_lab_1339-0.1.0/src/isl75_big_data_lab/lab/hadoop/A3/Employee.java +42 -0
- bd_lab_1339-0.1.0/src/isl75_big_data_lab/lab/hadoop/A4/Titanic.java +50 -0
- bd_lab_1339-0.1.0/src/isl75_big_data_lab/lab/pig/B4/crops.pig +29 -0
- bd_lab_1339-0.1.0/src/isl75_big_data_lab/lab/pig/B5/olympics.pig +14 -0
- bd_lab_1339-0.1.0/src/isl75_big_data_lab/lab/pig/B5/prepare.py +15 -0
- bd_lab_1339-0.1.0/src/isl75_big_data_lab/lab/pig/B6/retail.pig +35 -0
- bd_lab_1339-0.1.0/src/isl75_big_data_lab/lab/run.sh +42 -0
- bd_lab_1339-0.1.0/src/isl75_big_data_lab/lab/spark/B1/lengths.py +14 -0
- bd_lab_1339-0.1.0/src/isl75_big_data_lab/lab/spark/B2/weather.py +22 -0
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: bd_lab_1339
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Nine ISL75 Big Data Lab exercises for Hadoop, Spark, and Pig
|
|
5
|
+
Requires-Python: >=3.9
|
|
6
|
+
Description-Content-Type: text/markdown
|
|
7
|
+
|
|
8
|
+
# ISL75 Big Data Lab
|
|
9
|
+
|
|
10
|
+
Nine complete exercise programs with small synthetic samples. The wheel
|
|
11
|
+
exports Java MapReduce, PySpark and Pig Latin sources to any writable
|
|
12
|
+
directory. See RUN.md in the exported folder for the Ubuntu run commands.
|
|
13
|
+
|
|
14
|
+
## 1. Build on Windows
|
|
15
|
+
|
|
16
|
+
Open PowerShell in this project folder and run:
|
|
17
|
+
|
|
18
|
+
~~~powershell
|
|
19
|
+
py -3.13 -m venv .venv
|
|
20
|
+
.\.venv\Scripts\python.exe -m pip install --upgrade build twine
|
|
21
|
+
.\.venv\Scripts\python.exe -m build
|
|
22
|
+
.\.venv\Scripts\python.exe -m twine check dist/*
|
|
23
|
+
~~~
|
|
24
|
+
|
|
25
|
+
On Ubuntu, use python3 -m venv .venv and .venv/bin/python in place of the
|
|
26
|
+
Windows paths. If Python 3.13 is unavailable on Windows, use py -3.
|
|
27
|
+
|
|
28
|
+
## 2. Try the local wheel
|
|
29
|
+
|
|
30
|
+
~~~powershell
|
|
31
|
+
.\.venv\Scripts\python.exe -m pip install .\dist\bd_lab_1339-0.1.0-py3-none-any.whl
|
|
32
|
+
.\.venv\Scripts\python.exe -m isl75_big_data_lab list
|
|
33
|
+
.\.venv\Scripts\python.exe -m isl75_big_data_lab export .\lab-programs
|
|
34
|
+
~~~
|
|
35
|
+
|
|
36
|
+
Use a fresh directory name each time you export. The installed
|
|
37
|
+
big-data-lab command does the same thing when the environment is active.
|
|
38
|
+
|
|
39
|
+
## 3. Publish
|
|
40
|
+
|
|
41
|
+
First confirm you can claim the distribution name. If it has already been
|
|
42
|
+
claimed by someone else, change project.name in pyproject.toml and rebuild
|
|
43
|
+
into an empty dist directory. For later releases, increment the version.
|
|
44
|
+
|
|
45
|
+
Create a TestPyPI account and token. Upload with:
|
|
46
|
+
|
|
47
|
+
~~~powershell
|
|
48
|
+
.\.venv\Scripts\python.exe -m twine upload --repository testpypi dist/*
|
|
49
|
+
~~~
|
|
50
|
+
|
|
51
|
+
Enter __token__ if prompted for a username and use the TestPyPI token when
|
|
52
|
+
prompted. Test with this command in a fresh virtual environment:
|
|
53
|
+
|
|
54
|
+
~~~bash
|
|
55
|
+
python -m pip install --index-url https://test.pypi.org/simple/ --no-deps bd_lab_1339
|
|
56
|
+
~~~
|
|
57
|
+
|
|
58
|
+
Create a separate account and token for the real PyPI. Publish with:
|
|
59
|
+
|
|
60
|
+
~~~powershell
|
|
61
|
+
.\.venv\Scripts\python.exe -m twine upload dist/*
|
|
62
|
+
~~~
|
|
63
|
+
|
|
64
|
+
Keep tokens out of the project and command history. See the
|
|
65
|
+
[Python Packaging User Guide](https://packaging.python.org/en/latest/tutorials/packaging-projects/).
|
|
66
|
+
|
|
67
|
+
## 4. Install from PyPI after publishing
|
|
68
|
+
|
|
69
|
+
In an active virtual environment:
|
|
70
|
+
|
|
71
|
+
~~~bash
|
|
72
|
+
python -m pip install bd_lab_1339
|
|
73
|
+
big-data-lab list
|
|
74
|
+
big-data-lab export ./lab-programs
|
|
75
|
+
cd lab-programs
|
|
76
|
+
bash run.sh A1
|
|
77
|
+
~~~
|
|
78
|
+
|
|
79
|
+
On Ubuntu use python3 in place of python if that is the interpreter name
|
|
80
|
+
in your environment. See RUN.md for all program commands and sample outputs.
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
# ISL75 Big Data Lab
|
|
2
|
+
|
|
3
|
+
Nine complete exercise programs with small synthetic samples. The wheel
|
|
4
|
+
exports Java MapReduce, PySpark and Pig Latin sources to any writable
|
|
5
|
+
directory. See RUN.md in the exported folder for the Ubuntu run commands.
|
|
6
|
+
|
|
7
|
+
## 1. Build on Windows
|
|
8
|
+
|
|
9
|
+
Open PowerShell in this project folder and run:
|
|
10
|
+
|
|
11
|
+
~~~powershell
|
|
12
|
+
py -3.13 -m venv .venv
|
|
13
|
+
.\.venv\Scripts\python.exe -m pip install --upgrade build twine
|
|
14
|
+
.\.venv\Scripts\python.exe -m build
|
|
15
|
+
.\.venv\Scripts\python.exe -m twine check dist/*
|
|
16
|
+
~~~
|
|
17
|
+
|
|
18
|
+
On Ubuntu, use python3 -m venv .venv and .venv/bin/python in place of the
|
|
19
|
+
Windows paths. If Python 3.13 is unavailable on Windows, use py -3.
|
|
20
|
+
|
|
21
|
+
## 2. Try the local wheel
|
|
22
|
+
|
|
23
|
+
~~~powershell
|
|
24
|
+
.\.venv\Scripts\python.exe -m pip install .\dist\bd_lab_1339-0.1.0-py3-none-any.whl
|
|
25
|
+
.\.venv\Scripts\python.exe -m isl75_big_data_lab list
|
|
26
|
+
.\.venv\Scripts\python.exe -m isl75_big_data_lab export .\lab-programs
|
|
27
|
+
~~~
|
|
28
|
+
|
|
29
|
+
Use a fresh directory name each time you export. The installed
|
|
30
|
+
big-data-lab command does the same thing when the environment is active.
|
|
31
|
+
|
|
32
|
+
## 3. Publish
|
|
33
|
+
|
|
34
|
+
First confirm you can claim the distribution name. If it has already been
|
|
35
|
+
claimed by someone else, change project.name in pyproject.toml and rebuild
|
|
36
|
+
into an empty dist directory. For later releases, increment the version.
|
|
37
|
+
|
|
38
|
+
Create a TestPyPI account and token. Upload with:
|
|
39
|
+
|
|
40
|
+
~~~powershell
|
|
41
|
+
.\.venv\Scripts\python.exe -m twine upload --repository testpypi dist/*
|
|
42
|
+
~~~
|
|
43
|
+
|
|
44
|
+
Enter __token__ if prompted for a username and use the TestPyPI token when
|
|
45
|
+
prompted. Test with this command in a fresh virtual environment:
|
|
46
|
+
|
|
47
|
+
~~~bash
|
|
48
|
+
python -m pip install --index-url https://test.pypi.org/simple/ --no-deps bd_lab_1339
|
|
49
|
+
~~~
|
|
50
|
+
|
|
51
|
+
Create a separate account and token for the real PyPI. Publish with:
|
|
52
|
+
|
|
53
|
+
~~~powershell
|
|
54
|
+
.\.venv\Scripts\python.exe -m twine upload dist/*
|
|
55
|
+
~~~
|
|
56
|
+
|
|
57
|
+
Keep tokens out of the project and command history. See the
|
|
58
|
+
[Python Packaging User Guide](https://packaging.python.org/en/latest/tutorials/packaging-projects/).
|
|
59
|
+
|
|
60
|
+
## 4. Install from PyPI after publishing
|
|
61
|
+
|
|
62
|
+
In an active virtual environment:
|
|
63
|
+
|
|
64
|
+
~~~bash
|
|
65
|
+
python -m pip install bd_lab_1339
|
|
66
|
+
big-data-lab list
|
|
67
|
+
big-data-lab export ./lab-programs
|
|
68
|
+
cd lab-programs
|
|
69
|
+
bash run.sh A1
|
|
70
|
+
~~~
|
|
71
|
+
|
|
72
|
+
On Ubuntu use python3 in place of python if that is the interpreter name
|
|
73
|
+
in your environment. See RUN.md for all program commands and sample outputs.
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["setuptools>=77"]
|
|
3
|
+
build-backend = "setuptools.build_meta"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "bd_lab_1339"
|
|
7
|
+
version = "0.1.0"
|
|
8
|
+
description = "Nine ISL75 Big Data Lab exercises for Hadoop, Spark, and Pig"
|
|
9
|
+
readme = "README.md"
|
|
10
|
+
requires-python = ">=3.9"
|
|
11
|
+
|
|
12
|
+
[project.scripts]
|
|
13
|
+
big-data-lab = "isl75_big_data_lab.__main__:main"
|
|
14
|
+
|
|
15
|
+
[tool.setuptools]
|
|
16
|
+
include-package-data = false
|
|
17
|
+
|
|
18
|
+
[tool.setuptools.packages.find]
|
|
19
|
+
where = ["src"]
|
|
20
|
+
namespaces = false
|
|
21
|
+
|
|
22
|
+
[tool.setuptools.package-data]
|
|
23
|
+
isl75_big_data_lab = [
|
|
24
|
+
"lab/*.md", "lab/*.sh", "lab/Dataset/*.csv", "lab/Dataset/*.txt",
|
|
25
|
+
"lab/hadoop/*/*.java", "lab/spark/*/*.py",
|
|
26
|
+
"lab/pig/*/*.pig", "lab/pig/*/*.py",
|
|
27
|
+
]
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: bd_lab_1339
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Nine ISL75 Big Data Lab exercises for Hadoop, Spark, and Pig
|
|
5
|
+
Requires-Python: >=3.9
|
|
6
|
+
Description-Content-Type: text/markdown
|
|
7
|
+
|
|
8
|
+
# ISL75 Big Data Lab
|
|
9
|
+
|
|
10
|
+
Nine complete exercise programs with small synthetic samples. The wheel
|
|
11
|
+
exports Java MapReduce, PySpark and Pig Latin sources to any writable
|
|
12
|
+
directory. See RUN.md in the exported folder for the Ubuntu run commands.
|
|
13
|
+
|
|
14
|
+
## 1. Build on Windows
|
|
15
|
+
|
|
16
|
+
Open PowerShell in this project folder and run:
|
|
17
|
+
|
|
18
|
+
~~~powershell
|
|
19
|
+
py -3.13 -m venv .venv
|
|
20
|
+
.\.venv\Scripts\python.exe -m pip install --upgrade build twine
|
|
21
|
+
.\.venv\Scripts\python.exe -m build
|
|
22
|
+
.\.venv\Scripts\python.exe -m twine check dist/*
|
|
23
|
+
~~~
|
|
24
|
+
|
|
25
|
+
On Ubuntu, use python3 -m venv .venv and .venv/bin/python in place of the
|
|
26
|
+
Windows paths. If Python 3.13 is unavailable on Windows, use py -3.
|
|
27
|
+
|
|
28
|
+
## 2. Try the local wheel
|
|
29
|
+
|
|
30
|
+
~~~powershell
|
|
31
|
+
.\.venv\Scripts\python.exe -m pip install .\dist\bd_lab_1339-0.1.0-py3-none-any.whl
|
|
32
|
+
.\.venv\Scripts\python.exe -m isl75_big_data_lab list
|
|
33
|
+
.\.venv\Scripts\python.exe -m isl75_big_data_lab export .\lab-programs
|
|
34
|
+
~~~
|
|
35
|
+
|
|
36
|
+
Use a fresh directory name each time you export. The installed
|
|
37
|
+
big-data-lab command does the same thing when the environment is active.
|
|
38
|
+
|
|
39
|
+
## 3. Publish
|
|
40
|
+
|
|
41
|
+
First confirm you can claim the distribution name. If it has already been
|
|
42
|
+
claimed by someone else, change project.name in pyproject.toml and rebuild
|
|
43
|
+
into an empty dist directory. For later releases, increment the version.
|
|
44
|
+
|
|
45
|
+
Create a TestPyPI account and token. Upload with:
|
|
46
|
+
|
|
47
|
+
~~~powershell
|
|
48
|
+
.\.venv\Scripts\python.exe -m twine upload --repository testpypi dist/*
|
|
49
|
+
~~~
|
|
50
|
+
|
|
51
|
+
Enter __token__ if prompted for a username and use the TestPyPI token when
|
|
52
|
+
prompted. Test with this command in a fresh virtual environment:
|
|
53
|
+
|
|
54
|
+
~~~bash
|
|
55
|
+
python -m pip install --index-url https://test.pypi.org/simple/ --no-deps bd_lab_1339
|
|
56
|
+
~~~
|
|
57
|
+
|
|
58
|
+
Create a separate account and token for the real PyPI. Publish with:
|
|
59
|
+
|
|
60
|
+
~~~powershell
|
|
61
|
+
.\.venv\Scripts\python.exe -m twine upload dist/*
|
|
62
|
+
~~~
|
|
63
|
+
|
|
64
|
+
Keep tokens out of the project and command history. See the
|
|
65
|
+
[Python Packaging User Guide](https://packaging.python.org/en/latest/tutorials/packaging-projects/).
|
|
66
|
+
|
|
67
|
+
## 4. Install from PyPI after publishing
|
|
68
|
+
|
|
69
|
+
In an active virtual environment:
|
|
70
|
+
|
|
71
|
+
~~~bash
|
|
72
|
+
python -m pip install bd_lab_1339
|
|
73
|
+
big-data-lab list
|
|
74
|
+
big-data-lab export ./lab-programs
|
|
75
|
+
cd lab-programs
|
|
76
|
+
bash run.sh A1
|
|
77
|
+
~~~
|
|
78
|
+
|
|
79
|
+
On Ubuntu use python3 in place of python if that is the interpreter name
|
|
80
|
+
in your environment. See RUN.md for all program commands and sample outputs.
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
README.md
|
|
2
|
+
pyproject.toml
|
|
3
|
+
src/bd_lab_1339.egg-info/PKG-INFO
|
|
4
|
+
src/bd_lab_1339.egg-info/SOURCES.txt
|
|
5
|
+
src/bd_lab_1339.egg-info/dependency_links.txt
|
|
6
|
+
src/bd_lab_1339.egg-info/entry_points.txt
|
|
7
|
+
src/bd_lab_1339.egg-info/top_level.txt
|
|
8
|
+
src/isl75_big_data_lab/__init__.py
|
|
9
|
+
src/isl75_big_data_lab/__main__.py
|
|
10
|
+
src/isl75_big_data_lab/lab/RUN.md
|
|
11
|
+
src/isl75_big_data_lab/lab/run.sh
|
|
12
|
+
src/isl75_big_data_lab/lab/Dataset/A3. EmpDataset.csv
|
|
13
|
+
src/isl75_big_data_lab/lab/Dataset/A4. Titanic.csv
|
|
14
|
+
src/isl75_big_data_lab/lab/Dataset/B2. Weather.txt
|
|
15
|
+
src/isl75_big_data_lab/lab/Dataset/B4. Crop_Production.csv
|
|
16
|
+
src/isl75_big_data_lab/lab/Dataset/B5. olympic_athletes.csv
|
|
17
|
+
src/isl75_big_data_lab/lab/Dataset/B5. olympic_host.csv
|
|
18
|
+
src/isl75_big_data_lab/lab/Dataset/B6. online-retail.csv
|
|
19
|
+
src/isl75_big_data_lab/lab/Dataset/numbers.txt
|
|
20
|
+
src/isl75_big_data_lab/lab/Dataset/paragraph.txt
|
|
21
|
+
src/isl75_big_data_lab/lab/Dataset/words.txt
|
|
22
|
+
src/isl75_big_data_lab/lab/hadoop/A1/WordCount.java
|
|
23
|
+
src/isl75_big_data_lab/lab/hadoop/A2/OddEven.java
|
|
24
|
+
src/isl75_big_data_lab/lab/hadoop/A3/Employee.java
|
|
25
|
+
src/isl75_big_data_lab/lab/hadoop/A4/Titanic.java
|
|
26
|
+
src/isl75_big_data_lab/lab/pig/B4/crops.pig
|
|
27
|
+
src/isl75_big_data_lab/lab/pig/B5/olympics.pig
|
|
28
|
+
src/isl75_big_data_lab/lab/pig/B5/prepare.py
|
|
29
|
+
src/isl75_big_data_lab/lab/pig/B6/retail.pig
|
|
30
|
+
src/isl75_big_data_lab/lab/spark/B1/lengths.py
|
|
31
|
+
src/isl75_big_data_lab/lab/spark/B2/weather.py
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
isl75_big_data_lab
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"""Installable ISL75 lab exercises."""
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import argparse
|
|
2
|
+
from importlib.resources import files
|
|
3
|
+
from pathlib import Path
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
def copy_tree(source, target):
|
|
7
|
+
target.mkdir()
|
|
8
|
+
for entry in source.iterdir():
|
|
9
|
+
if entry.name == '__pycache__':
|
|
10
|
+
continue
|
|
11
|
+
dest = target / entry.name
|
|
12
|
+
if entry.is_dir():
|
|
13
|
+
copy_tree(entry, dest)
|
|
14
|
+
else:
|
|
15
|
+
dest.write_bytes(entry.read_bytes())
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
def main():
|
|
19
|
+
parser = argparse.ArgumentParser(description="Access the ISL75 lab programs.")
|
|
20
|
+
commands = parser.add_subparsers(dest="command", required=True)
|
|
21
|
+
commands.add_parser("list", help="List the nine programs")
|
|
22
|
+
export = commands.add_parser("export", help="Copy programs and samples to a new folder")
|
|
23
|
+
export.add_argument("destination", type=Path)
|
|
24
|
+
args = parser.parse_args()
|
|
25
|
+
source = files("isl75_big_data_lab") / "lab"
|
|
26
|
+
|
|
27
|
+
if args.command == "list":
|
|
28
|
+
for folder in ("hadoop", "spark", "pig"):
|
|
29
|
+
for program in sorted((source / folder).iterdir(), key=lambda p: p.name):
|
|
30
|
+
names = ", ".join(sorted(entry.name for entry in program.iterdir() if entry.is_file()))
|
|
31
|
+
print(f"{program.name} {folder} {names}")
|
|
32
|
+
return
|
|
33
|
+
|
|
34
|
+
destination = args.destination.expanduser().resolve()
|
|
35
|
+
destination.parent.mkdir(parents=True, exist_ok=True)
|
|
36
|
+
try:
|
|
37
|
+
copy_tree(source, destination)
|
|
38
|
+
except FileExistsError:
|
|
39
|
+
parser.error(f"Destination already exists: {destination}")
|
|
40
|
+
print(f"Exported programs, sample data, and RUN.md to {destination}")
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
if __name__ == "__main__":
|
|
44
|
+
main()
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
000000000199999194200000000000000000000000000000000000000000000000000000000000000000000-00551
|
|
2
|
+
000000000299999194200000000000000000000000000000000000000000000000000000000000000000000+01111
|
|
3
|
+
000000000299999194200000000000000000000000000000000000000000000000000000000000000000000+00781
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
InvoiceNo,StockCode,Description,Quantity,InvoiceDate,UnitPrice,CustomerID,Country
|
|
2
|
+
100,A,Sample item,10,2009,2.50,C1,United Kingdom
|
|
3
|
+
100,B,Sample item,3,2009,4.00,C1,United Kingdom
|
|
4
|
+
101,A,Sample item,2,2009,3.50,C2,France
|
|
5
|
+
102,C,Sample item,4,2010,2.00,C3,United Kingdom
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
# Run the lab programs
|
|
2
|
+
|
|
3
|
+
Install the bundle with Python 3.9 or newer on Windows, macOS or Linux.
|
|
4
|
+
The commands below run the exercises from Bash on Ubuntu or WSL.
|
|
5
|
+
Use the Java/JDK matched to your course Hadoop, Spark and Pig installations.
|
|
6
|
+
Make these tools available on PATH as needed: javac, jar, hadoop,
|
|
7
|
+
spark-submit, python3 and pig. pip installs the source files and sample inputs.
|
|
8
|
+
|
|
9
|
+
From the exported folder:
|
|
10
|
+
|
|
11
|
+
~~~bash
|
|
12
|
+
bash run.sh A1
|
|
13
|
+
bash run.sh A2
|
|
14
|
+
bash run.sh A3
|
|
15
|
+
bash run.sh A4
|
|
16
|
+
bash run.sh B1
|
|
17
|
+
bash run.sh B2 1942
|
|
18
|
+
bash run.sh B4
|
|
19
|
+
bash run.sh B5
|
|
20
|
+
bash run.sh B6
|
|
21
|
+
~~~
|
|
22
|
+
|
|
23
|
+
The Hadoop runner uses local mode with file URLs. The Pig runner uses
|
|
24
|
+
local mode. Each run creates a fresh run-* directory.
|
|
25
|
+
|
|
26
|
+
## Use your course inputs
|
|
27
|
+
|
|
28
|
+
The bundled Dataset directory contains small invented samples. To use
|
|
29
|
+
the original course files, give the full path to your Dataset directory.
|
|
30
|
+
|
|
31
|
+
~~~bash
|
|
32
|
+
LAB_DATA_DIR="$HOME/Big_data_Lab_programs/Dataset" bash run.sh A3
|
|
33
|
+
LAB_DATA_DIR="$HOME/Big_data_Lab_programs/Dataset" bash run.sh B5
|
|
34
|
+
~~~
|
|
35
|
+
|
|
36
|
+
The override applies to every input for that command. For A1, A2 and B1
|
|
37
|
+
use the bundled inputs, or put custom words.txt, numbers.txt and
|
|
38
|
+
paragraph.txt in a directory of your choice and point LAB_DATA_DIR there.
|
|
39
|
+
|
|
40
|
+
## Sample results
|
|
41
|
+
|
|
42
|
+
| ID | Result to check |
|
|
43
|
+
|---|---|
|
|
44
|
+
| A1 | big 2, data 2, lab 1 |
|
|
45
|
+
| A2 | Sum 15, Odd 3, Even 2 |
|
|
46
|
+
| A3 | Female 2, average 210000.0. Male 1, average 60000.0. |
|
|
47
|
+
| A4 | Average death ages 22.0 male, 34.0 female, 28.0 overall. Each class has one survivor. |
|
|
48
|
+
| B1 | 2 lines. Word lengths in order are 3, 4, 3, 5, 2, 4. |
|
|
49
|
+
| B2 | 1942 minimum -5.5 C at 000001-99999 and maximum 11.1 C at 000002-99999. |
|
|
50
|
+
| B4 | Rice production 66, annual average 33, and 2010 area 15. Rice is the only Karnataka crop in the sample. |
|
|
51
|
+
| B5 | One Tokyo first-Games athlete, Beijing 2022 in China, one Summer and two Winter games, and two games after 2000. |
|
|
52
|
+
| B6 | 2 unique UK customers, 2 distinct 2009 invoices, France revenue 7.0, and United Kingdom 17 items. |
|
|
53
|
+
|
|
54
|
+
The Olympic query uses the first Games field provided by the athlete CSV.
|
|
55
|
+
The weather output identifies locations by station ID.
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import java.io.IOException;
|
|
2
|
+
import org.apache.hadoop.fs.Path;
|
|
3
|
+
import org.apache.hadoop.io.*;
|
|
4
|
+
import org.apache.hadoop.mapreduce.*;
|
|
5
|
+
import org.apache.hadoop.mapreduce.lib.input.FileInputFormat;
|
|
6
|
+
import org.apache.hadoop.mapreduce.lib.output.FileOutputFormat;
|
|
7
|
+
import org.apache.hadoop.util.GenericOptionsParser;
|
|
8
|
+
public class WordCount {
|
|
9
|
+
public static class M extends Mapper<LongWritable, Text, Text, Text> {
|
|
10
|
+
public void map(LongWritable offset, Text row, Context c)
|
|
11
|
+
throws IOException, InterruptedException {
|
|
12
|
+
for (String word : row.toString().split("\\s+"))
|
|
13
|
+
if (!word.isEmpty()) c.write(new Text(word), new Text("1"));
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
public static class R extends Reducer<Text, Text, Text, Text> {
|
|
17
|
+
public void reduce(Text key, Iterable<Text> values, Context c)
|
|
18
|
+
throws IOException, InterruptedException {
|
|
19
|
+
int count = 0;
|
|
20
|
+
for (Text one : values) count++;
|
|
21
|
+
c.write(key, new Text("" + count));
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
public static void main(String[] args) throws Exception {
|
|
25
|
+
Job job = Job.getInstance();
|
|
26
|
+
args = new GenericOptionsParser(job.getConfiguration(), args)
|
|
27
|
+
.getRemainingArgs();
|
|
28
|
+
job.setJarByClass(WordCount.class);
|
|
29
|
+
job.setMapperClass(M.class);
|
|
30
|
+
job.setReducerClass(R.class);
|
|
31
|
+
job.setNumReduceTasks(1);
|
|
32
|
+
job.setOutputKeyClass(Text.class);
|
|
33
|
+
job.setOutputValueClass(Text.class);
|
|
34
|
+
FileInputFormat.addInputPath(job, new Path(args[0]));
|
|
35
|
+
FileOutputFormat.setOutputPath(job, new Path(args[1]));
|
|
36
|
+
System.exit(job.waitForCompletion(true) ? 0 : 1);
|
|
37
|
+
}
|
|
38
|
+
}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import java.io.IOException;
|
|
2
|
+
import org.apache.hadoop.fs.Path;
|
|
3
|
+
import org.apache.hadoop.io.*;
|
|
4
|
+
import org.apache.hadoop.mapreduce.*;
|
|
5
|
+
import org.apache.hadoop.mapreduce.lib.input.FileInputFormat;
|
|
6
|
+
import org.apache.hadoop.mapreduce.lib.output.FileOutputFormat;
|
|
7
|
+
import org.apache.hadoop.util.GenericOptionsParser;
|
|
8
|
+
public class OddEven {
|
|
9
|
+
public static class M extends Mapper<LongWritable, Text, Text, Text> {
|
|
10
|
+
public void map(LongWritable offset, Text row, Context c)
|
|
11
|
+
throws IOException, InterruptedException {
|
|
12
|
+
for (String n : row.toString().split("\\s+"))
|
|
13
|
+
if (!n.isEmpty()) c.write(new Text("numbers"), new Text(n));
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
public static class R extends Reducer<Text, Text, Text, Text> {
|
|
17
|
+
public void reduce(Text key, Iterable<Text> values, Context c)
|
|
18
|
+
throws IOException, InterruptedException {
|
|
19
|
+
long sum = 0, odd = 0, even = 0;
|
|
20
|
+
for (Text value : values) {
|
|
21
|
+
long n = Long.parseLong(value.toString());
|
|
22
|
+
sum += n;
|
|
23
|
+
if (n % 2 == 0) even++; else odd++;
|
|
24
|
+
}
|
|
25
|
+
c.write(new Text("Sum"), new Text("" + sum));
|
|
26
|
+
c.write(new Text("Odd"), new Text("" + odd));
|
|
27
|
+
c.write(new Text("Even"), new Text("" + even));
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
public static void main(String[] args) throws Exception {
|
|
31
|
+
Job job = Job.getInstance();
|
|
32
|
+
args = new GenericOptionsParser(job.getConfiguration(), args)
|
|
33
|
+
.getRemainingArgs();
|
|
34
|
+
job.setJarByClass(OddEven.class);
|
|
35
|
+
job.setMapperClass(M.class);
|
|
36
|
+
job.setReducerClass(R.class);
|
|
37
|
+
job.setNumReduceTasks(1);
|
|
38
|
+
job.setOutputKeyClass(Text.class);
|
|
39
|
+
job.setOutputValueClass(Text.class);
|
|
40
|
+
FileInputFormat.addInputPath(job, new Path(args[0]));
|
|
41
|
+
FileOutputFormat.setOutputPath(job, new Path(args[1]));
|
|
42
|
+
System.exit(job.waitForCompletion(true) ? 0 : 1);
|
|
43
|
+
}
|
|
44
|
+
}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import java.io.IOException;
|
|
2
|
+
import org.apache.hadoop.fs.Path;
|
|
3
|
+
import org.apache.hadoop.io.*;
|
|
4
|
+
import org.apache.hadoop.mapreduce.*;
|
|
5
|
+
import org.apache.hadoop.mapreduce.lib.input.FileInputFormat;
|
|
6
|
+
import org.apache.hadoop.mapreduce.lib.output.FileOutputFormat;
|
|
7
|
+
import org.apache.hadoop.util.GenericOptionsParser;
|
|
8
|
+
public class Employee {
|
|
9
|
+
public static class M extends Mapper<LongWritable, Text, Text, Text> {
|
|
10
|
+
public void map(LongWritable offset, Text row, Context c)
|
|
11
|
+
throws IOException, InterruptedException {
|
|
12
|
+
String[] f = row.toString().split(",");
|
|
13
|
+
if (f.length >= 5) c.write(new Text(f[3]), new Text(f[4]));
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
public static class R extends Reducer<Text, Text, Text, Text> {
|
|
17
|
+
public void reduce(Text key, Iterable<Text> values, Context c)
|
|
18
|
+
throws IOException, InterruptedException {
|
|
19
|
+
double sum = 0;
|
|
20
|
+
int count = 0;
|
|
21
|
+
for (Text salary : values) {
|
|
22
|
+
sum += Double.parseDouble(salary.toString());
|
|
23
|
+
count++;
|
|
24
|
+
}
|
|
25
|
+
c.write(key, new Text(count + "\t" + sum / count));
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
public static void main(String[] args) throws Exception {
|
|
29
|
+
Job job = Job.getInstance();
|
|
30
|
+
args = new GenericOptionsParser(job.getConfiguration(), args)
|
|
31
|
+
.getRemainingArgs();
|
|
32
|
+
job.setJarByClass(Employee.class);
|
|
33
|
+
job.setMapperClass(M.class);
|
|
34
|
+
job.setReducerClass(R.class);
|
|
35
|
+
job.setNumReduceTasks(1);
|
|
36
|
+
job.setOutputKeyClass(Text.class);
|
|
37
|
+
job.setOutputValueClass(Text.class);
|
|
38
|
+
FileInputFormat.addInputPath(job, new Path(args[0]));
|
|
39
|
+
FileOutputFormat.setOutputPath(job, new Path(args[1]));
|
|
40
|
+
System.exit(job.waitForCompletion(true) ? 0 : 1);
|
|
41
|
+
}
|
|
42
|
+
}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import java.io.IOException;
|
|
2
|
+
import org.apache.hadoop.fs.Path;
|
|
3
|
+
import org.apache.hadoop.io.*;
|
|
4
|
+
import org.apache.hadoop.mapreduce.*;
|
|
5
|
+
import org.apache.hadoop.mapreduce.lib.input.FileInputFormat;
|
|
6
|
+
import org.apache.hadoop.mapreduce.lib.output.FileOutputFormat;
|
|
7
|
+
import org.apache.hadoop.util.GenericOptionsParser;
|
|
8
|
+
public class Titanic {
|
|
9
|
+
public static class M extends Mapper<LongWritable, Text, Text, Text> {
|
|
10
|
+
public void map(LongWritable offset, Text row, Context c)
|
|
11
|
+
throws IOException, InterruptedException {
|
|
12
|
+
String[] f = row.toString().split(",", -1);
|
|
13
|
+
if (f.length < 6) return;
|
|
14
|
+
if (f[1].equals("1"))
|
|
15
|
+
c.write(new Text("Class " + f[2]), new Text("1"));
|
|
16
|
+
if (f[1].equals("0") && !f[5].isEmpty()) {
|
|
17
|
+
c.write(new Text("Age " + f[4]), new Text(f[5]));
|
|
18
|
+
c.write(new Text("Age all"), new Text(f[5]));
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
public static class R extends Reducer<Text, Text, Text, Text> {
|
|
23
|
+
public void reduce(Text key, Iterable<Text> values, Context c)
|
|
24
|
+
throws IOException, InterruptedException {
|
|
25
|
+
double sum = 0;
|
|
26
|
+
int count = 0;
|
|
27
|
+
for (Text v : values) {
|
|
28
|
+
sum += Double.parseDouble(v.toString());
|
|
29
|
+
count++;
|
|
30
|
+
}
|
|
31
|
+
String result = key.toString().startsWith("Age")
|
|
32
|
+
? "" + sum / count : "" + count;
|
|
33
|
+
c.write(key, new Text(result));
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
public static void main(String[] args) throws Exception {
|
|
37
|
+
Job job = Job.getInstance();
|
|
38
|
+
args = new GenericOptionsParser(job.getConfiguration(), args)
|
|
39
|
+
.getRemainingArgs();
|
|
40
|
+
job.setJarByClass(Titanic.class);
|
|
41
|
+
job.setMapperClass(M.class);
|
|
42
|
+
job.setReducerClass(R.class);
|
|
43
|
+
job.setNumReduceTasks(1);
|
|
44
|
+
job.setOutputKeyClass(Text.class);
|
|
45
|
+
job.setOutputValueClass(Text.class);
|
|
46
|
+
FileInputFormat.addInputPath(job, new Path(args[0]));
|
|
47
|
+
FileOutputFormat.setOutputPath(job, new Path(args[1]));
|
|
48
|
+
System.exit(job.waitForCompletion(true) ? 0 : 1);
|
|
49
|
+
}
|
|
50
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
C = LOAD 'crops.csv' USING PigStorage(',')
|
|
2
|
+
AS (state:chararray, district:chararray, yr:int, season:chararray,
|
|
3
|
+
crop:chararray, area:double, production:double);
|
|
4
|
+
|
|
5
|
+
-- 1. Total production by crop
|
|
6
|
+
P = FILTER C BY yr IS NOT NULL AND production IS NOT NULL;
|
|
7
|
+
G = GROUP P BY crop;
|
|
8
|
+
Total = FOREACH G GENERATE group, SUM(P.production);
|
|
9
|
+
DUMP Total;
|
|
10
|
+
|
|
11
|
+
-- 2. Sum by crop and year, then average the yearly totals
|
|
12
|
+
Y = GROUP P BY (crop, yr);
|
|
13
|
+
Yearly = FOREACH Y GENERATE group.crop AS crop,
|
|
14
|
+
SUM(P.production) AS annual;
|
|
15
|
+
G = GROUP Yearly BY crop;
|
|
16
|
+
Average = FOREACH G GENERATE group, AVG(Yearly.annual);
|
|
17
|
+
DUMP Average;
|
|
18
|
+
|
|
19
|
+
-- 3. Crop names grown in Karnataka
|
|
20
|
+
K = FILTER C BY state == 'Karnataka';
|
|
21
|
+
Names = FOREACH K GENERATE crop;
|
|
22
|
+
UniqueCrops = DISTINCT Names;
|
|
23
|
+
DUMP UniqueCrops;
|
|
24
|
+
|
|
25
|
+
-- 4. Total area by crop in 2010
|
|
26
|
+
A = FILTER C BY yr == 2010;
|
|
27
|
+
G = GROUP A BY crop;
|
|
28
|
+
Area2010 = FOREACH G GENERATE group, SUM(A.area);
|
|
29
|
+
DUMP Area2010;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
A = LOAD 'athletes.tsv' USING PigStorage('\t')
|
|
2
|
+
AS (url:chararray, athlete:chararray, first_game:chararray);
|
|
3
|
+
H = LOAD 'hosts.tsv' USING PigStorage('\t')
|
|
4
|
+
AS (game:chararray, country:chararray, season:chararray, yr:int);
|
|
5
|
+
|
|
6
|
+
Tokyo = FILTER A BY first_game == 'Tokyo 2020';
|
|
7
|
+
DUMP Tokyo;
|
|
8
|
+
China = FILTER H BY country == 'China';
|
|
9
|
+
DUMP China;
|
|
10
|
+
G = GROUP H BY season;
|
|
11
|
+
SeasonCounts = FOREACH G GENERATE group, COUNT(H);
|
|
12
|
+
DUMP SeasonCounts;
|
|
13
|
+
Recent = FILTER H BY yr > 2000;
|
|
14
|
+
DUMP Recent;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import csv
|
|
2
|
+
import sys
|
|
3
|
+
from pathlib import Path
|
|
4
|
+
|
|
5
|
+
folder = Path(sys.argv[1])
|
|
6
|
+
for file, out, fields in [
|
|
7
|
+
("B5. olympic_athletes.csv", "athletes.tsv", (0, 1, 3)),
|
|
8
|
+
("B5. olympic_host.csv", "hosts.tsv", (4, 3, 5, 6)),
|
|
9
|
+
]:
|
|
10
|
+
with (folder / file).open(encoding="utf-8-sig", newline="") as src:
|
|
11
|
+
with open(out, "w", encoding="utf-8") as dst:
|
|
12
|
+
rows = csv.reader(src)
|
|
13
|
+
next(rows)
|
|
14
|
+
for row in rows:
|
|
15
|
+
print(*(row[i] for i in fields), sep="\t", file=dst)
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
R = LOAD 'retail.csv' USING PigStorage(',')
|
|
2
|
+
AS (invoice:chararray, stock:chararray, description:chararray,
|
|
3
|
+
qty:int, yr:int, price:double, customer:chararray,
|
|
4
|
+
country:chararray);
|
|
5
|
+
|
|
6
|
+
-- 1. Count distinct UK customer IDs
|
|
7
|
+
UK = FILTER R BY country == 'United Kingdom'
|
|
8
|
+
AND customer IS NOT NULL AND customer != '';
|
|
9
|
+
IDs = FOREACH UK GENERATE customer;
|
|
10
|
+
UniqueIDs = DISTINCT IDs;
|
|
11
|
+
G = GROUP UniqueIDs ALL;
|
|
12
|
+
UKCount = FOREACH G GENERATE COUNT(UniqueIDs);
|
|
13
|
+
DUMP UKCount;
|
|
14
|
+
|
|
15
|
+
-- 2. Count distinct invoice numbers in 2009
|
|
16
|
+
Y = FILTER R BY yr == 2009;
|
|
17
|
+
Invoices = FOREACH Y GENERATE invoice;
|
|
18
|
+
UniqueBills = DISTINCT Invoices;
|
|
19
|
+
G = GROUP UniqueBills ALL;
|
|
20
|
+
BillCount = FOREACH G GENERATE COUNT(UniqueBills);
|
|
21
|
+
DUMP BillCount;
|
|
22
|
+
|
|
23
|
+
-- 3. Sum quantity times unit price for France
|
|
24
|
+
F = FILTER R BY country == 'France';
|
|
25
|
+
Amounts = FOREACH F GENERATE qty * price AS revenue;
|
|
26
|
+
G = GROUP Amounts ALL;
|
|
27
|
+
FranceRevenue = FOREACH G GENERATE SUM(Amounts.revenue);
|
|
28
|
+
DUMP FranceRevenue;
|
|
29
|
+
|
|
30
|
+
-- 4. Sum quantities by country and take the top country
|
|
31
|
+
G = GROUP R BY country;
|
|
32
|
+
Totals = FOREACH G GENERATE group AS country, SUM(R.qty) AS items;
|
|
33
|
+
Ranked = ORDER Totals BY items DESC, country ASC;
|
|
34
|
+
Top = LIMIT Ranked 1;
|
|
35
|
+
DUMP Top;
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
#!/usr/bin/env bash
|
|
2
|
+
set -euo pipefail
|
|
3
|
+
cd -- "$(dirname -- "$0")"
|
|
4
|
+
data=$(cd -- "${LAB_DATA_DIR:-Dataset}" && pwd)
|
|
5
|
+
work=$(mktemp -d "$PWD/run-${1:-lab}-XXXXXX")
|
|
6
|
+
echo "Run directory: $work"
|
|
7
|
+
|
|
8
|
+
case "${1:-}" in
|
|
9
|
+
A1) main=WordCount; input=words.txt ;;
|
|
10
|
+
A2) main=OddEven; input=numbers.txt ;;
|
|
11
|
+
A3) main=Employee; input='A3. EmpDataset.csv' ;;
|
|
12
|
+
A4) main=Titanic; input='A4. Titanic.csv' ;;
|
|
13
|
+
B1)
|
|
14
|
+
spark-submit --master 'local[*]' spark/B1/lengths.py "file://$data/paragraph.txt"
|
|
15
|
+
exit ;;
|
|
16
|
+
B2)
|
|
17
|
+
spark-submit --master 'local[*]' spark/B2/weather.py "file://$data/B2. Weather.txt" "${2:-1942}"
|
|
18
|
+
exit ;;
|
|
19
|
+
B4)
|
|
20
|
+
tail -n +2 "$data/B4. Crop_Production.csv" > "$work/crops.csv"
|
|
21
|
+
cd "$work"
|
|
22
|
+
pig -x local ../pig/B4/crops.pig
|
|
23
|
+
exit ;;
|
|
24
|
+
B5)
|
|
25
|
+
cd "$work"
|
|
26
|
+
python3 ../pig/B5/prepare.py "$data"
|
|
27
|
+
pig -x local ../pig/B5/olympics.pig
|
|
28
|
+
exit ;;
|
|
29
|
+
B6)
|
|
30
|
+
tail -n +2 "$data/B6. online-retail.csv" > "$work/retail.csv"
|
|
31
|
+
cd "$work"
|
|
32
|
+
pig -x local ../pig/B6/retail.pig
|
|
33
|
+
exit ;;
|
|
34
|
+
*) echo 'Usage: bash run.sh A1|A2|A3|A4|B1|B2|B4|B5|B6 [weather-year]' >&2; exit 2 ;;
|
|
35
|
+
esac
|
|
36
|
+
|
|
37
|
+
mkdir "$work/classes"
|
|
38
|
+
javac -cp "$(hadoop classpath --glob)" -d "$work/classes" "hadoop/$1/$main.java"
|
|
39
|
+
jar cf "$work/$main.jar" -C "$work/classes" .
|
|
40
|
+
hadoop jar "$work/$main.jar" "$main" -D mapreduce.framework.name=local \
|
|
41
|
+
"file://$data/$input" "file://$work/output"
|
|
42
|
+
cat "$work"/output/part-r-*
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import re
|
|
2
|
+
import sys
|
|
3
|
+
from pyspark import SparkContext
|
|
4
|
+
|
|
5
|
+
sc = SparkContext(appName="WordLengths")
|
|
6
|
+
sc.setLogLevel("ERROR")
|
|
7
|
+
lines = sc.textFile(sys.argv[1])
|
|
8
|
+
|
|
9
|
+
print("Lines:", lines.count())
|
|
10
|
+
words = lines.flatMap(lambda line: re.findall(r"\b\w+\b", line))
|
|
11
|
+
for word, length in words.map(lambda w: (w, len(w))).collect():
|
|
12
|
+
print(word, length)
|
|
13
|
+
|
|
14
|
+
sc.stop()
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import sys
|
|
2
|
+
from pyspark import SparkContext
|
|
3
|
+
|
|
4
|
+
sc = SparkContext(appName="Weather")
|
|
5
|
+
sc.setLogLevel("ERROR")
|
|
6
|
+
path, year = sys.argv[1:3]
|
|
7
|
+
rows = sc.textFile(path).filter(
|
|
8
|
+
lambda s: len(s) >= 93 and s[15:19] == year
|
|
9
|
+
and s[92] in "01459" and s[87:92] != "+9999")
|
|
10
|
+
data = rows.map(lambda s: (int(s[87:92]), s[4:10] + "-" + s[10:15]))
|
|
11
|
+
data.cache()
|
|
12
|
+
|
|
13
|
+
if data.isEmpty():
|
|
14
|
+
print("No valid observations for", year)
|
|
15
|
+
else:
|
|
16
|
+
low, high = data.keys().min(), data.keys().max()
|
|
17
|
+
for label, temp in [("Minimum", low), ("Maximum", high)]:
|
|
18
|
+
stations = data.filter(lambda x: x[0] == temp)
|
|
19
|
+
ids = sorted(stations.values().distinct().collect())
|
|
20
|
+
print(year, label, temp / 10, "C", ", ".join(ids))
|
|
21
|
+
|
|
22
|
+
sc.stop()
|