Post

GCP Lab: Analyzing WTA Match Data with Hadoop MapReduce

GCP Lab: Analyzing WTA Match Data with Hadoop MapReduce

As part of CSE 3244: Data Management in the Cloud at The Ohio State University, I used Google Cloud Platform (GCP) to provision a Linux VM, ran a containerized Hadoop environment on it, and used a Java MapReduce job to count WTA (ITF-sanctioned tournament) match wins by player and by country.

External IP addresses and the shell username in the screenshots are masked.


1. Project Goals

  • Get comfortable using a public cloud (Google Cloud Platform)
  • Create and provision compute instances and disks (I/O) myself
  • Work with and preprocess a large dataset
  • Use MapReduce to extract structure (meaningful aggregates) from text data
  • Run MapReduce jobs from the command line

The task: count wins per player and per country from WTA match CSV files. The trick is that the tournament ID contains the host country (for example, 2015-W-C50-USA-02A-2015 → USA).


2. Architecture

1
2
3
4
5
GCP Compute Engine VM (Ubuntu 20.04 · 4 vCPU · 16 GB · 50 GB)
└── Docker
    └── Cloudera QuickStart container (Hadoop + HDFS)
        ├── HDFS /tennis            <- CSV files uploaded here
        └── Java MapReduce CountWins -> results in /tennis.CountWins

The VM’s ~/tmp folder is mounted into the container as /src, so the code and data downloaded on the VM can be used inside the container as-is.


3. Technologies Used

AreaTechnologyWhat I did with it
CloudGCP Compute EngineCreated a project, created and sized a VM, connected with browser SSH, suspended and deleted the VM
OSUbuntu 20.04 LTSHost OS; installed Docker with apt
ContainerDocker (docker.io)pull the image, check its ID with images, run (volume mount -v, --privileged), ps, attach
Big data platformCloudera QuickStartRan a single-node environment with Hadoop and HDFS preinstalled, as a container
Distributed file systemHDFSLoaded and inspected data with hdfs dfs -mkdir / -put / -ls / -cat / -rm -r
Processing modelHadoop MapReduceRan the per-player, per-country win count job
LanguageJava (JDK 1.7)Compiled with Hadoop’s built-in compiler and packaged with jar
ShellLinux Bashwget, tar, environment variables (JAVA_HOME, HADOOP_CLASSPATH)

4. Steps (with Screenshots)

Task 1 · Set Up GCP and Cloudera QuickStart

Step 1. Create a GCP project. Create a new project in the console. The project ID cannot be changed later.

GCP New Project form with project name CSE3244-project Figure 1. Creating a new project (CSE3244-project)

Step 2. Create a VM instance. Compute Engine → Create Instance. Choose the e2-standard-4 machine type (4 vCPU, 16 GB). The estimated monthly cost is shown on the right.

Create an instance page with e2-standard-4 selected and a monthly estimate of $98.84 Figure 2. Choosing the machine type (region us-central1, e2-standard-4)

Instead of the default boot disk, choose Ubuntu 20.04 LTS and set the size to 50 GB.

Boot disk panel with Ubuntu 20.04 LTS, balanced persistent disk, 50 GB Figure 3. Boot disk settings (Ubuntu 20.04 LTS, Balanced persistent disk, 50 GB)

Step 3. Connect with SSH. Click SSH next to the instance in the VM list to open a terminal in the browser. The internal and external IPs are also shown here.

VM instances list showing instance-1 with internal IP, masked external IP, and SSH button Figure 4. VM instance list and the SSH button

Step 4. Install Docker. Run sudo apt update, then sudo apt install docker.io.

Terminal output of sudo apt install docker.io Figure 5. Installing docker.io (dependencies such as containerd and runc are installed with it)

Step 5. Download the Cloudera QuickStart image. It is about 4.4 GB, so it takes a few minutes. Docker warns that the image uses an outdated (schema1) format.

Terminal output of docker pull cloudera/quickstart:latest with schema1 warning Figure 6. docker pull cloudera/quickstart:latest

