Skip to content

Commit 54225e0

Browse files
committed
Accept legacy native metric dependencies
1 parent ed1cee8 commit 54225e0

3 files changed

Lines changed: 48 additions & 0 deletions

File tree

sidemantic-rs/src/config/schema.rs

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,8 @@ pub struct MetricConfig {
134134
pub agg: Option<String>,
135135
#[serde(default, alias = "expr", alias = "measure")]
136136
pub sql: Option<String>,
137+
#[serde(default, rename = "metrics", skip_serializing_if = "Option::is_none")]
138+
_legacy_metric_dependencies: Option<Vec<String>>,
137139
pub numerator: Option<String>,
138140
pub denominator: Option<String>,
139141
pub offset_window: Option<String>,
@@ -1359,6 +1361,27 @@ models:
13591361
);
13601362
}
13611363

1364+
#[test]
1365+
fn test_native_yaml_accepts_legacy_metric_dependencies() {
1366+
let yaml = r#"
1367+
version: 1
1368+
metrics:
1369+
- name: revenue_per_order
1370+
type: derived
1371+
sql: revenue / order_count
1372+
metrics:
1373+
- revenue
1374+
- order_count
1375+
"#;
1376+
1377+
let config: SidemanticConfig = serde_yaml::from_str(yaml).unwrap();
1378+
let (_, metrics, _) = config.into_parts().unwrap();
1379+
1380+
assert_eq!(metrics.len(), 1);
1381+
assert_eq!(metrics[0].name, "revenue_per_order");
1382+
assert_eq!(metrics[0].sql.as_deref(), Some("revenue / order_count"));
1383+
}
1384+
13621385
#[test]
13631386
fn test_native_yaml_rejects_auto_dimensions_true() {
13641387
let yaml = r#"

sidemantic/adapters/sidemantic.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@
8181
"sql",
8282
"expr",
8383
"measure",
84+
"metrics",
8485
"numerator",
8586
"denominator",
8687
"offset_window",

tests/adapters/sidemantic_adapter/test_parsing.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,30 @@ def test_parse_native_yaml_accepts_compatibility_aliases(tmp_path):
138138
assert orders.metrics[1].sql == "total_revenue / order_count"
139139

140140

141+
def test_parse_native_yaml_accepts_legacy_metric_dependencies(tmp_path):
142+
"""Legacy exported derived metrics used `metrics` for dependency hints."""
143+
adapter = SidemanticAdapter()
144+
yaml_path = tmp_path / "metrics.yml"
145+
yaml_path.write_text(
146+
"""
147+
version: 1
148+
metrics:
149+
- name: revenue_per_order
150+
type: derived
151+
sql: total_revenue / order_count
152+
metrics:
153+
- total_revenue
154+
- order_count
155+
"""
156+
)
157+
158+
graph = adapter.parse(yaml_path)
159+
160+
metric = graph.metrics["revenue_per_order"]
161+
assert metric.type == "derived"
162+
assert metric.sql == "total_revenue / order_count"
163+
164+
141165
@pytest.mark.parametrize(
142166
("yaml_body", "error_text"),
143167
[

0 commit comments

Comments
 (0)