| """ |
| Stage 8: subset reviews/reviews_all.parquet to only POIs in the clean benchmark. |
| |
| Source v1 reviews/ contains six per-source parquet files plus a unified |
| reviews_all.parquet (~13 GB). We only re-emit the unified file -- it's |
| the only one downstream pipelines actually read (reviews_*.parquet glob |
| matches reviews_all.parquet so it's de-facto the canonical). |
| """ |
| import duckdb, time |
| from pathlib import Path |
|
|
| ROOT = Path("/scratch/peibo/RQ3/Data/data/processed/cross_city_benchmark_clean") |
| SRC = "/scratch/peibo/RQ3/Data/data/processed/cross_city_benchmark/reviews/reviews_all.parquet" |
| POIS = ROOT / "pois.parquet" |
| OUT = ROOT / "reviews" / "reviews_all.parquet" |
| OUT.parent.mkdir(parents=True, exist_ok=True) |
|
|
| t0 = time.time() |
| def step(msg): print(f"[{time.time()-t0:6.1f}s] {msg}", flush=True) |
|
|
| con = duckdb.connect() |
| con.execute("PRAGMA threads=32") |
| con.execute("SET memory_limit='48GB'") |
| con.execute("SET preserve_insertion_order=false") |
| con.execute("SET temp_directory='/scratch/peibo/duckdb_tmp'") |
|
|
| step(f"reading clean POI universe from {POIS}") |
| con.execute(f"CREATE TABLE keep_ids AS SELECT fsq_place_id FROM '{POIS}'") |
| n_keep = con.execute("SELECT COUNT(*) FROM keep_ids").fetchone()[0] |
| step(f" {n_keep:,} POIs to keep") |
|
|
| step(f"streaming + filtering {SRC} ... (this takes a few minutes)") |
| con.execute(f""" |
| COPY ( |
| SELECT r.* FROM '{SRC}' r |
| SEMI JOIN keep_ids k USING (fsq_place_id) |
| ) TO '{OUT}' (FORMAT PARQUET, COMPRESSION 'zstd', ROW_GROUP_SIZE 200000) |
| """) |
| n_rev = con.execute(f"SELECT COUNT(*) FROM '{OUT}'").fetchone()[0] |
| n_pois_with_reviews = con.execute( |
| f"SELECT COUNT(DISTINCT fsq_place_id) FROM '{OUT}'").fetchone()[0] |
| sz = OUT.stat().st_size / 1e6 |
| print() |
| print("=== Stage 8 output ===") |
| print(f" file: {OUT} ({sz/1024:.2f} GB)") |
| print(f" reviews: {n_rev:,}") |
| print(f" POIs with reviews: {n_pois_with_reviews:,} of {n_keep:,}") |
| print(f" total elapsed: {time.time()-t0:.1f}s") |
|
|