GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Chowder/amber/src/bench/python/gen_reuse_bench_data.py at main · Texera/Chowder

Expand file tree

/

gen_reuse_bench_data.py

Copy path
More file actions
More file actions

Latest commit

 

History

History
History
87 lines (75 loc) · 3.71 KB
/

gen_reuse_bench_data.py

Copy path

File metadata and controls

87 lines (75 loc) · 3.71 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
"""Scaled copies of the IMDB movie table for the reuse benchmark (ReuseBenchmark.scala).
The benchmark's workflows scan one CSV file, group it by ``country``, filter it on
``imdb_score`` and sort it. A scaled copy repeats every row ``factor`` times. Each copy keeps
the key columns (``country``, ``title_year``, ``imdb_score``, ``director_name``) unchanged, so
the group-by output stays at the 66 countries of the original and every row still joins with
its country's aggregate, and it changes ``movie_title`` and ``num_voted_users`` so that the
copies are distinct rows.
Usage (run with ``python3 -I`` because the input is downloaded data):
python3 -I gen_reuse_bench_data.py --input movie_metadata.csv --out-dir experiments/workflows/imdb --factors 1 20 100
The output file for factor N is ``<out-dir>/movies_x<N>.csv``. The script also writes
``<out-dir>/tens.csv``, the ten-row constant table (columns ``k`` and ``tenth``) that the
``expand`` family multiplies the movie table with.
"""
import argparse
import csv
import os
def main() -> None:
parser = argparse.ArgumentParser(description=__doc__.split("\n\n")[0])
parser.add_argument("--input", required=True, help="the original movie_metadata.csv")
parser.add_argument("--out-dir", required=True, help="folder for the scaled copies")
parser.add_argument(
"--factors",
nargs="+",
type=int,
required=True,
help="how many times each row is repeated, one output file per factor",
)
args = parser.parse_args()
with open(args.input, newline="", encoding="utf-8", errors="replace") as handle:
reader = csv.reader(handle)
header = next(reader)
rows = [row for row in reader if len(row) == len(header)]
title_index = header.index("movie_title")
voted_index = header.index("num_voted_users")
os.makedirs(args.out_dir, exist_ok=True)
tens_path = os.path.join(args.out_dir, "tens.csv")
with open(tens_path, "w", newline="", encoding="utf-8") as out:
writer = csv.writer(out, lineterminator="\n")
writer.writerow(["k", "tenth"])
for k in range(10):
writer.writerow([k, f"tenth-{k}"])
print(f"{tens_path}: 10 rows")
for factor in args.factors:
path = os.path.join(args.out_dir, f"movies_x{factor}.csv")
with open(path, "w", newline="", encoding="utf-8") as out:
writer = csv.writer(out, lineterminator="\n")
writer.writerow(header)
for copy in range(factor):
for row in rows:
scaled = list(row)
scaled[title_index] = f"{row[title_index].strip()} [{copy}]"
try:
scaled[voted_index] = str(int(row[voted_index]) + copy)
except ValueError:
pass
writer.writerow(scaled)
print(f"{path}: {len(rows) * factor} rows, {os.path.getsize(path)} bytes")
if __name__ == "__main__":
main()
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.