Step 6. Check the image ID. sudo docker images shows the image ID (4239cd2958c6). This value goes into the container run command.

Terminal output of sudo docker images showing cloudera/quickstart, image ID 4239cd2958c6, 6.34GB Figure 7. docker images output (6.34 GB)

Steps 7–8. Download code and data, then run the container. Download gcplab.tar.xz into ~/tmp, extract it, and run the container with -v ~/tmp:/src to mount it.

Step 9. Detach, reattach, and exit. Detach with Ctrl+P → Ctrl+Q, find the container ID with docker ps, and get back in with docker attach. The output also shows the container’s web ports (80, 7180, 8888) mapped to VM ports.

Terminal output of docker ps and docker attach with port mappings Figure 8. docker ps and docker attach

To stop the VM, open the instance’s three-dot menu and choose Suspend or Delete.

VM instance menu with Stop, Suspend, Reset, and Delete options Figure 9. VM menu (Stop · Suspend · Reset · Delete)

Task 2 · Run the MapReduce Program

  • Understand the domain: tennis, the ITF, the WTA tour structure, and the tournament naming rules
  • Upload the CSV files to HDFS /tennis
  • Compile CountWins.java → build a jar → delete the old output folder → run the job
  • Check the top 20 lines of the result file part-r-00000 and submit
  • Bonus task: change the map function to aggregate by player name instead of player ID

Key commands

1
2
3
4
5
6
7
8
9
10
11
$ sudo docker run --hostname=quickstart.cloudera --privileged=true \
    -t -i -v ~/tmp:/src <image-id> /usr/bin/docker-quickstart -d

$ hdfs dfs -mkdir /tennis
$ hdfs dfs -put wta_matches_qual_itf_* /tennis

$ hadoop com.sun.tools.javac.Main -Xlint:deprecation CountWins.java
$ jar cf cw.jar CountWins*class
$ hdfs dfs -rm -r /tennis.CountWins
$ hadoop jar cw.jar CountWins /tennis /tennis.CountWins
$ hdfs dfs -cat /tennis.CountWins/part-r-00000 | head -n 20

5. Results

Task 2 Result · Wins by Player ID × Country (Top 20 Lines)

The output format is player ID, country, wins. For example, 200002,USA,63 means player 200002 won 63 matches at tournaments held in the USA.

Submitted result file: top 20 lines of player ID, country, win counts, followed by the modified map function for the extra credit Figure 10. Submitted result file — top 20 lines of part-r-00000, followed by the extra-credit map function

Player IDCountryWinsPlayer IDCountryWins
200002AUS3200002NZL1
200002BAH1200002QAT2
200002CAN7200002SWE1
200002ESP2200002UAE2
200002FRA15200002USA63
200002GBR13200008AUS3
200002GER4200008ESP3
200002ITA8200008ITA1
200002JPN3200008UAE2
200002NA11200009CHN6
  • Within the top 20 lines, player 200002’s 63 wins in the USA is the highest count.
  • NA means the country code could not be extracted from the tournament ID. If splitting the ID on - gives fewer than 4 pieces, the country is set to NA.

Bonus Task · Changing the Map Function to Aggregate by Player Name

I changed the map function to use the 11th CSV column (cur_lst[10], the winner’s name) as the key.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
public void map(LongWritable cur_key, Text cur_val, Context cur_out)
        throws IOException, InterruptedException {
    String cur_lne = cur_val.toString();
    String[] cur_lst = cur_lne.split(",",0);
    String[] cur_wta = cur_lst[0].split("-",0); // First element is the tournament ID
    String country = "NA";
    if (cur_wta.length > 3 ) {
        country = cur_wta[3];
    }
    String winner = cur_lst[10];
    //We now have country and winner, let's emit
    String emt_str = winner + "," + country+ ",";
    if ((emt_str.equals("") == false ) && (emt_str.length() > 3)) {
        emt_wrd.set(emt_str);
        cur_out.write(emt_wrd, num_one);
    }
}

What the map function does

  • Splits one line (one match) on commas.
  • Splits the first column (tournament ID) on - and uses the 4th piece as the country code; if it is missing, uses NA.
  • Takes the winner’s name from the 11th column.
  • Emits "winner name,country," as the key and 1 as the value. Reduce then adds up the 1s for each key to produce the win count.

Bonus Result · Wins by Player Name × Country (Top 20 Lines)

Submitted result file: top 20 lines of player name, country, win counts, followed by the written analysis Figure 11. Submitted result file — top 20 lines aggregated by player name, with my written analysis

Player nameCountryWinsPlayer nameCountryWins
Aaddi GuptaESP1Aastha DargudeIND4
Aaddi GuptaGRE3Aayushi TanwarIND1
Aaddi GuptaTUN3Abbi MelroseGBR1
Aaliya EbrahimEGY2Abbi MelroseJAM1
Aaliya EbrahimIND1Abbie MyersAUS43
Aaliyah HohmannTUN1Abbie MyersBRN3
Aanu AyegbusiNGR3Abbie MyersEGY10
Aanya GoelDOM4Abbie MyersGBR1
Aanya GoelMEX11Abbie MyersGRE1
Aanya GoelUSA1Abbie MyersINA2

Submitted analysis (original)

I modified the ID column by modifying the map function here. Now we can observe the actual player’s name on the first column. Some researchers might need actual names of the player because ID doesn’t give much intuition and insight. Abbie Myers tends win significantly more time than other players.


6. What I Learned

① Cloud resource lifecycle and cost

ActionCompute billingStorage billingData
Just closing the SSH session (Ctrl+D)ContinuesContinuesKept
SuspendStopsContinuesKept
DeleteStopsStopsAll deleted
  • The VM creation page shows the estimated monthly cost up front. For this lab’s spec (4 vCPU, 16 GB, based on a 10 GB disk) it showed about $98.84/month, or about $0.14/hour (Figure 2).
  • Closing the window does not stop the VM; it keeps running and billing. When it is not in use, it must be suspended or deleted.
  • Instead of using the defaults, I chose the OS, CPU, memory, and disk to fit the job.

② Reproducing a complex environment quickly with containers

  • Instead of installing a Hadoop cluster by hand, a single prebuilt image runs it right away.
  • A volume mount (-v ~/tmp:/src) lets the host and the container share the same files.
  • Detaching (Ctrl+P → Ctrl+Q) keeps the container alive; exiting (Ctrl+D) stops it, and it then has to be started again with docker run.
  • Image and container IDs have to be looked up (docker images, docker ps) and filled in manually.

③ HDFS is separate from the local file system

  • Files on the VM or in the container must be uploaded with hdfs dfs -put before MapReduce can read them.
  • MapReduce will not run if the output folder already exists, so it has to be removed with hdfs dfs -rm -r before re-running.

④ Thinking in MapReduce

  • Map: produce key-value pairs from each match record. Here the key was "player,country" and the value was 1.
  • Reduce: group by key and sum to get the final win count.
  • I practiced the deployment flow: write Java → compile → package as a jar → run with hadoop jar.
  • The choice of key changes what the result means. In the bonus task, switching the key from player ID to player name turned the same aggregation into a result people can read and interpret immediately.
  • Incomplete source data (tournament IDs without a country) needs handling with a default value (NA).

⑤ Data analysis starts with understanding the domain

  • Understanding tennis, the ITF, and the tournament structure comes before the code — that is where the idea of pulling the country out of the tournament name comes from.
  • As in the bonus task, first decide what question the data can answer, then design Map and Reduce around it.

This lab is for learning, so it gives the container broad privileges with --privileged and uses the old JDK 1.7 and Cloudera QuickStart image. In practice, containers are usually run with least privilege, and teams often use managed services (such as GCP Dataproc) or current Spark/Hadoop environments.

This post is licensed under CC BY 4.0 by the author.