New York Public Library “What’s on the Menu?” Dataset

The dataset is created by the New York Public Library. It contains historical data on the menus of hotels, restaurants and cafes with the dishes along with their prices.

Source: http://menus.nypl.org/data
The data is in public domain.

The data is from library’s archive and it may be incomplete and difficult for statistical analysis. Nevertheless it is also very yummy.
The size is just 1.3 million records about dishes in the menus (a very small data volume for ClickHouse, but it’s still a good example).

Download the Dataset

  1. wget https://s3.amazonaws.com/menusdata.nypl.org/gzips/2021_08_01_07_01_17_data.tgz

Replace the link to the up to date link from http://menus.nypl.org/data if needed.
Download size is about 35 MB.

Unpack the Dataset

  1. tar xvf 2021_08_01_07_01_17_data.tgz

Uncompressed size is about 150 MB.

The data is normalized consisted of four tables:
- Menu: information about menus: the name of the restaurant, the date when menu was seen, etc;
- Dish: information about dishes: the name of the dish along with some characteristic;
- MenuPage: information about the pages in the menus; every page belongs to some menu;
- MenuItem: an item of the menu - a dish along with its price on some menu page: links to dish and menu page.

Create the Tables

  1. CREATE TABLE dish
  2. (
  3. id UInt32,
  4. name String,
  5. description String,
  6. menus_appeared UInt32,
  7. times_appeared Int32,
  8. first_appeared UInt16,
  9. last_appeared UInt16,
  10. lowest_price Decimal64(3),
  11. highest_price Decimal64(3)
  12. ) ENGINE = MergeTree ORDER BY id;
  13. CREATE TABLE menu
  14. (
  15. id UInt32,
  16. name String,
  17. sponsor String,
  18. event String,
  19. venue String,
  20. place String,
  21. physical_description String,
  22. occasion String,
  23. notes String,
  24. call_number String,
  25. keywords String,
  26. language String,
  27. date String,
  28. location String,
  29. location_type String,
  30. currency String,
  31. currency_symbol String,
  32. status String,
  33. page_count UInt16,
  34. dish_count UInt16
  35. ) ENGINE = MergeTree ORDER BY id;
  36. CREATE TABLE menu_page
  37. (
  38. id UInt32,
  39. menu_id UInt32,
  40. page_number UInt16,
  41. image_id String,
  42. full_height UInt16,
  43. full_width UInt16,
  44. uuid UUID
  45. ) ENGINE = MergeTree ORDER BY id;
  46. CREATE TABLE menu_item
  47. (
  48. id UInt32,
  49. menu_page_id UInt32,
  50. price Decimal64(3),
  51. high_price Decimal64(3),
  52. dish_id UInt32,
  53. created_at DateTime,
  54. updated_at DateTime,
  55. xpos Float64,
  56. ypos Float64
  57. ) ENGINE = MergeTree ORDER BY id;

We use Decimal data type to store prices. Everything else is quite straightforward.

Import Data

Upload data into ClickHouse:

  1. clickhouse-client --format_csv_allow_single_quotes 0 --input_format_null_as_default 0 --query "INSERT INTO dish FORMAT CSVWithNames" < Dish.csv
  2. clickhouse-client --format_csv_allow_single_quotes 0 --input_format_null_as_default 0 --query "INSERT INTO menu FORMAT CSVWithNames" < Menu.csv
  3. clickhouse-client --format_csv_allow_single_quotes 0 --input_format_null_as_default 0 --query "INSERT INTO menu_page FORMAT CSVWithNames" < MenuPage.csv
  4. clickhouse-client --format_csv_allow_single_quotes 0 --input_format_null_as_default 0 --date_time_input_format best_effort --query "INSERT INTO menu_item FORMAT CSVWithNames" < MenuItem.csv

We use CSVWithNames format as the data is represented by CSV with header.

We disable format_csv_allow_single_quotes as only double quotes are used for data fields and single quotes can be inside the values and should not confuse the CSV parser.

We disable input_format_null_as_default as our data does not have NULLs. Otherwise ClickHouse will try to parse \N sequences and can be confused with \ in data.

The setting --date_time_input_format best_effort allows to parse DateTime fields in wide variety of formats. For example, ISO-8601 without seconds like ‘2000-01-01 01:02’ will be recognized. Without this setting only fixed DateTime format is allowed.

Denormalize the Data

Data is presented in multiple tables in normalized form. It means you have to perform JOINs if you want to query, e.g. dish names from menu items.
For typical analytical tasks it is way more efficient to deal with pre-JOINed data to avoid doing JOIN every time. It is called “denormalized” data.

We will create a table that will contain all the data JOINed together:

  1. CREATE TABLE menu_item_denorm
  2. ENGINE = MergeTree ORDER BY (dish_name, created_at)
  3. AS SELECT
  4. price,
  5. high_price,
  6. created_at,
  7. updated_at,
  8. xpos,
  9. ypos,
  10. dish.id AS dish_id,
  11. dish.name AS dish_name,
  12. dish.description AS dish_description,
  13. dish.menus_appeared AS dish_menus_appeared,
  14. dish.times_appeared AS dish_times_appeared,
  15. dish.first_appeared AS dish_first_appeared,
  16. dish.last_appeared AS dish_last_appeared,
  17. dish.lowest_price AS dish_lowest_price,
  18. dish.highest_price AS dish_highest_price,
  19. menu.id AS menu_id,
  20. menu.name AS menu_name,
  21. menu.sponsor AS menu_sponsor,
  22. menu.event AS menu_event,
  23. menu.venue AS menu_venue,
  24. menu.place AS menu_place,
  25. menu.physical_description AS menu_physical_description,
  26. menu.occasion AS menu_occasion,
  27. menu.notes AS menu_notes,
  28. menu.call_number AS menu_call_number,
  29. menu.keywords AS menu_keywords,
  30. menu.language AS menu_language,
  31. menu.date AS menu_date,
  32. menu.location AS menu_location,
  33. menu.location_type AS menu_location_type,
  34. menu.currency AS menu_currency,
  35. menu.currency_symbol AS menu_currency_symbol,
  36. menu.status AS menu_status,
  37. menu.page_count AS menu_page_count,
  38. menu.dish_count AS menu_dish_count
  39. FROM menu_item
  40. JOIN dish ON menu_item.dish_id = dish.id
  41. JOIN menu_page ON menu_item.menu_page_id = menu_page.id
  42. JOIN menu ON menu_page.menu_id = menu.id

Validate the Data

  1. SELECT count() FROM menu_item_denorm
  2. 1329175

Run Some Queries

Averaged historical prices of dishes:

  1. SELECT
  2. round(toUInt32OrZero(extract(menu_date, '^\\d{4}')), -1) AS d,
  3. count(),
  4. round(avg(price), 2),
  5. bar(avg(price), 0, 100, 100)
  6. FROM menu_item_denorm
  7. WHERE (menu_currency = 'Dollars') AND (d > 0) AND (d < 2022)
  8. GROUP BY d
  9. ORDER BY d ASC
  10. ┌────d─┬─count()─┬─round(avg(price), 2)─┬─bar(avg(price), 0, 100, 100)─┐
  11. 1850 618 1.5 █▍
  12. 1860 1634 1.29 █▎
  13. 1870 2215 1.36 █▎
  14. 1880 3909 1.01
  15. 1890 8837 1.4 █▍
  16. 1900 176292 0.68
  17. 1910 212196 0.88
  18. 1920 179590 0.74
  19. 1930 73707 0.6
  20. 1940 58795 0.57
  21. 1950 41407 0.95
  22. 1960 51179 1.32 █▎
  23. 1970 12914 1.86 █▋
  24. 1980 7268 4.35 ████▎
  25. 1990 11055 6.03 ██████
  26. 2000 2467 11.85 ███████████▋
  27. 2010 597 25.66 █████████████████████████▋
  28. └──────┴─────────┴──────────────────────┴──────────────────────────────┘
  29. 17 rows in set. Elapsed: 0.044 sec. Processed 1.33 million rows, 54.62 MB (30.00 million rows/s., 1.23 GB/s.)

Take it with a grain of salt.

