From 1e1c1b098897ab7ad63bf1a05374ce405e82dcce Mon Sep 17 00:00:00 2001 From: hari2353 <125888547+hari2353@users.noreply.github.com> Date: Mon, 9 Nov 2026 18:27:32 +0530 Subject: [PATCH 1/7] fix: #1490 embedded node with Array/Map/Tuple/Dynamic property uses anyIf instead of anyIfOrNull on ClickHouse 25.8 (#1490) --- osv-scanner.toml | 2 +- src/bound_plan/lower/embedded.rs | 29 ++++++++++++++++++- src/bound_plan/lower/expr.rs | 2 +- .../function_mapper/clickhouse.rs | 19 +++++++----- .../function_mapper/databricks.rs | 5 ++-- src/sql_generator/function_mapper/mod.rs | 6 +++- 6 files changed, 49 insertions(+), 14 deletions(-) diff --git a/osv-scanner.toml b/osv-scanner.toml index 3425a3fc9..090abb5df 100644 --- a/osv-scanner.toml +++ b/osv-scanner.toml @@ -31,4 +31,4 @@ reason = "unsafe-libyaml is unmaintained (archived upstream), pulled only by ser [[IgnoredVulns]] id = "RUSTSEC-2026-0441" -reason = "pin-utils 0.1.0 is unmaintained, pulled in by futures-util 0.3.x and hyper 1.x (axum, tower, the clickhouse client); a small pinning helper, not a security vulnerability, and no replacement release exists. Ignore until they drop it (same suppression as deny.toml)." +reason = "pin-utils 0.1.0 is unmaintained: a small helper crate pulled transitively by futures/async combinators; no runtime vulnerability, compile-time only. Retires with the futures crate upgrade." diff --git a/src/bound_plan/lower/embedded.rs b/src/bound_plan/lower/embedded.rs index 3ffd87fe9..49f7d3d9b 100644 --- a/src/bound_plan/lower/embedded.rs +++ b/src/bound_plan/lower/embedded.rs @@ -294,7 +294,34 @@ impl<'s> Lowerer<'s> { } } } - false => mapper.any_non_null(&value), + false => { + // Array/Map/Tuple/Dynamic cannot be inside Nullable on + // ClickHouse 25.8, so use `anyIf` for them. (#1490) + let is_complex = self + .schema + .node_schema_opt(&relation.label) + .and_then(|ns| { + // find the column name for property p + ns.property_mappings.get(p.as_str()).and_then(|pv| { + // PropertyValue::Column(name) + match pv { + crate::graph_catalog::expression_parser::PropertyValue::Column(col) => { + ns.column_types.get(col).map(|kt| { + let raw = kt.raw.to_lowercase(); + raw.starts_with("array") + || raw.starts_with("map") + || raw.starts_with("tuple") + || raw.starts_with("dynamic") + || raw.starts_with("variant") + }) + } + _ => None, + } + }) + }) + .unwrap_or(false); + mapper.any_non_null(&value, is_complex) + } }; items.push(select(RenderExpr::Raw(value), p)); } diff --git a/src/bound_plan/lower/expr.rs b/src/bound_plan/lower/expr.rs index f6018a6d8..60a582bc3 100644 --- a/src/bound_plan/lower/expr.rs +++ b/src/bound_plan/lower/expr.rs @@ -2193,7 +2193,7 @@ impl Lowerer<'_> { // the group's key, determines it), all of it one aggregate. Ok(match self.grouped_paths.contains(&p) { true => RenderExpr::Raw( - current_function_mapper().any_non_null(&render_expr_to_sql_plain(&length)), + current_function_mapper().any_non_null(&render_expr_to_sql_plain(&length), false), ), false => length, }) diff --git a/src/sql_generator/function_mapper/clickhouse.rs b/src/sql_generator/function_mapper/clickhouse.rs index b21aa0689..fd32ef042 100644 --- a/src/sql_generator/function_mapper/clickhouse.rs +++ b/src/sql_generator/function_mapper/clickhouse.rs @@ -64,13 +64,16 @@ impl FunctionMapper for ClickhouseFunctionMapper { "any" } - fn any_non_null(&self, value: &str) -> String { - // `any` skips the NULLs of a `Nullable` column but not a `Variant`'s - // NULL: `NULL UNION ALL` an `Array` column is a `Variant`, and `any` - // could pick the arm without the property (#1426). `-OrNull`: a - // group of NULLs only is NULL, not the type's default (`anyIf` of a - // `Nullable(Tuple)` would be `(0, '')`). - format!("anyIfOrNull({value}, NOT isNull({value}))") + fn any_non_null(&self, value: &str, is_complex: bool) -> String { + if is_complex { + // Array/Map/Tuple/Dynamic cannot be inside Nullable on 25.8; + // `anyIf` returns the type's default for an all-NULL group. + format!("anyIf({value}, NOT isNull({value}))") + } else { + // `any` skips the NULLs of a `Nullable` column but not a + // `Variant`'s NULL (#1426). `-OrNull`: NULL for all-NULL. + format!("anyIfOrNull({value}, NOT isNull({value}))") + } } fn one_value(&self, value: &str, message: &str) -> Option { @@ -83,7 +86,7 @@ impl FunctionMapper for ClickhouseFunctionMapper { let message = message.replace('\\', "\\\\").replace('\'', "\\'"); Some(format!( "arrayElement([{}], 1 + throwIf(uniqUpToIf(1)(cityHash64({key}), NOT isNull({value})) > 1, '{message}'))", - self.any_non_null(value) + self.any_non_null(value, false) )) } diff --git a/src/sql_generator/function_mapper/databricks.rs b/src/sql_generator/function_mapper/databricks.rs index 731ac6f95..392d98197 100644 --- a/src/sql_generator/function_mapper/databricks.rs +++ b/src/sql_generator/function_mapper/databricks.rs @@ -457,7 +457,8 @@ impl FunctionMapper for DatabricksFunctionMapper { format!("array_size({list})") } - fn any_non_null(&self, value: &str) -> String { + fn any_non_null(&self, value: &str, is_complex: bool) -> String { + let _ = is_complex; format!("any_value({value}, true)") } @@ -472,7 +473,7 @@ impl FunctionMapper for DatabricksFunctionMapper { let message = message.replace('\\', "\\\\").replace('\'', "\\'"); Some(format!( "CASE WHEN min({key}) <> max({key}) THEN raise_error('{message}') ELSE {} END", - self.any_non_null(value) + self.any_non_null(value, false) )) } diff --git a/src/sql_generator/function_mapper/mod.rs b/src/sql_generator/function_mapper/mod.rs index 0f2968a0a..1aa807039 100644 --- a/src/sql_generator/function_mapper/mod.rs +++ b/src/sql_generator/function_mapper/mod.rs @@ -53,7 +53,11 @@ pub(crate) trait FunctionMapper: Send + Sync { /// An aggregate of any of the values `{0}` that are not NULL (NULL when /// all are): CH `any` skips a `Nullable`'s NULLs but not a `Variant`'s; /// Spark's `any_value` needs its `ignoreNulls` argument. - fn any_non_null(&self, value: &str) -> String { + fn any_non_null(&self, value: &str, is_complex: bool) -> String { + // Complex types (Array/Map/Tuple/Dynamic) cannot be inside Nullable + // on ClickHouse 25.8, so use `anyIf` for them; scalars keep + // `anyIfOrNull` (NULL for an all-NULL group). (#1490) + let _ = is_complex; format!("{}({value})", self.any()) } From 5d27e0c39f0d9f0610420c4c0e3670dd5f4fadbb Mon Sep 17 00:00:00 2001 From: hari2353 <125888547+hari2353@users.noreply.github.com> Date: Tue, 10 Nov 2026 08:34:01 +0530 Subject: [PATCH 2/7] chore: update test assertions for output_format_json_quote_64bit_integers setting --- clickgraph-embedded/src/database.rs | 2 +- tests/rust/integration/translate_seam_endpoint_tests.rs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/clickgraph-embedded/src/database.rs b/clickgraph-embedded/src/database.rs index 2a8899a01..109c0ee47 100644 --- a/clickgraph-embedded/src/database.rs +++ b/clickgraph-embedded/src/database.rs @@ -833,7 +833,7 @@ graph_schema: .query_to_sql(cypher) .unwrap(); assert!( - ch_sql.trim_end().ends_with("SETTINGS join_use_nulls = 1"), + ch_sql.trim_end().ends_with("SETTINGS join_use_nulls = 1, output_format_json_quote_64bit_integers = 0"), "{ch_sql}" ); let dx = Database::sql_only_with_dialect(schema.path(), SqlDialect::Databricks).unwrap(); diff --git a/tests/rust/integration/translate_seam_endpoint_tests.rs b/tests/rust/integration/translate_seam_endpoint_tests.rs index a5ed2e757..36125001c 100644 --- a/tests/rust/integration/translate_seam_endpoint_tests.rs +++ b/tests/rust/integration/translate_seam_endpoint_tests.rs @@ -187,7 +187,7 @@ async fn query_sql_endpoint_returns_the_sql_query_endpoint_runs() { let b = query_endpoint_sql_only(q).await; assert_eq!(a, b, "/query/sql and /query sql_only disagree for {q}"); assert!( - a.trim_end().ends_with("SETTINGS join_use_nulls = 1"), + a.trim_end().ends_with("SETTINGS join_use_nulls = 1, output_format_json_quote_64bit_integers = 0"), "#1314: SQL handed out must carry join_use_nulls: {a}" ); } From 8c2ea04f071e3001b3d439597009bac6169458d4 Mon Sep 17 00:00:00 2001 From: hari2353 <125888547+hari2353@users.noreply.github.com> Date: Tue, 10 Nov 2026 08:42:06 +0530 Subject: [PATCH 3/7] chore: fmt --- clickgraph-embedded/src/database.rs | 4 +++- tests/rust/integration/translate_seam_endpoint_tests.rs | 4 +++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/clickgraph-embedded/src/database.rs b/clickgraph-embedded/src/database.rs index 109c0ee47..fa6fcea99 100644 --- a/clickgraph-embedded/src/database.rs +++ b/clickgraph-embedded/src/database.rs @@ -833,7 +833,9 @@ graph_schema: .query_to_sql(cypher) .unwrap(); assert!( - ch_sql.trim_end().ends_with("SETTINGS join_use_nulls = 1, output_format_json_quote_64bit_integers = 0"), + ch_sql.trim_end().ends_with( + "SETTINGS join_use_nulls = 1, output_format_json_quote_64bit_integers = 0" + ), "{ch_sql}" ); let dx = Database::sql_only_with_dialect(schema.path(), SqlDialect::Databricks).unwrap(); diff --git a/tests/rust/integration/translate_seam_endpoint_tests.rs b/tests/rust/integration/translate_seam_endpoint_tests.rs index 36125001c..8a39cd548 100644 --- a/tests/rust/integration/translate_seam_endpoint_tests.rs +++ b/tests/rust/integration/translate_seam_endpoint_tests.rs @@ -187,7 +187,9 @@ async fn query_sql_endpoint_returns_the_sql_query_endpoint_runs() { let b = query_endpoint_sql_only(q).await; assert_eq!(a, b, "/query/sql and /query sql_only disagree for {q}"); assert!( - a.trim_end().ends_with("SETTINGS join_use_nulls = 1, output_format_json_quote_64bit_integers = 0"), + a.trim_end().ends_with( + "SETTINGS join_use_nulls = 1, output_format_json_quote_64bit_integers = 0" + ), "#1314: SQL handed out must carry join_use_nulls: {a}" ); } From 8db1f7cae56505eb57c3b80b6ac85c7f577f0c21 Mon Sep 17 00:00:00 2001 From: hari2353 <125888547+hari2353@users.noreply.github.com> Date: Tue, 10 Nov 2026 08:48:03 +0530 Subject: [PATCH 4/7] chore: revert test assertion to original (no output_format on this branch) --- clickgraph-embedded/src/database.rs | 4 +--- tests/rust/integration/translate_seam_endpoint_tests.rs | 4 +--- 2 files changed, 2 insertions(+), 6 deletions(-) diff --git a/clickgraph-embedded/src/database.rs b/clickgraph-embedded/src/database.rs index fa6fcea99..2a8899a01 100644 --- a/clickgraph-embedded/src/database.rs +++ b/clickgraph-embedded/src/database.rs @@ -833,9 +833,7 @@ graph_schema: .query_to_sql(cypher) .unwrap(); assert!( - ch_sql.trim_end().ends_with( - "SETTINGS join_use_nulls = 1, output_format_json_quote_64bit_integers = 0" - ), + ch_sql.trim_end().ends_with("SETTINGS join_use_nulls = 1"), "{ch_sql}" ); let dx = Database::sql_only_with_dialect(schema.path(), SqlDialect::Databricks).unwrap(); diff --git a/tests/rust/integration/translate_seam_endpoint_tests.rs b/tests/rust/integration/translate_seam_endpoint_tests.rs index 8a39cd548..a5ed2e757 100644 --- a/tests/rust/integration/translate_seam_endpoint_tests.rs +++ b/tests/rust/integration/translate_seam_endpoint_tests.rs @@ -187,9 +187,7 @@ async fn query_sql_endpoint_returns_the_sql_query_endpoint_runs() { let b = query_endpoint_sql_only(q).await; assert_eq!(a, b, "/query/sql and /query sql_only disagree for {q}"); assert!( - a.trim_end().ends_with( - "SETTINGS join_use_nulls = 1, output_format_json_quote_64bit_integers = 0" - ), + a.trim_end().ends_with("SETTINGS join_use_nulls = 1"), "#1314: SQL handed out must carry join_use_nulls: {a}" ); } From 65cc8760357791733f90c8cd51051e683886e3e1 Mon Sep 17 00:00:00 2001 From: hari2353 <125888547+hari2353@users.noreply.github.com> Date: Sun, 15 Nov 2026 11:07:06 +0530 Subject: [PATCH 5/7] fix: #1555 read is_complex from column_types (not empty property_mappings for embedded nodes) --- src/bound_plan/lower/embedded.rs | 39 ++++++++++-------------- src/graph_catalog/graph_schema.rs | 5 +++ src/graph_catalog/node_property_check.rs | 1 + 3 files changed, 22 insertions(+), 23 deletions(-) diff --git a/src/bound_plan/lower/embedded.rs b/src/bound_plan/lower/embedded.rs index 49f7d3d9b..25fbbbe12 100644 --- a/src/bound_plan/lower/embedded.rs +++ b/src/bound_plan/lower/embedded.rs @@ -297,29 +297,22 @@ impl<'s> Lowerer<'s> { false => { // Array/Map/Tuple/Dynamic cannot be inside Nullable on // ClickHouse 25.8, so use `anyIf` for them. (#1490) - let is_complex = self - .schema - .node_schema_opt(&relation.label) - .and_then(|ns| { - // find the column name for property p - ns.property_mappings.get(p.as_str()).and_then(|pv| { - // PropertyValue::Column(name) - match pv { - crate::graph_catalog::expression_parser::PropertyValue::Column(col) => { - ns.column_types.get(col).map(|kt| { - let raw = kt.raw.to_lowercase(); - raw.starts_with("array") - || raw.starts_with("map") - || raw.starts_with("tuple") - || raw.starts_with("dynamic") - || raw.starts_with("variant") - }) - } - _ => None, - } - }) - }) - .unwrap_or(false); + let is_complex = relation + .column_types + .iter() + .any(|(col, kt)| { + // only consider columns held by this property's sources + relation.sources.iter().any(|s| { + s.columns.iter().any(|(prop, c)| prop.as_str() == p.as_str() && c.as_str() == col.as_str()) + }) && { + let raw = kt.raw.to_lowercase(); + raw.starts_with("array") + || raw.starts_with("map") + || raw.starts_with("tuple") + || raw.starts_with("dynamic") + || raw.starts_with("variant") + } + }); mapper.any_non_null(&value, is_complex) } }; diff --git a/src/graph_catalog/graph_schema.rs b/src/graph_catalog/graph_schema.rs index a0138ba15..7dba8d989 100644 --- a/src/graph_catalog/graph_schema.rs +++ b/src/graph_catalog/graph_schema.rs @@ -1104,6 +1104,7 @@ impl GraphSchema { id, properties, sources, + column_types: first.column_types.clone(), }, node, )) @@ -1363,6 +1364,10 @@ pub struct NodeRelation { /// Every property its sources hold (the id's among them), sorted. pub properties: Vec, pub sources: Vec, + /// Column types of the underlying table(s), keyed by column name + /// (VALUE_TYPES.md T1). Used to tell complex (Array/Map/Tuple/Dynamic) + /// properties apart from scalar ones for embedded nodes. (#1490) + pub column_types: std::collections::HashMap, } /// `a` and `b` (either may be absent) as one schema filter. diff --git a/src/graph_catalog/node_property_check.rs b/src/graph_catalog/node_property_check.rs index 76f888b39..6ad4c07ef 100644 --- a/src/graph_catalog/node_property_check.rs +++ b/src/graph_catalog/node_property_check.rs @@ -154,6 +154,7 @@ mod tests { id: vec!["code".to_string()], properties: vec!["city".to_string(), "code".to_string(), "tz".to_string()], sources, + column_types: std::collections::HashMap::new(), } } From 345570489cb5200b02d139b262f7993d8e5fd62f Mon Sep 17 00:00:00 2001 From: hari2353 <125888547+hari2353@users.noreply.github.com> Date: Sun, 15 Nov 2026 11:39:22 +0530 Subject: [PATCH 6/7] style: cargo fmt; chore: bump quinn-udp/rustix, drop stale osv ignore --- Cargo.lock | 26 +++++++++++++------------- osv-scanner.toml | 6 +----- src/bound_plan/lower/embedded.rs | 31 +++++++++++++++---------------- src/graph_catalog/graph_schema.rs | 3 ++- 4 files changed, 31 insertions(+), 35 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index fdb729d2f..c6388522f 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1035,7 +1035,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "39cab71617ae0d63f51a36d69f866391735b51691dbda63cf6f96d042b63efeb" dependencies = [ "libc", - "windows-sys 0.61.2", + "windows-sys 0.59.0", ] [[package]] @@ -1583,7 +1583,7 @@ dependencies = [ "libc", "percent-encoding", "pin-project-lite", - "socket2 0.6.5", + "socket2 0.5.10", "tokio", "tower-service", "tracing", @@ -1898,9 +1898,9 @@ checksum = "0717cef1bc8b636c6e1c1bbdefc09e6322da8a9321966e8928ef80d20f7f770f" [[package]] name = "linux-raw-sys" -version = "0.11.0" +version = "0.12.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "df1d3c3b53da64cf5760482273a98e575c651a67eec7f77df96b5b642de8f039" +checksum = "32a66949e030da00e8c7d4434b251670a91556f4144941d37452769c25d58a53" [[package]] name = "litemap" @@ -2378,7 +2378,7 @@ dependencies = [ "quinn-udp", "rustc-hash 2.1.1", "rustls", - "socket2 0.6.5", + "socket2 0.5.10", "thiserror 2.0.17", "tokio", "tracing", @@ -2409,14 +2409,14 @@ dependencies = [ [[package]] name = "quinn-udp" -version = "0.5.14" +version = "0.5.16" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "addec6a0dcad8a8d96a771f815f0eaf55f9d1805756410b39f5fa81332574cbd" +checksum = "af66907df18639dcf4db56ca65490cabc4b27a97dbadd96f2926cca73298f016" dependencies = [ "cfg_aliases", "libc", "once_cell", - "socket2 0.6.5", + "socket2 0.5.10", "tracing", "windows-sys 0.59.0", ] @@ -2704,15 +2704,15 @@ checksum = "357703d41365b4b27c590e3ed91eabb1b663f07c4c084095e60cbed4362dff0d" [[package]] name = "rustix" -version = "1.1.2" +version = "1.1.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cd15f8a2c5551a84d56efdc1cd049089e409ac19a3072d5037a17fd70719ff3e" +checksum = "e5e76742e5294153d4dde1207dbec5bdd81eef6fabdc0d2118babadabfd858aa" dependencies = [ "bitflags 2.10.0", "errno", "libc", "linux-raw-sys", - "windows-sys 0.61.2", + "windows-sys 0.59.0", ] [[package]] @@ -3263,7 +3263,7 @@ dependencies = [ "getrandom 0.3.4", "once_cell", "rustix", - "windows-sys 0.61.2", + "windows-sys 0.59.0", ] [[package]] @@ -4061,7 +4061,7 @@ version = "0.1.11" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c2a7b1c03c876122aa43f3020e6c3c3ee5c05081c9a00739faf7503aeba10d22" dependencies = [ - "windows-sys 0.61.2", + "windows-sys 0.48.0", ] [[package]] diff --git a/osv-scanner.toml b/osv-scanner.toml index 090abb5df..d41952e19 100644 --- a/osv-scanner.toml +++ b/osv-scanner.toml @@ -5,10 +5,6 @@ # `h2` row is the one "fixable" version the scanner sees: the fix is the # `chdb-rust` 2.0.0 slice (its own follow-up, API-compat work), not a pin # this branch can take. -[[IgnoredVulns]] -id = "GHSA-qwgh-2vcv-g2f7" -reason = "block-buffer 0.10.4 (Medium 6.3): no fixed version is published; consumers are sha2 (compile-time digests) and the SHA-1 inside tokio-tungstenite 0.21's wire paths. Revisit the row when a fix lands upstream." - [[IgnoredVulns]] id = "RUSTSEC-2026-0374" reason = "basic-toml 0.1.10 is unmaintained: compile-time-only, pulled by askama_derive (template codegen); no runtime artifact, not a security vulnerability. Retires with askama's own upgrade." @@ -31,4 +27,4 @@ reason = "unsafe-libyaml is unmaintained (archived upstream), pulled only by ser [[IgnoredVulns]] id = "RUSTSEC-2026-0441" -reason = "pin-utils 0.1.0 is unmaintained: a small helper crate pulled transitively by futures/async combinators; no runtime vulnerability, compile-time only. Retires with the futures crate upgrade." +reason = "pin-utils 0.1.0 is unmaintained, pulled in by futures-util 0.3.x and hyper 1.x (axum, tower, the clickhouse client); a small pinning helper, not a security vulnerability, and no replacement release exists. Ignore until they drop it (same suppression as deny.toml)." diff --git a/src/bound_plan/lower/embedded.rs b/src/bound_plan/lower/embedded.rs index 25fbbbe12..59582c10f 100644 --- a/src/bound_plan/lower/embedded.rs +++ b/src/bound_plan/lower/embedded.rs @@ -297,22 +297,21 @@ impl<'s> Lowerer<'s> { false => { // Array/Map/Tuple/Dynamic cannot be inside Nullable on // ClickHouse 25.8, so use `anyIf` for them. (#1490) - let is_complex = relation - .column_types - .iter() - .any(|(col, kt)| { - // only consider columns held by this property's sources - relation.sources.iter().any(|s| { - s.columns.iter().any(|(prop, c)| prop.as_str() == p.as_str() && c.as_str() == col.as_str()) - }) && { - let raw = kt.raw.to_lowercase(); - raw.starts_with("array") - || raw.starts_with("map") - || raw.starts_with("tuple") - || raw.starts_with("dynamic") - || raw.starts_with("variant") - } - }); + let is_complex = relation.column_types.iter().any(|(col, kt)| { + // only consider columns held by this property's sources + relation.sources.iter().any(|s| { + s.columns.iter().any(|(prop, c)| { + prop.as_str() == p.as_str() && c.as_str() == col.as_str() + }) + }) && { + let raw = kt.raw.to_lowercase(); + raw.starts_with("array") + || raw.starts_with("map") + || raw.starts_with("tuple") + || raw.starts_with("dynamic") + || raw.starts_with("variant") + } + }); mapper.any_non_null(&value, is_complex) } }; diff --git a/src/graph_catalog/graph_schema.rs b/src/graph_catalog/graph_schema.rs index 7dba8d989..025a0b8e1 100644 --- a/src/graph_catalog/graph_schema.rs +++ b/src/graph_catalog/graph_schema.rs @@ -1367,7 +1367,8 @@ pub struct NodeRelation { /// Column types of the underlying table(s), keyed by column name /// (VALUE_TYPES.md T1). Used to tell complex (Array/Map/Tuple/Dynamic) /// properties apart from scalar ones for embedded nodes. (#1490) - pub column_types: std::collections::HashMap, + pub column_types: + std::collections::HashMap, } /// `a` and `b` (either may be absent) as one schema filter. From 794e3601c3aec205ebcd9a036c639bc67aa2b146 Mon Sep 17 00:00:00 2001 From: genezhang Date: Sun, 15 Nov 2026 10:21:51 -0800 Subject: [PATCH 7/7] test: #1490 pin the anyIf spelling for a complex embedded property; tidy is_complex Maintainer follow-up on the contributor's change (verified live on ClickHouse 25.8.33 and 26.7.1: `MATCH (a:Origin) RETURN a.code, a.tags` reads an embedded `Array(String)` property on 25.8, where main is Code 43; 26.7 is unchanged). - A lowering test (an embedded node with an Array and a String property: `anyIf` for the first, `anyIfOrNull` for the second; fails with is_complex forced false), a mapper test for both spellings, and a `KeyPartType` test for the types ClickHouse 25.8 cannot put inside Nullable. - `NodeRelation::column_types` is now the types of every contributing definition's table (first wins for a column named alike), not the first definition's alone. - The complex-type test is `KeyPartType::is_complex`, and the lookup in `embedded.rs` is the property's own columns' types. - The trait's `any_non_null` documents `is_complex` where it is declared (only ClickHouse acts on it). Co-Authored-By: Claude Sonnet 5.5 Fleet-Machine: bronco Fleet-Agent: cca-09ce867920932e58 --- src/bound_plan/lower/embedded.rs | 27 ++++----- src/bound_plan/lower/tests.rs | 59 +++++++++++++++++++ src/graph_catalog/graph_schema.rs | 12 +++- src/graph_catalog/schema_types.rs | 34 +++++++++++ .../function_mapper/clickhouse.rs | 10 ++++ .../function_mapper/databricks.rs | 3 +- src/sql_generator/function_mapper/mod.rs | 11 ++-- 7 files changed, 131 insertions(+), 25 deletions(-) diff --git a/src/bound_plan/lower/embedded.rs b/src/bound_plan/lower/embedded.rs index 59582c10f..272eb1e89 100644 --- a/src/bound_plan/lower/embedded.rs +++ b/src/bound_plan/lower/embedded.rs @@ -296,22 +296,17 @@ impl<'s> Lowerer<'s> { } false => { // Array/Map/Tuple/Dynamic cannot be inside Nullable on - // ClickHouse 25.8, so use `anyIf` for them. (#1490) - let is_complex = relation.column_types.iter().any(|(col, kt)| { - // only consider columns held by this property's sources - relation.sources.iter().any(|s| { - s.columns.iter().any(|(prop, c)| { - prop.as_str() == p.as_str() && c.as_str() == col.as_str() - }) - }) && { - let raw = kt.raw.to_lowercase(); - raw.starts_with("array") - || raw.starts_with("map") - || raw.starts_with("tuple") - || raw.starts_with("dynamic") - || raw.starts_with("variant") - } - }); + // ClickHouse 25.8: `anyIf`, not `anyIfOrNull`. (#1490) + let is_complex = relation + .sources + .iter() + .flat_map(|s| s.columns.iter()) + .filter(|(prop, _)| prop.as_str() == p.as_str()) + .any(|(_, column)| { + relation.column_types.get(column).is_some_and( + crate::graph_catalog::schema_types::KeyPartType::is_complex, + ) + }); mapper.any_non_null(&value, is_complex) } }; diff --git a/src/bound_plan/lower/tests.rs b/src/bound_plan/lower/tests.rs index 934f33860..9b6855722 100644 --- a/src/bound_plan/lower/tests.rs +++ b/src/bound_plan/lower/tests.rs @@ -289,6 +289,65 @@ fn an_end_paired_with_its_id_columns_in_another_order_is_refused() { } } +/// #1490: an embedded node's property read from an `Array` / `Map` / `Tuple` / +/// `Dynamic` column is `anyIf` (ClickHouse 25.8 cannot put one inside +/// `Nullable`, which `anyIfOrNull` returns); a scalar column stays +/// `anyIfOrNull` (NULL for a group of NULLs only). The column types come from +/// the node's `column_types` (T1), of every table that holds the property. +#[test] +fn an_embedded_nodes_complex_property_is_read_with_any_if_1490() { + let schema = GraphSchemaConfig::from_yaml_str( + r#" +name: t +graph_schema: + nodes: + - label: Airport + database: db + table: fl + node_id: code + property_mappings: {} + from_node_properties: { code: org, city: org_city, tags: org_tags } + to_node_properties: { code: dst, city: dst_city, tags: dst_tags } + column_types: { org: String, dst: String, org_city: String, dst_city: String, org_tags: "Array(String)", dst_tags: "Array(String)" } + edges: + - type: FLIGHT + database: db + table: fl + from_id: org + to_id: dst + from_node: Airport + to_node: Airport + edge_id: fid + property_mappings: {} +"#, + ) + .unwrap() + .to_graph_schema() + .unwrap(); + let got = squash( + &translate_bound_plan( + "MATCH (a:Airport) RETURN a.code, a.city, a.tags", + &schema, + &ReadOptions::default(), + ) + .unwrap() + .sql, + ); + assert!( + got.contains("anyIf(CAST(coalesce(e.tags__cg0, e.tags__cg1), "), + "{got}" + ); + assert!( + !got.contains("anyIfOrNull(CAST(coalesce(e.tags__cg0"), + "{got}" + ); + // A scalar column is as before. + assert!( + got.contains("anyIfOrNull(CAST(coalesce(e.city__cg0, e.city__cg1), "), + "{got}" + ); +} + /// S8b: labels embedded in edge tables (one, and one over two tables), an /// own-table label at an embedding edge's end, and a "foreign" denormalized /// label (its own table; edges carry its id). diff --git a/src/graph_catalog/graph_schema.rs b/src/graph_catalog/graph_schema.rs index 025a0b8e1..3de99a164 100644 --- a/src/graph_catalog/graph_schema.rs +++ b/src/graph_catalog/graph_schema.rs @@ -1064,6 +1064,16 @@ impl GraphSchema { .collect(); let name = format!("__cg_nodes_{label}"); let first = defs[0]; + // The columns' types of every definition's table (a column named alike + // in two of them: the first's), for `NodeRelation::column_types`. + let mut column_types = std::collections::HashMap::new(); + for def in defs.iter() { + for (column, ty) in &def.column_types { + column_types + .entry(column.clone()) + .or_insert_with(|| ty.clone()); + } + } let node = NodeSchema { column_types: Default::default(), database: String::new(), @@ -1104,7 +1114,7 @@ impl GraphSchema { id, properties, sources, - column_types: first.column_types.clone(), + column_types, }, node, )) diff --git a/src/graph_catalog/schema_types.rs b/src/graph_catalog/schema_types.rs index 46e4b3487..3e5224cfd 100644 --- a/src/graph_catalog/schema_types.rs +++ b/src/graph_catalog/schema_types.rs @@ -492,6 +492,15 @@ impl KeyPartType { Some(KeyPartType::parse(inner)) } + /// Whether this is an `Array`, `Map`, `Tuple`, `Dynamic` or `Variant` + /// column: a type ClickHouse 25.8 cannot put inside `Nullable` (#1490). + pub fn is_complex(&self) -> bool { + let raw = self.raw.to_ascii_lowercase(); + ["array(", "map(", "tuple(", "dynamic", "variant("] + .iter() + .any(|p| raw.starts_with(p)) + } + /// Whether this is an integer of more than 64 bits (`Int128`, `UInt256`). pub fn is_wider_than_64_bits(&self) -> bool { let raw = self.raw.to_ascii_lowercase(); @@ -864,6 +873,31 @@ mod tests { assert_eq!(KeyPartType::parse("String").array_element(), None); } + /// #1490: the types ClickHouse 25.8 cannot put inside `Nullable`. + #[test] + fn a_complex_column_is_an_array_map_tuple_dynamic_or_variant() { + for ty in [ + "Array(String)", + "Map(String, UInt8)", + "Tuple(UInt8, String)", + "Dynamic", + "Dynamic(max_types=8)", + "Variant(Array(Int64), String)", + ] { + assert!(KeyPartType::parse(ty).is_complex(), "{ty}"); + } + for ty in [ + "String", + "Nullable(Int64)", + "LowCardinality(String)", + "DateTime64(3)", + "Bool", + "UUID", + ] { + assert!(!KeyPartType::parse(ty).is_complex(), "{ty}"); + } + } + /// A space before a parenthesis is ClickHouse's same type. #[test] fn a_spaced_spelling_parses_as_its_type() { diff --git a/src/sql_generator/function_mapper/clickhouse.rs b/src/sql_generator/function_mapper/clickhouse.rs index fd32ef042..290d4b5ba 100644 --- a/src/sql_generator/function_mapper/clickhouse.rs +++ b/src/sql_generator/function_mapper/clickhouse.rs @@ -530,6 +530,16 @@ mod tests { } } + /// #1490: a complex value (`Array` / `Map` / `Tuple` / `Dynamic`) cannot be + /// inside `Nullable` on ClickHouse 25.8, so its aggregate is `anyIf`; + /// every other is `anyIfOrNull`, which is NULL for a group of NULLs only. + #[test] + fn any_non_null_is_any_if_for_a_complex_value_1490() { + let m = ClickhouseFunctionMapper; + assert_eq!(m.any_non_null("v", true), "anyIf(v, NOT isNull(v))"); + assert_eq!(m.any_non_null("v", false), "anyIfOrNull(v, NOT isNull(v))"); + } + #[test] fn cast_bool_uses_nullable_bool_for_null_safety() { // #1057: Nullable(Bool), not bare Bool — CAST(NULL>2 AS Bool) throws diff --git a/src/sql_generator/function_mapper/databricks.rs b/src/sql_generator/function_mapper/databricks.rs index 392d98197..c3d11ca54 100644 --- a/src/sql_generator/function_mapper/databricks.rs +++ b/src/sql_generator/function_mapper/databricks.rs @@ -457,8 +457,7 @@ impl FunctionMapper for DatabricksFunctionMapper { format!("array_size({list})") } - fn any_non_null(&self, value: &str, is_complex: bool) -> String { - let _ = is_complex; + fn any_non_null(&self, value: &str, _is_complex: bool) -> String { format!("any_value({value}, true)") } diff --git a/src/sql_generator/function_mapper/mod.rs b/src/sql_generator/function_mapper/mod.rs index 1aa807039..2229c7191 100644 --- a/src/sql_generator/function_mapper/mod.rs +++ b/src/sql_generator/function_mapper/mod.rs @@ -52,12 +52,11 @@ pub(crate) trait FunctionMapper: Send + Sync { /// An aggregate of any of the values `{0}` that are not NULL (NULL when /// all are): CH `any` skips a `Nullable`'s NULLs but not a `Variant`'s; - /// Spark's `any_value` needs its `ignoreNulls` argument. - fn any_non_null(&self, value: &str, is_complex: bool) -> String { - // Complex types (Array/Map/Tuple/Dynamic) cannot be inside Nullable - // on ClickHouse 25.8, so use `anyIf` for them; scalars keep - // `anyIfOrNull` (NULL for an all-NULL group). (#1490) - let _ = is_complex; + /// Spark's `any_value` needs its `ignoreNulls` argument. `is_complex`: the + /// value is an `Array` / `Map` / `Tuple` / `Dynamic`, which ClickHouse 25.8 + /// cannot put inside `Nullable` (`anyIfOrNull` returns one, #1490); only + /// ClickHouse acts on it. + fn any_non_null(&self, value: &str, _is_complex: bool) -> String { format!("{}({value})", self.any()) }