Amazon 고객 리뷰 데이터셋

Amazon 고객 리뷰 데이터셋

이 데이터셋은 Amazon 상품에 대한 1억 5천만 개 이상의 고객 리뷰를 담고 있어요. AWS S3에 snappy 압축 Parquet 파일(압축 기준 총 49GB)로 저장되어 있고, 이걸 ClickHouse에 삽입하는 과정을 단계별로 살펴볼게요.

출처: Amazon customer review

본문

이 데이터셋에는 Amazon 상품에 대한 1억 5천만 개 이상의 고객 리뷰가 들어 있어요. 데이터는 AWS S3의 snappy 압축 Parquet 파일로, 압축 기준 총 49GB 크기예요. ClickHouse에 삽입하는 단계를 함께 진행해 볼게요.

아래 쿼리들은 ClickHouse Cloud의 Production 인스턴스에서 실행됐어요. 자세한 내용은 "Playground 사양"을 참고하세요.

데이터셋 로드하기

  1. ClickHouse에 데이터를 삽입하지 않고, 제자리에서 쿼리할 수 있어요. 몇몇 행을 가져와서 어떤 모습인지 확인해 볼게요:
SELECT *
FROM s3('https://datasets-documentation.s3.eu-west-3.amazonaws.com/amazon_reviews/amazon_reviews_2015.snappy.parquet', NOSIGN)
LIMIT 3

행은 이런 모습이에요:

Row 1:
──────
review_date:       16462
marketplace:       US
customer_id:       25444946 -- 25.44 million
review_id:         R146L9MMZYG0WA
product_id:        B00NV85102
product_parent:    908181913 -- 908.18 million
product_title:     XIKEZAN iPhone 6 Plus 5.5 inch Waterproof Case, Shockproof Dirtproof Snowproof Full Body Skin Case Protective Cover with Hand Strap & Headphone Adapter & Kickstand
product_category:  Wireless
star_rating:       4
helpful_votes:     0
total_votes:       0
vine:              false
verified_purchase: true
review_headline:   case is sturdy and protects as I want
review_body:       I won't count on the waterproof part (I took off the rubber seals at the bottom because the got on my nerves). But the case is sturdy and protects as I want.

Row 2:
──────
review_date:       16462
marketplace:       US
customer_id:       1974568 -- 1.97 million
review_id:         R2LXDXT293LG1T
product_id:        B00OTFZ23M
product_parent:    951208259 -- 951.21 million
product_title:     Season.C Chicago Bulls Marilyn Monroe No.1 Hard Back Case Cover for Samsung Galaxy S5 i9600
product_category:  Wireless
star_rating:       1
helpful_votes:     0
total_votes:       0
vine:              false
verified_purchase: true
review_headline:   One Star
review_body:       Cant use the case because its big for the phone. Waist of money!

Row 3:
──────
review_date:       16462
marketplace:       US
customer_id:       24803564 -- 24.80 million
review_id:         R7K9U5OEIRJWR
product_id:        B00LB8C4U4
product_parent:    524588109 -- 524.59 million
product_title:     iPhone 5s Case, BUDDIBOX [Shield] Slim Dual Layer Protective Case with Kickstand for Apple iPhone 5 and 5s
product_category:  Wireless
star_rating:       4
helpful_votes:     0
total_votes:       0
vine:              false
verified_purchase: true
review_headline:   but overall this case is pretty sturdy and provides good protection for the phone
review_body:       The front piece was a little difficult to secure to the phone at first, but overall this case is pretty sturdy and provides good protection for the phone, which is what I need. I would buy this case again.
  1. 이 데이터를 ClickHouse에 저장할 amazon_reviews라는 새 MergeTree 테이블을 정의해 볼게요:
CREATE DATABASE amazon

CREATE TABLE amazon.amazon_reviews
(
    `review_date` Date,
    `marketplace` LowCardinality(String),
    `customer_id` UInt64,
    `review_id` String,
    `product_id` String,
    `product_parent` UInt64,
    `product_title` String,
    `product_category` LowCardinality(String),
    `star_rating` UInt8,
    `helpful_votes` UInt32,
    `total_votes` UInt32,
    `vine` Bool,
    `verified_purchase` Bool,
    `review_headline` String,
    `review_body` String,
    PROJECTION helpful_votes
    (
        SELECT *
        ORDER BY helpful_votes
    )
)
ENGINE = MergeTree
ORDER BY (review_date, product_category)
  1. 아래 INSERT 명령은 s3Cluster 테이블 함수를 사용해요. 이 함수는 클러스터의 모든 노드를 사용해서 여러 S3 파일을 병렬로 처리할 수 있게 해 줘요. 또한 https://datasets-documentation.s3.eu-west-3.amazonaws.com/amazon_reviews/amazon_reviews_*.snappy.parquet 이름으로 시작하는 모든 파일을 삽입하도록 와일드카드를 사용해요:
INSERT INTO amazon.amazon_reviews SELECT *
FROM s3Cluster('default', 
'https://datasets-documentation.s3.eu-west-3.amazonaws.com/amazon_reviews/amazon_reviews_*.snappy.parquet', NOSIGN)

ClickHouse Cloud에서 클러스터 이름은 default예요. default를 여러분의 클러스터 이름으로 바꾸세요… 또는 클러스터가 없다면 s3 테이블 함수(s3Cluster 대신)를 사용하세요.

  1. 그 쿼리는 오래 걸리지 않아요 — 평균 초당 약 300,000행을 처리해요. 5분 정도면 모든 행이 삽입된 걸 볼 수 있어요.

  2. 데이터가 얼마나 많은 공간을 차지하는지 확인해 볼게요. 원본 데이터는 약 70GB였지만, ClickHouse에서 압축하면 약 30GB를 차지해요.

예시 쿼리

  1. 몇 가지 쿼리를 실행해 볼게요. 데이터셋에서 가장 도움이 된(helpful) 리뷰 상위 10개예요. 이 쿼리는 성능을 높이기 위해 projection을 사용해요.

  2. 다음은 리뷰가 가장 많은 Amazon 상위 10개 상품이에요.

  3. 다음은 각 상품에 대한 월별 평균 리뷰 평점이에요 (실제 Amazon 면접 문제랍니다!).

  4. 다음은 상품 카테고리별 총 투표 수예요. product_category가 기본 키에 있기 때문에 이 쿼리는 빨라요.

  5. 리뷰에서 **"awful"**이라는 단어가 가장 자주 나타나는 상품을 찾아볼게요. 큰 작업이에요 — 1억 5,100만 개가 넘는 문자열을 파싱해서 한 단어를 찾아야 하거든요:

SELECT
    product_id,
    any(product_title),
    avg(star_rating),
    count() AS count
FROM amazon.amazon_reviews
WHERE position(review_body, 'awful') > 0
GROUP BY product_id
ORDER BY count DESC
LIMIT 50;

이렇게 많은 양의 데이터에 대한 쿼리 시간을 주목해 보세요. 결과도 재미있게 읽을 수 있어요!

  1. 같은 쿼리를 다시 실행하되, 이번에는 리뷰에서 awesome을 검색해 볼게요:
SELECT 
    product_id,
    any(product_title),
    avg(star_rating),
    count() AS count
FROM amazon.amazon_reviews
WHERE position(review_body, 'awesome') > 0
GROUP BY product_id
ORDER BY count DESC
LIMIT 50;

더 알아보기 (Learn more)