Burger Prices:

  1. SELECT
  2. round(toUInt32OrZero(extract(menu_date, '^\\d{4}')), -1) AS d,
  3. count(),
  4. round(avg(price), 2),
  5. bar(avg(price), 0, 50, 100)
  6. FROM menu_item_denorm
  7. WHERE (menu_currency = 'Dollars') AND (d > 0) AND (d < 2022) AND (dish_name ILIKE '%burger%')
  8. GROUP BY d
  9. ORDER BY d ASC
  10. ┌────d─┬─count()─┬─round(avg(price), 2)─┬─bar(avg(price), 0, 50, 100)───────────┐
  11. 1880 2 0.42
  12. 1890 7 0.85 █▋
  13. 1900 399 0.49
  14. 1910 589 0.68 █▎
  15. 1920 280 0.56
  16. 1930 74 0.42
  17. 1940 119 0.59 █▏
  18. 1950 134 1.09 ██▏
  19. 1960 272 0.92 █▋
  20. 1970 108 1.18 ██▎
  21. 1980 88 2.82 █████▋
  22. 1990 184 3.68 ███████▎
  23. 2000 21 7.14 ██████████████▎
  24. 2010 6 18.42 ████████████████████████████████████▋
  25. └──────┴─────────┴──────────────────────┴───────────────────────────────────────┘
  26. 14 rows in set. Elapsed: 0.052 sec. Processed 1.33 million rows, 94.15 MB (25.48 million rows/s., 1.80 GB/s.)

Vodka:

  1. SELECT
  2. round(toUInt32OrZero(extract(menu_date, '^\\d{4}')), -1) AS d,
  3. count(),
  4. round(avg(price), 2),
  5. bar(avg(price), 0, 50, 100)
  6. FROM menu_item_denorm
  7. WHERE (menu_currency IN ('Dollars', '')) AND (d > 0) AND (d < 2022) AND (dish_name ILIKE '%vodka%')
  8. GROUP BY d
  9. ORDER BY d ASC
  10. ┌────d─┬─count()─┬─round(avg(price), 2)─┬─bar(avg(price), 0, 50, 100)─┐
  11. 1910 2 0
  12. 1920 1 0.3
  13. 1940 21 0.42
  14. 1950 14 0.59 █▏
  15. 1960 113 2.17 ████▎
  16. 1970 37 0.68 █▎
  17. 1980 19 2.55 █████
  18. 1990 86 3.6 ███████▏
  19. 2000 2 3.98 ███████▊
  20. └──────┴─────────┴──────────────────────┴─────────────────────────────┘

To get vodka we have to write ILIKE '%vodka%' and this definitely makes a statement.

Caviar:

Let’s print caviar prices. Also let’s print a name of any dish with caviar.

  1. SELECT
  2. round(toUInt32OrZero(extract(menu_date, '^\\d{4}')), -1) AS d,
  3. count(),
  4. round(avg(price), 2),
  5. bar(avg(price), 0, 50, 100),
  6. any(dish_name)
  7. FROM menu_item_denorm
  8. WHERE (menu_currency IN ('Dollars', '')) AND (d > 0) AND (d < 2022) AND (dish_name ILIKE '%caviar%')
  9. GROUP BY d
  10. ORDER BY d ASC
  11. ┌────d─┬─count()─┬─round(avg(price), 2)─┬─bar(avg(price), 0, 50, 100)──────┬─any(dish_name)──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┐
  12. 1090 1 0 Caviar
  13. 1880 3 0 Caviar
  14. 1890 39 0.59 █▏ Butter and caviar
  15. 1900 1014 0.34 Anchovy Caviar on Toast
  16. 1910 1588 1.35 ██▋ 1/1 Brötchen Caviar
  17. 1920 927 1.37 ██▋ ASTRAKAN CAVIAR
  18. 1930 289 1.91 ███▋ Astrachan caviar
  19. 1940 201 0.83 █▋ (SPECIAL) Domestic Caviar Sandwich
  20. 1950 81 2.27 ████▌ Beluga Caviar
  21. 1960 126 2.21 ████▍ Beluga Caviar
  22. 1970 105 0.95 █▊ BELUGA MALOSSOL CAVIAR AMERICAN DRESSING
  23. 1980 12 7.22 ██████████████▍ Authentic Iranian Beluga Caviar the world's finest black caviar presented in ice garni and a sampling of chilled 100° Russian vodka │
  24. │ 1990 │ 74 │ 14.42 │ ████████████████████████████▋ │ Avocado Salad, Fresh cut avocado with caviare │
  25. │ 2000 │ 3 │ 7.82 │ ███████████████▋ │ Aufgeschlagenes Kartoffelsueppchen mit Forellencaviar │
  26. │ 2010 │ 6 │ 15.58 │ ███████████████████████████████▏ │ "OYSTERS AND PEARLS" "Sabayon" of Pearl Tapioca with Island Creek Oysters and Russian Sevruga Caviar │
  27. └──────┴─────────┴──────────────────────┴──────────────────────────────────┴─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┘

At least they have caviar with vodka. Very nice.

Test it in Playground

The data is uploaded to ClickHouse Playground, example.