Skip to content

techops-recsys-lateral-hiring/dataengineer-transformations-scala

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

27 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Data transformations with Scala

This is a collection of jobs that are supposed to transform data. These jobs are using Spark to process larger volumes of data and are supposed to run on a Spark cluster ( via spark-submit).

Preparing for the interview

Warning

The exercises will be given at the time of interview, and solved by pairing with the interviewer.
Please do not solve the exercises before the interview.

✅ Goals:

  1. Get a working environment set up. You can setup a local environment, use a github codespaces or use other alternative.
    1. Get a high-level understanding of the code and test dataset structure
  2. Have your preferred text editor or IDE setup and ready to go.
  3. ⚠️ Don't solve the exercises before the interview. ⚠️

Setup the environment

Option 1: Local Setup

Tip

Use the Devcontainer setup if you encounter issues.

Pre-requisites

Please make sure you have the following installed and can run them

  • Java 17
  • Scala 2.13.17
  • Sbt 1.11.6
  • Apache Spark 4.0 with ability to run spark-submit

Windows users

We recommend using WSL 2 on Windows for this exercise, due to the lack of support of windows paths from Hadoop/Spark.

Follow instructions on the Windows official page and then the linux install.
Use the Devcontainer setup if you encounter issues.

Local Setup Process

  • Clone the repo
  • Package the project with sbt package
  • Ensure that you're able to run the tests with sbt test (some are ignored)
  • Sample data is available in the src/test/resource/data directory

Option 2: Devcontainer setup - Github codespaces

Configuration to use dev containers is provided in .devcontainer

Warning

This takes up to 7 minutes to setup, make sure to have things running before the interview.
You might need to wait for sbt to install on codespaces

  1. Fork this repository.
  2. Follow codespace instructions from the forked repository, to create the environment.

Option 3: In VSCode - Alternative

This requires a working local docker setup matching your OS and licensing situation, and VSCode.

If you have all of these, follow instructions in https://code.visualstudio.com/docs/devcontainers/containers. Otherwise, consider using codespaces.

Verify setup

All of the following commands should be running successfully

Run all tests

sbt test

Run specific tests class

sbt "test:testOnly *MySuite"

Run style checks

sbt scalastyle

Done!

All commands are passing?
You are good to go!

Warning

Remember, do not try to solve the exercises ahead of the interview.

Tip

You are allowed to customize your environment (having the test in vscode directly for example): feel free to spend the time making this comfortable for you. This is not an expectation.

Jobs

There are two applications in this repo: Word Count, and Citibike.

Currently these exist as skeletons, and have some initial test cases which are defined but ignored. For each application, please un-ignore the tests and implement the missing logic.

Wordcount

A NLP model is dependent on a specific input file. This job is supposed to preprocess a given text file to produce this input file for the NLP model (feature engineering). This job will count the occurrences of a word within the given text file (corpus).

There is a dump of the data lake for this under test/resources/data/words.txt with a text file.

Input

Simple *.txt file containing text.

Output

A single *.csv file containing data similar to:

"word","count"
"a","3"
"an","5"
...

Run the job

 spark-submit --master local --class thoughtworks.wordcount.WordCount \
    target/scala-2.12/tw-pipeline_2.12-0.1.0-SNAPSHOT.jar \
    "./src/main/resources/data/words.txt" \
    ./output

Citibike

For analytics purposes the BI department of a bike share company would like to present dashboards, displaying the distance each bike was driven. There is a *.csv file that contains historical data of previous bike rides. This input file needs to be processed in multiple steps. There is a pipeline running these jobs.

citibike pipeline

There is a dump of the datalake for this under /src/test/resources/data/citibike.csv with historical data.

Ingest

Reads a *.csv file and transforms it to parquet format. The column names will be sanitized (whitespaces replaced).

Input

Historical bike ride *.csv file:

"tripduration","starttime","stoptime","start station id","start station name","start station latitude",...
364,"2017-07-01 00:00:00","2017-07-01 00:06:05",539,"Metropolitan Ave & Bedford Ave",40.71534825,...
...
Output

*.parquet files containing the same content

"tripduration","starttime","stoptime","start_station_id","start_station_name","start_station_latitude",...
364,"2017-07-01 00:00:00","2017-07-01 00:06:05",539,"Metropolitan Ave & Bedford Ave",40.71534825,...
...
Run the job
spark-submit --master local --class thoughtworks.ingest.DailyDriver \
    target/scala-2.12/tw-pipeline_2.12-0.1.0-SNAPSHOT.jar \
    "./src/main/resources/data/citibike.csv" \
    "./output_int"

Distance calculation

This job takes bike trip information and calculates the "as the crow flies" distance traveled for each trip. It reads the previously ingested data parquet files.

Tip

For distance calculation, consider using Haversine formula as an option.

Input

Historical bike ride *.parquet files

"tripduration",...
364,...
...
Outputs

*.parquet files containing historical data with distance column containing the calculated distance.

"tripduration",...,"distance"
364,...,1.34
...
Run the job
 spark-submit --master local --class thoughtworks.citibike.CitibikeTransformer \
    target/scala-2.12/tw-pipeline_2.12-0.1.0-SNAPSHOT.jar \
    "./output_int" \
    ./output

Warning

One last time: do not try to solve the exercises ahead of the interview. 😅

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 6

Languages