Prerequisites
For this tutorial, you’ll need:- A ClickHouse Cloud account ($300 in free credits when signing up)
- A ClickHouse Cloud service
Create the table
- Select SQL console from the the left hand menu
- Click the + tab next to the home icon to create a new query
- In the SQL editor type the following query, then click Run:
Preprocess and insert the data
You can use the Wait for the data to insert - it will take a minute or two depending on the network speed.
url function to stream data into ClickHouse. Some preprocess is required first.
The query below inserts 25+ million rows into the uk_price_paid table and performs the following preprocessing steps:- splits the
postcodeto two different columns -postcode1andpostcode2, which is better for storage and queries - converts the
timefield to date as it only contains00:00time - ignores the UUID field because it isn’t needed for analysis
- transforms
typeanddurationto more readableEnumfields using the transform function - transforms the
is_newfield from a single-character string (Y/N) to a UInt8 field with 0 or 1 - drops the last two columns since they all have the same value (which is 0)
Validate the data
Let’s verify it worked by seeing how many rows were inserted:At the time this query was run, the dataset had 27,450,499 rows. Let’s see what the storage size is of the table in ClickHouse:Notice the size of the table is just 221.43 MiB, while the original dataset in uncompressed form is about 4 GiB.
ClickHouse offers excellent data compression out of the box, but also allows you to further tune compression per column if you need.
Run some queries
With the data loaded, try out the following queries to get a sense of how fast analytical queries return results.
The query below finds the average price per year across all of the data:The query below applies a filter to find the average price per year in London:It looks like something happened to home prices in 2020! But that is probably not a surprise…The query below finds the most expensive neighborhoods:
Next steps
In this tutorial you created a table, preprocessed and loaded UK property price data into ClickHouse, and then ran some analytical queries on that data. Next you can:- Learn how to speed up these queries with projections. See “Projections” for examples which use the same dataset.
- Learn more about ClickHouse core concepts
- Explore ClickHouse best practices
- Explore other sample datasets