Run benchmark in the DB under test for a given scenario.
(
scenario: Scenario,
samples: int,
repository: Path,
print_results: bool,
db_port: int,
db_host: str,
db_user: str,
db_pass: str | None,
db_require_ssl: bool,
)
| 200 | @click.option("--db-pass", **Opt.db_pass) |
| 201 | @click.option("--db-require-ssl", **Opt.db_require_ssl) |
| 202 | def run( |
| 203 | scenario: Scenario, |
| 204 | samples: int, |
| 205 | repository: Path, |
| 206 | print_results: bool, |
| 207 | db_port: int, |
| 208 | db_host: str, |
| 209 | db_user: str, |
| 210 | db_pass: str | None, |
| 211 | db_require_ssl: bool, |
| 212 | ) -> None: |
| 213 | """Run benchmark in the DB under test for a given scenario.""" |
| 214 | |
| 215 | info(f'Running "{scenario}" scenario') |
| 216 | |
| 217 | try: |
| 218 | with closing( |
| 219 | sql.Database( |
| 220 | port=db_port, |
| 221 | host=db_host, |
| 222 | user=db_user, |
| 223 | database=str(scenario), |
| 224 | password=db_pass, |
| 225 | require_ssl=db_require_ssl, |
| 226 | ) |
| 227 | ) as db: |
| 228 | db_version = db.mz_version() or db.version() |
| 229 | df = pd.DataFrame.from_records( |
| 230 | [ |
| 231 | ( |
| 232 | query.name(), |
| 233 | sample, |
| 234 | cast( |
| 235 | np.timedelta64, |
| 236 | db.explain(query, timing=True).optimization_time(), |
| 237 | ).astype(int), |
| 238 | ) |
| 239 | for sample in range(samples) |
| 240 | for query in [ |
| 241 | sql.Query(query) |
| 242 | for query in sql.parse_from_file(scenario.workload_path()) |
| 243 | ] |
| 244 | ], |
| 245 | columns=["query", "sample", "data"], |
| 246 | ).pivot(index="sample", columns="query", values="data") |
| 247 | |
| 248 | if print_results: |
| 249 | print(df.to_string()) |
| 250 | |
| 251 | results_path = util.results_path(repository, scenario, db_version) |
| 252 | info(f'Writing results to "{results_path}"') |
| 253 | df.to_csv(results_path, index=False, quoting=csv.QUOTE_MINIMAL) |
| 254 | except Exception as e: |
| 255 | raise click.ClickException(f"run command failed: {e}") |
| 256 | |
| 257 | |
| 258 | @app.command() |
nothing calls this directly
no test coverage detected