:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.
Python ab-testingai-analyticsanalyticscdpdata-warehouseexperimentsfeature-flagsjavascriptproduct-analyticspythonreactsession-replaysurveystypescriptweb-analytics
fix(cohorts): match seeder clickhouse tests to clickhouse 26.9 json parsing (#114769)
Rory Shanksbe301e502035
diff --git a/rust/cohort-seeder/tests/ch_materialized_properties.rs b/rust/cohort-seeder/tests/ch_materialized_properties.rsindex 460866eb1391..f6ccec3d17af 100644--- a/rust/cohort-seeder/tests/ch_materialized_properties.rs+++ b/rust/cohort-seeder/tests/ch_materialized_properties.rs@@ -49,8 +49,6 @@ const LITERALS: &[&str] = &[#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord)]enum Residual {- /// Every column stores `''` while `serde_json` reads the blob.- BlobClickHouseCannotParse,/// The column holds the first value, `serde_json` the last.RepeatedKey,/// Comes back typed and too deep for `serde_json`.@@ -63,9 +61,7 @@ impl Residual {const fn divergence(self) -> Divergence {match self {Self::UnreadableBlob => Divergence::OverCount,- Self::BlobClickHouseCannotParse | Self::StringHoldingDeepJson | Self::RepeatedKey => {- Divergence::UnderCount- }+ Self::StringHoldingDeepJson | Self::RepeatedKey => Divergence::UnderCount,}}}@@ -182,10 +178,7 @@ fn corpus() -> Vec<Case> {r#"{"$current_url":"elsewhere","$current_url":"https://example.com/"}"#,Residual::RepeatedKey,),- Case::residual(- r#"{"$current_url":"https://example.com/","n":18446744073709551616}"#,- Residual::BlobClickHouseCannotParse,- ),+ Case::exact(r#"{"$current_url":"https://example.com/","n":18446744073709551616}"#),Case::residual(json!({URL: "https://example.com/",diff --git a/rust/cohort-seeder/tests/ch_person_key_filter.rs b/rust/cohort-seeder/tests/ch_person_key_filter.rsindex 77e1329d4e5b..2987de7e075b 100644--- a/rust/cohort-seeder/tests/ch_person_key_filter.rs+++ b/rust/cohort-seeder/tests/ch_person_key_filter.rs@@ -11,8 +11,7 @@//! is the whole saving. Every other blob must be admitted, because the seeder decides those: an//! array errors in the VM, a scalar and a literal `null` read every key as null, an empty blob//! parses to `{}` and is decided from the cached vacuous verdict, a malformed blob is a skipped-//! row, and a document holding a number ClickHouse cannot represent also reports `Null` while-//! `serde_json` parses it and the VM reads its keys.+//! row, and a document holding a float ClickHouse cannot represent also reports `Null`.//!//! Needs a reachable ClickHouse, which is why it sits behind `ch-test-support`. It reads its//! endpoint through the seeder's own `Config`/`build_client`, so it also exercises the client-side@@ -100,13 +99,14 @@ const CORPUS: &[Case] = &[case(r#"{not json"#, &["email"]),case(r#"{"email":1,"#, &["email"]),case(r#"{'email':1}"#, &["email"]),- // The case the plan's tighter predicate would have dropped: ClickHouse gives up on the whole- // document over a number it cannot represent and reports `Null`, while `serde_json` parses it- // and the VM reads `email` — so this person is a member the scan must not drop.+ // ClickHouse parses an integer past the 64-bit range, so this blob is an object that carries+ // `email` and the filter admits it on its keys.case(r#"{"email":"[email protected]","big":123456789012345678901234567890}"#,&["email"],),+ // ClickHouse gives up on the whole document over a float it cannot represent and reports+ // `Null`, so the filter admits it with the other non-objects.case(r#"{"email":"[email protected]","huge":1e309}"#, &["email"]),// Many keys, one read: the shape the filter exists for.case(diff --git a/rust/cohort-seeder/tests/ch_rebuild_equivalence.rs b/rust/cohort-seeder/tests/ch_rebuild_equivalence.rsindex 11a2973031ea..6d7056924a46 100644--- a/rust/cohort-seeder/tests/ch_rebuild_equivalence.rs+++ b/rust/cohort-seeder/tests/ch_rebuild_equivalence.rs@@ -57,7 +57,10 @@ const CORPUS: &[Case] = &[r#"{"nul":null,"yes":true,"no":false}"#,&["nul", "yes", "no"],),- case(r#"{"big":123456789012345678901234567890}"#, &["big"]),+ case(+ r#"{"plan":"paid","big":123456789012345678901234567890}"#,+ &["plan"],+ ),case(r#"{"tiny":-1.5e-300,"round":1.0,"zero":-0.0}"#,&["tiny", "round", "zero"],@@ -207,20 +210,55 @@ async fn a_blob_too_deep_for_serde_but_not_for_clickhouse_diverges() {);}-/// ClickHouse gives up on the whole document when any number token is outside what it can-/// represent, wherever that token sits: `JSONType` reports `Null`, so the rebuild's guard passes-/// the blob through verbatim. The projected row is then byte-identical to the wide scan's row,-/// which is zero evaluation divergence, just wider than the pruned oracle. That is why this sits-/// beside the depth pin instead of weakening the main assertion.+/// ClickHouse gives up on the whole document when a float token is outside what it can represent,+/// wherever that token sits: `JSONType` reports `Null`, so the rebuild's guard passes the blob+/// through verbatim. The projected row is then byte-identical to the wide scan's row, which is zero+/// evaluation divergence, just wider than the pruned oracle. That is why this sits beside the depth+/// pin instead of weakening the main assertion.#[tokio::test]async fn a_number_clickhouse_cannot_represent_passes_the_whole_blob_through() {let client = connect();- for blob in [- r#"{"plan":"paid","big":123456789012345678901234567890}"#,- r#"{"plan":"paid","huge":1e309}"#,+ let blob = r#"{"plan":"paid","huge":1e309}"#;+ let rebuilt = rebuild_all(&client, &["plan"], &[blob]).await;+ assert_eq!(rebuilt[0], blob, "expected verbatim passthrough");+}++/// ClickHouse parses an integer past the 64-bit range, but `JSONExtractKeysAndValuesRaw` returns it+/// as a quoted string, while `serde_json` reads the original token as a number. So a read key that+/// holds such an integer reaches the VM as a string in the seeded row and as a number in the live+/// row, and a condition on that key can evaluate differently. Pinned rather than hedged because+/// the fix belongs in ClickHouse: the rebuild must stay on the simdjson parser.+#[tokio::test]+async fn an_integer_past_64_bits_rebuilds_as_a_string() {+ let client = connect();+ for (blob, digits) in [+ (+ r#"{"plan":"paid","big":123456789012345678901234567890}"#,+ "123456789012345678901234567890",+ ),+ (+ r#"{"plan":"paid","big":18446744073709551616}"#,+ "18446744073709551616",+ ),+ (+ r#"{"plan":"paid","big":-9223372036854775809}"#,+ "-9223372036854775809",+ ),] {- let rebuilt = rebuild_all(&client, &["plan"], &[blob]).await;- assert_eq!(rebuilt[0], blob, "expected verbatim passthrough");+ let rebuilt = rebuild_all(&client, &["big"], &[blob]).await;+ assert_eq!(+ parse(&rebuilt[0]),+ Ok(Value::Object(Map::from_iter([(+ "big".to_owned(),+ Value::String(digits.to_owned())+ )]))),+ "{blob} rebuilt as {}",+ rebuilt[0]+ );+ assert!(+ matches!(parse(blob), Ok(Value::Object(map)) if map["big"].is_number()),+ "serde_json is meant to read {blob} as a number"+ );}}