Amazon カスタマーレビュー
このデータセットには、Amazon 商品に対する1億5,000万件以上のカスタマーレビューが含まれています。データは AWS S3 上の snappy で圧縮された Parquet ファイルとして提供されており、圧縮後の合計サイズは 49GB です。これを ClickHouse に取り込む手順を順を追って確認していきます。
注記
以下のクエリは、Production 環境の ClickHouse Cloud インスタンス上で実行されています。詳細については "Playground specifications" を参照してください。
データセットの読み込み
- データを ClickHouse に挿入しなくても、元の場所に対して直接クエリを実行できます。どのようなデータか確認するために、いくつか行を取得してみましょう。
行は次のような形になります:
- このデータを格納するために、ClickHouse に
amazon_reviewsという名前の新しいMergeTreeテーブルを定義します。
- 次の
INSERTコマンドでは、s3Clusterテーブル関数を使用します。これにより、クラスター内のすべてのノードを使って複数の S3 ファイルを並列に処理できます。また、https://datasets-documentation.s3.eu-west-3.amazonaws.com/amazon_reviews/amazon_reviews_*.snappy.parquetという名前で始まるすべてのファイルを挿入するために、ワイルドカードも使用します。
ヒント
ClickHouse Cloud では、クラスター名は default です。default を環境のクラスター名に置き換えてください。クラスターがない場合は、s3Cluster の代わりに s3 テーブル関数を使用してください。
- このクエリはそれほど時間がかからず、平均で毎秒約 300,000 行を処理します。およそ 5 分以内に、すべての行が挿入されていることを確認できるはずです。
- Let's see how much space our data is using:
The original data was about 70G, but compressed in ClickHouse it takes up about 30G.
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:
Notice the query time for such a large amount of data. The results are also a fun read!
- We can run the same query again, except this time we search for awesome in the reviews: