Skip to content

Commit 0097b53

Browse files
fix(asap-tools): write sketchdb SQL only for a sketchdb arm
Without --prebuilt-output-dir no config runs sketchdb, yet structured groups got sketchdb SQL files and sql_file entries. They are now written only with the flag; the ASAPQuery SQL is still rendered, so a bad entry fails either way. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
1 parent 571b13c commit 0097b53

2 files changed

Lines changed: 22 additions & 15 deletions

File tree

‎asap-tools/experiments/datasets/fake_metric/sketch_bench_workloads.py‎

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -666,20 +666,27 @@ def convert(
666666
# Structured groups come first: sketchdb runs only those, and results pair
667667
# across modes by query index, so its queries must be baseline's first.
668668
groups: Dict[Tuple[bool, int], Dict[str, List[str]]] = {}
669+
sketchdb_arm = prebuilt_output_dir is not None
669670
for entry, q in entries:
670671
structured = "promql" not in entry
671672
files = groups.setdefault(
672673
(not structured, q.interval_secs),
673-
{m: [] for m in modes + ([SKETCHDB] if structured else [])},
674+
{
675+
m: []
676+
for m in modes + ([SKETCHDB] if structured and sketchdb_arm else [])
677+
},
674678
)
675679
comment = f"-- {describe(entry)}\n"
676680
files[BASELINE].append(comment + raw_sql(q, labels))
677681
if BASELINE_MV in files:
678682
files[BASELINE_MV].append(comment + mv_sql(q, views, labels))
679683
if structured:
680-
files[SKETCHDB].append(comment + asapquery_sql(entry))
684+
# Rendered either way, so a table without ASAPQuery SQL fails alike.
685+
sql = asapquery_sql(entry)
686+
if SKETCHDB in files:
687+
files[SKETCHDB].append(comment + sql)
681688
has_structured = any(not promql for promql, _ in groups)
682-
if prebuilt_output_dir is not None and not has_structured:
689+
if sketchdb_arm and not has_structured:
683690
raise ValueError(
684691
f"{table_path}: --prebuilt-output-dir given, but no structured entry "
685692
"has ASAPQuery SQL for a sketchdb arm"
@@ -756,7 +763,7 @@ def experiment_params(arm_modes: List[str], init_mode: str) -> dict:
756763
+ yaml.safe_dump(experiment_params([mode], mode), sort_keys=False)
757764
)
758765
out_paths.append(out_path)
759-
if prebuilt_output_dir is not None:
766+
if sketchdb_arm:
760767
prebuilt_output_dir = os.path.abspath(prebuilt_output_dir)
761768
check_prebuilt_controller_output(prebuilt_output_dir)
762769
# With baseline in the same experiment, so its results score sketchdb's.

‎asap-tools/experiments/tests/test_sketch_bench_workloads.py‎

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -372,20 +372,13 @@ def test_writes_config_grouped_by_interval(self):
372372
"sketch_bench_views.data_total_value_counter_60s"
373373
),
374374
)
375+
# No --prebuilt-output-dir, so no sketchdb arm or SQL.
375376
structured = groups["interval_60s_structured"]
376377
self.assertEqual(
377-
sorted(structured["sql_file"]),
378-
["baseline", "baseline_mv", "sketchdb"],
378+
sorted(structured["sql_file"]), ["baseline", "baseline_mv"]
379379
)
380-
# The table's sql as written, with only NOW() substituted.
381-
end = "'" + sbw.floored_end_datetime(60) + "'"
382-
with open(structured["sql_file"]["sketchdb"]) as f:
383-
self.assertEqual(
384-
f.read(),
385-
"-- quantile(0.99, latency) by (service) over 300s\n"
386-
+ e2e["queries"][-1]["sql"].replace("NOW()", end)
387-
+ ";\n",
388-
)
380+
sql_dir = os.path.dirname(structured["sql_file"]["baseline"])
381+
self.assertFalse([n for n in os.listdir(sql_dir) if "sketchdb" in n])
389382
finally:
390383
os.chdir(cwd)
391384

@@ -530,6 +523,13 @@ def test_sketchdb_arm_runs_the_structured_queries_on_the_saved_plan(self):
530523
self.assertEqual([g["id"] for g in client["sketchdb"]], [0])
531524
self.assertEqual(len(client["baseline"][0]["queries"]), 2)
532525
self.assertEqual(len(client["sketchdb"][0]["queries"]), 2)
526+
# The table's sql as written, with only NOW() substituted.
527+
end = "'" + sbw.floored_end_datetime(60) + "'"
528+
self.assertEqual(
529+
client["sketchdb"][0]["queries"][0],
530+
"-- quantile(0.99, latency) by (service) over 300s\n"
531+
+ structured[0]["sql"].replace("NOW()", end),
532+
)
533533
# The runner's check that the saved plan covers sketchdb's queries.
534534
copy_prebuilt_controller_output(
535535
plan,

0 commit comments

Comments
 (0)