Skip to main content
In this tutorial you’ll explore how ClickHouse can be used to run analytical queries over large amounts of data. You’ll also see how you can use a dictionary to enrich the data and write join queries.

Prerequisites

For this tutorial, you’ll need:
1

Create the table

The dataset used in this tutorial is the New York City taxi dataset, which contains details about millions of taxi rides, with columns including tip amount, tolls, payment type, and more.
  1. Select SQL console from the the left hand menu
  2. Click the + tab next to the home icon to create a new query
  3. In the SQL editor type the following query, then click Run:
Expandable
2

Insert the data

Now that you’ve created a table, add the New York City taxi data from CSV files in S3.The following command inserts ~2,000,000 rows into your trips table from two different files in S3: trips_1.tsv.gz and trips_2.tsv.gz:
Expandable
Wait for the data to finish inserting. Around 150MB of data will be downloaded. When the data is finished inserting, check the number of rows in the trips table:
You should get a result of 1,999,657 rows
3

Analyze the data

With the data loaded, you can run some queries to analyze the data.
  • Calculate the average tip amount:
  • Calculate the average cost based on the number of passengers:
  • Calculate the daily number of pickups per neighborhood:
  • Calculate the length of each trip in minutes, then group the results by trip length:
  • Show the number of pickups in each neighborhood broken down by hour of the day:
4

Create a dictionary

Next you’ll create a dictionary (a mapping of key-value pairs stored in memory) called taxi_zone_dictionary to provide a mapping between location IDs and NYC borough names, sourced from a CSV file containing every New York City neighborhood. These correspond to the pickup_nyct2010_gid and dropoff_nyct2010_gid columns in the trips table.Here’s an excerpt from the CSV file you’re using in table format. The LocationID column in the file maps to the pickup_nyct2010_gid and dropoff_nyct2010_gid columns in your trips table:Run the following SQL command, which creates a dictionary named taxi_zone_dictionary and populates the dictionary from the CSV file in S3. The URL for the file is https://datasets-documentation.s3.eu-west-3.amazonaws.com/nyc-taxi/taxi_zone_lookup.csv.
Setting LIFETIME to 0 disables automatic updates to avoid unnecessary traffic to our S3 bucket. In other cases, you might configure it differently. For details, see Refreshing dictionary data using LIFETIME.
Verify it worked. The following query should return 265 rows, or one row for each neighborhood:
5

Run queries using the dictionary

You can use the dictGet function (or its variations) to retrieve a value from a dictionary. You pass in the name of the dictionary, the value you want, and the key (which in our example is the LocationID column of taxi_zone_dictionary), and get back the matching value. For example, the following query returns the Borough whose LocationID is 132 (corresponding to JFK airport):
JFK is in Queens. Notice the time to retrieve the value is essentially 0:
Use the dictHas function to see if a key is present in the dictionary. For example, the following query returns 1 (which is “true” in ClickHouse):
The following query returns 0 because 4567 isn’t a value of LocationID in the dictionary:
Use the dictGet function to retrieve a borough’s name in a query. For example:
This query sums up the number of taxi rides per borough that end at either the LaGuardia or JFK airport. The result looks like the following, and notice there are quite a few trips where the pickup neighborhood is unknown:
6

Perform a join

Finally, write some queries that join the taxi_zone_dictionary with your trips table.Start with a simple JOIN that acts similarly to the previous airport query above:
The response looks identical to the dictGet query:
Notice the output of the above JOIN query is the same as the query before it that used dictGetOrDefault (except that the Unknown values aren’t included). Behind the scenes, ClickHouse is actually calling the dictGet function for the taxi_zone_dictionary dictionary, but the JOIN syntax is more familiar for SQL developers.
This query returns rows for the 1000 trips with the highest tip amount, then performs an inner join of each row with the dictionary:
Prefer listing only the columns your query needs rather than using SELECT *. Because ClickHouse stores data by column, selecting fewer columns directly reduces the data read, decompressed, and processed.

Next steps

Learn more about ClickHouse with the following documentation:
Last modified on September 23, 2026