Skip to content

Commit 35a1ee1

Browse files
zzylolclaude
andauthored
planner: accept optional measured_at on atomic-cost entries (#796)
sketch-bench#155 (for sketch-bench#147) adds a measured_at block to every atomic-cost row. AtomicCostEntry denies unknown fields, so a regenerated table would fail to load. Carry it as an optional opaque Value. Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
1 parent 8b2b9ed commit 35a1ee1

2 files changed

Lines changed: 29 additions & 0 deletions

File tree

‎asap-planner-rs/src/optimizer/atomic_costs.rs‎

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,12 @@ pub struct AtomicCostEntry {
8383
pub merge_cpu_secs: f64,
8484
pub query_cpu_secs: f64,
8585
pub query_accuracy: BTreeMap<String, f64>,
86+
/// The conditions sketch-bench measured the row under (items, keys and
87+
/// value range per instance, merge operand size, distribution;
88+
/// sketch-bench#147). Carried opaquely, like a synthetic workload
89+
/// description; absent in tables written before it existed.
90+
#[serde(default, skip_serializing_if = "Option::is_none")]
91+
pub measured_at: Option<Value>,
8692
}
8793

8894
pub type AtomicCostTable = Vec<AtomicCostEntry>;
@@ -572,6 +578,23 @@ mod tests {
572578
assert!(serde_json::from_str::<AtomicCostEntry>(json).is_err());
573579
}
574580

581+
/// sketch-bench#147 adds `measured_at`; it loads, and older rows without
582+
/// it still do. Other unknown fields are still refused.
583+
#[test]
584+
fn atomic_cost_entry_accepts_optional_measured_at() {
585+
let base = r#""sketch":"kll-percall","sketch_config":null,"mem_bytes_per_instance":1.0,"insert_cpu_secs":1.0,"merge_cpu_secs":1.0,"query_cpu_secs":1.0,"query_accuracy":{}"#;
586+
let with = format!(
587+
r#"{{{base},"measured_at":{{"items_per_instance":1000000,"keys_per_instance":100000,"value_range":[1.0,100000.0],"merge_operand_items":62500,"distribution":{{"kind":"zipf","skewness":1.1,"population_size":100000,"seed":42}}}}}}"#
588+
);
589+
let entry: AtomicCostEntry = serde_json::from_str(&with).unwrap();
590+
assert_eq!(entry.measured_at.unwrap()["items_per_instance"], 1_000_000);
591+
let without: AtomicCostEntry = serde_json::from_str(&format!("{{{base}}}")).unwrap();
592+
assert!(without.measured_at.is_none());
593+
assert!(
594+
serde_json::from_str::<AtomicCostEntry>(&format!(r#"{{{base},"other":1}}"#)).is_err()
595+
);
596+
}
597+
575598
#[test]
576599
fn optional_loader_rejects_an_unselected_document() {
577600
let document = tempfile::NamedTempFile::new().unwrap();
@@ -594,6 +617,7 @@ mod tests {
594617
merge_cpu_secs: 4.5e-4,
595618
query_cpu_secs: 7.8e-8,
596619
query_accuracy: BTreeMap::new(),
620+
measured_at: None,
597621
}
598622
}
599623

@@ -616,6 +640,7 @@ mod tests {
616640
merge_cpu_secs: 4.0,
617641
query_cpu_secs: 8.0,
618642
query_accuracy: BTreeMap::new(),
643+
measured_at: None,
619644
}
620645
}
621646

@@ -792,6 +817,7 @@ mod tests {
792817
merge_cpu_secs: 2.76e-4,
793818
query_cpu_secs: 1.23e-4,
794819
query_accuracy: BTreeMap::new(),
820+
measured_at: None,
795821
}];
796822
let hll_params = HashMap::from([("precision".to_string(), Value::from(14u64))]);
797823
assert!(resolve_atomic_costs(&hll_table, AggregationType::HLL, &hll_params, 0).is_some());
@@ -804,6 +830,7 @@ mod tests {
804830
merge_cpu_secs: 1.0e-3,
805831
query_cpu_secs: 1.6e-4,
806832
query_accuracy: BTreeMap::new(),
833+
measured_at: None,
807834
}];
808835
let kll_params = HashMap::from([("K".to_string(), Value::from(200u64))]);
809836
assert!(

‎asap-planner-rs/src/optimizer/greedy.rs‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -237,6 +237,7 @@ mod tests {
237237
merge_cpu_secs: 0.0,
238238
query_cpu_secs: 0.0,
239239
query_accuracy: std::collections::BTreeMap::new(),
240+
measured_at: None,
240241
}];
241242
let aqe = make_aqe(Statistic::Topk, 60_000, 60_000, 1.0 / 60.0);
242243
let solution = greedy_assign(
@@ -275,6 +276,7 @@ mod tests {
275276
merge_cpu_secs: 0.0,
276277
query_cpu_secs: 0.0,
277278
query_accuracy: std::collections::BTreeMap::new(),
279+
measured_at: None,
278280
}];
279281
let mut aqe = make_aqe(Statistic::Sum, 60_000, 60_000, 1.0 / 60.0);
280282
aqe.requirements.grouping_labels = KeyByLabelNames::new(vec!["svc".into()]);

0 commit comments

Comments
 (0)