You can try this on self-hosted ClickHouse or on ClickHouse Cloud. If you don’t already have an account, you can start a free ClickHouse Cloud trial.
Loading the dataset
- Without inserting the data into ClickHouse, we can query it in place. Let’s grab some rows, so we can see what they look like:
- Let’s define a new
MergeTreetable namedamazon_reviewsto store this data in ClickHouse:
- The following
INSERTcommand uses thes3Clustertable function, which distributes the S3 files among the nodes of your cluster so they are read in parallel.
default and you can run this as shown. On a self-managed server, replace default with the name of your cluster — or, if you are running a single server, use the s3 table function instead, dropping the first argument so the call starts with the URL.
We use a wildcard in the URL to insert all matching review files.
- That query doesn’t take long - averaging about 300,000 rows per second. Within 5 minutes or so you should see all the rows inserted:
- Let’s see how much space our data is using:
Example queries
- Let’s run some queries. Here are the top 10 most-helpful reviews in the dataset:
This query is using a projection to speed up performance.
- Here are the top 10 products in Amazon with the most reviews:
- Here are the average review ratings per month for each product (an actual Amazon job interview question!):
- Here are the total number of votes per product category. This query is fast because
product_categoryis in the primary key:
- Let’s find the products with the word “awful” occurring most frequently in the review. This is a big task - over 151M strings have to be parsed looking for a single word:
runnable
- We can run the same query again, except this time we search for awesome in the reviews:
runnable