Easier to read with cream paper, a tint, more contrast or larger text? Choose your colours and text, once, for every page.

Preview

DA 2.8: Blending several sources for one report

This is the first page of the lesson. Read it and have a go at the activities. The rest is in the full lesson.

60 minutes

One monthly report from five places

A wholesaler gets orders from the web and from the shop counter. Prices live in a price list. Customers type their names with mistakes. Depots deliver by area.

The manager wants one report in pounds, ready to read.

Key words

WordWhat it means
Dataseta collection of related data about one subject
Blendingbringing data from several sources into one dataset
Consolidationstacking same-shaped datasets into one
Fuzzy matchingmatching values that are close but not the same
Spatial matchingmatching by where things are
Output formatthe shape the report must have
Requirementsomething the result must do or show

The cells students fill in are left blank in this preview.

By the end of this lesson

Note

I can combine several techniques to blend sources and present the result as required.

Starter

Have a go

Starter

3 questions
Have a go: your answers are marked here and then forgotten. Sign in if you would like your score kept, and to pick up where you left off.Sign in to keep your score

Your answers are marked here and are not kept. A college account keeps every student’s marks.

Review the sources, then pick techniques

List each source and ask what is wrong with it. Then match the problem to a technique.

Two sources of the same shape need consolidation. A shared id needs a join. Misspelt names need fuzzy matching. Positions need spatial matching.

Problem and technique

ProblemTechnique
Web orders and shop orders have the same columnsConsolidation (union all)
Each order needs its priceJoin on product
Customer names are typed wronglyFuzzy matching
Each order needs the nearest depotSpatial matching

The cells students fill in are left blank in this preview.

Try it: consolidate and join prices

Code: duckdb
with all_orders as (
  select * from web_orders union all select * from shop_orders
)
select o.customer, o.product, o.units * p.price_pence as pence
from all_orders o
join price_list p on p.product = o.product
order by o.customer, o.product;

Try it: fix typed names

Code: duckdb
select t.typed, a.account, t.note
from typed_names t
cross join account_names a
qualify row_number() over (partition by t.typed order by jaro_winkler_similarity(lower(t.typed), lower(a.account)) desc) = 1;

-- Each typed name now has its real account.

Check

Have a go

Check

3 questions
Have a go: your answers are marked here and then forgotten. Sign in if you would like your score kept, and to pick up where you left off.Sign in to keep your score

Your answers are marked here and are not kept. A college account keeps every student’s marks.

The lesson goes on

6 more parts of this lesson are in the full curriculum, with the tasks, the final check and the labs. A college account gives your students all of it.