Skip to content

ETL Extract-Transform-Load

Intro

Extract-Transform-Load (ETL) is a fancy way of saying, "We have some crufty, legacy data over in this system, and now we need it in this shiny new system over here, so we're going to migrate this."

(Typically, this is followed by, "We're only going to need to run this once." That's then typically followed by much orehead slapping and moaning about how stupid we could possibly be.)

Task

We are going to do the Transform step of an Extract-Transform-Load.

The goal

We're going to extract some Scrabble scores from a legacy system.

The old system stored a list of letters per score:

  • 1 point: "A", "E", "I", "O", "U", "L", "N", "R", "S", "T",
  • 2 points: "D", "G",
  • 3 points: "B", "C", "M", "P",
  • 4 points: "F", "H", "V", "W", "Y",
  • 5 points: "K",
  • 8 points: "J", "X",
  • 10 points: "Q", "Z",

The shiny new Scrabble system instead stores the score per letter, which makes it much faster and easier to calculate the core for a word. It also stores the letters in lower-case regardless of the case of the input letters:

  • "a" is worth 1 point.
  • "b" is worth 3 points.
  • "c" is worth 3 points.
  • "d" is worth 2 points.
  • Etc.

Your mission, should you choose to accept it, is to transform the legacy data format to the shiny new format.

The Code

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
#include "etl.h"
#include <cctype>

namespace etl {
std::map<char, int> transform(const std::map<int, std::vector<char>>);
} // namespace etl

std::map<char, int> etl::transform(const std::map<int, std::vector<char>> old) {
std::map<char, int> result{};
for (std::pair<int, std::vector<char>> i : old) {
    for (auto var : i.second)
    result.insert(std::pair<char, int>(std::tolower(var), i.first));
}

return result;
}
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
#include <vector>
#if !defined(ETL_H)
#define ETL_H
#include "map"
#include "vector"

namespace etl {
    std::map<char,int> transform(const std::map<int,std::vector<char>>);
}  // namespace etl

#endif // ETL_H

Last update: February 10, 2021

Comments