From 66d47c87059fa93756512bfffe7198a5d6b3fcef Mon Sep 17 00:00:00 2001 From: Madhavendra Rathore Date: Mon, 25 May 2026 21:52:35 +0000 Subject: [PATCH 1/3] =?UTF-8?q?feat(napi):=20accept=20ExecuteOptions=20on?= =?UTF-8?q?=20executeStatement=20=E2=80=94=20statementConf=20+=20queryTags?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Surfaces two of the kernel `StatementSpec` knobs through napi so JS callers can pass per-statement Spark conf and query tags: - `statementConf: Record` — per-statement conf overlay; merged on top of the session-level `sessionConf` at execute time. The kernel's `StatementSpec::statement_conf()` setter accepts this verbatim and forwards to SEA `parameters` / Thrift `confOverlay`. - `queryTags: Record` — convenience wrapper that JSON-encodes the tag map into the `query_tags` conf overlay key, matching NodeJS Thrift's `serializeQueryTags` shape (`{"k":"v","k2":"v2"}`). Passing both `queryTags` and an explicit `statementConf["query_tags"]` raises `InvalidArgument` to surface the ambiguity to the caller. Deferred (require kernel-side `StatementSpec` extensions or napi TypedValue mapping — separate PRs): - Positional / named parameters (TypedValue mapping) - Row limit, wait timeout (need `StatementSpec.row_limit` / `wait_timeout` fields — currently only on internal `ExecuteParams`) - Async execute (kernel has `submit()`; needs new napi wrapper class) The new `ExecuteOptions` napi-object is `Option<…>` so existing callers (`executeStatement(sql)`) keep working — napi-rs emits `options?: ExecuteOptions | undefined | null` on the JS-side d.ts. Empty maps (`{statementConf: {}}`) are treated the same as omission so the wire shape stays stable for the common case. Co-authored-by: Isaac Signed-off-by: Madhavendra Rathore --- napi/src/connection.rs | 244 ++++++++++++++++++++++++++++++++++++++++- 1 file changed, 241 insertions(+), 3 deletions(-) diff --git a/napi/src/connection.rs b/napi/src/connection.rs index 20d3d11a..ebf49ac0 100644 --- a/napi/src/connection.rs +++ b/napi/src/connection.rs @@ -27,6 +27,7 @@ //! fire-and-forget close on the captured runtime handle if explicit //! close was never called. +use std::collections::HashMap; use std::sync::Arc; use tokio::sync::Mutex; @@ -37,6 +38,40 @@ use crate::runtime; use crate::statement::Statement; use crate::util::guarded; +/// Per-statement options for `Connection.executeStatement`. +/// +/// Mirrors the kernel `StatementSpec` knobs that are safe to thread +/// through napi without a kernel-side change. Today this covers: +/// - `statementConf` — per-statement Spark conf overlay +/// (`StatementSpec.statement_conf` → SEA `parameters` / +/// Thrift `confOverlay`) +/// - `queryTags` — convenience wrapper over `statementConf` with +/// key `query_tags`; serialised to JSON before being placed in the +/// conf overlay. Mirrors NodeJS Thrift's `serializeQueryTags` +/// convention (`lib/DBSQLSession.ts::serializeQueryTags`). +/// +/// Positional parameters, named parameters, row limit, and wait +/// timeout are deferred: they require either a non-trivial JS↔napi +/// `TypedValue` mapping (params) or a kernel-side `StatementSpec` +/// extension (`row_limit`/`wait_timeout`). Both land in follow-on PRs. +#[allow( + dead_code, + reason = "exported via napi macro codegen; not called from Rust" +)] +#[napi(object)] +pub struct ExecuteOptions { + /// Per-statement Spark conf overlay. Merged on top of the + /// session-level `sessionConf` at execute time; this map wins + /// on key collisions. Unknown keys are rejected by the server. + pub statement_conf: Option>, + /// Query tags as key→value pairs. JSON-encoded into the + /// `query_tags` conf overlay key, matching NodeJS Thrift's + /// `serializeQueryTags` shape. Passing both `queryTags` and a + /// `query_tags` key in `statementConf` raises `InvalidArgument` + /// — the explicit field wins to avoid silent overwrite. + pub query_tags: Option>, +} + /// Closed-state error builder. Mirrors `statement::statement_closed_err` /// — route through the kernel envelope so the TS reviver mints a typed /// `KernelError(code='InvalidStatementHandle')`. Single source of truth @@ -47,6 +82,73 @@ fn connection_closed_err() -> napi::Error { ) } +/// Merge `statement_conf` and `query_tags` from JS-supplied +/// `ExecuteOptions` into the single `HashMap` the +/// kernel's `StatementSpec::statement_conf` accepts. +/// +/// Returns `Ok(None)` when no per-statement conf is set (caller skips +/// the `.statement_conf(...)` builder call so the kernel sees the +/// session-level conf untouched). Returns `Ok(Some(conf))` when at +/// least one knob was set. Returns `Err(InvalidArgument)` when both +/// `queryTags` and `statementConf["query_tags"]` are present — the +/// caller's intent is ambiguous. +fn build_merged_statement_conf( + options: Option, +) -> napi::Result>> { + let Some(options) = options else { + return Ok(None); + }; + + let mut conf = options.statement_conf.unwrap_or_default(); + if let Some(tags) = options.query_tags { + if !tags.is_empty() && conf.contains_key("query_tags") { + return Err(napi_err_from_kernel( + KernelError::invalid_argument().message( + "ExecuteOptions: cannot supply both `queryTags` and \ + `statementConf[\"query_tags\"]` — pick one", + ), + )); + } + if !tags.is_empty() { + conf.insert("query_tags".to_string(), serialize_query_tags(&tags)); + } + } + + if conf.is_empty() { + Ok(None) + } else { + Ok(Some(conf)) + } +} + +/// Serialise a tag map to the same wire shape NodeJS Thrift's +/// `serializeQueryTags` produces: comma-separated `key:value` pairs. +/// Backslashes in keys are doubled; backslash, colon, and comma in +/// values are backslash-escaped. Null/empty values would produce a +/// bare key with no colon — but the napi `HashMap` +/// shape can't carry nulls today, so every tag here is `key:value`. +/// +/// Match the Thrift wire shape exactly: the SEA server merges +/// `confOverlay.query_tags` the same way regardless of which backend +/// produced it, and JS callers porting from Thrift expect identical +/// behaviour. +fn serialize_query_tags(tags: &HashMap) -> String { + tags.iter() + .map(|(k, v)| { + let esc_key = k.replace('\\', "\\\\"); + let esc_val = v + .chars() + .flat_map(|c| match c { + '\\' | ':' | ',' => vec!['\\', c], + other => vec![other], + }) + .collect::(); + format!("{esc_key}:{esc_val}") + }) + .collect::>() + .join(",") +} + /// Opaque connection handle wrapping a kernel `Session`. /// /// `inner` is `Arc>>` so: @@ -88,17 +190,36 @@ impl Connection { /// Execute a SQL statement and return a Statement handle that /// streams batches via `fetchNextBatch()`. /// - /// No per-statement options: catalog / schema / sessionConf are - /// session-level (`openSession`). + /// Catalog / schema / sessionConf are session-level + /// (`openSession`). Per-statement options on `ExecuteOptions`: + /// - `statementConf` — per-statement Spark conf overlay + /// - `queryTags` — JSON-encoded into `statement_conf["query_tags"]` + /// matching NodeJS Thrift's `serializeQueryTags` shape + /// + /// `options` is omitted/`None` for the no-options path; passing + /// `{ statementConf: {} }` (an empty map) is treated the same as + /// omission to keep the wire shape stable for the common case. #[napi] - pub async fn execute_statement(&self, sql: String) -> napi::Result { + pub async fn execute_statement( + &self, + sql: String, + options: Option, + ) -> napi::Result { let inner = Arc::clone(&self.inner); + // Merge `query_tags` into `statement_conf` at the napi boundary + // so the kernel sees a single conf map. JSON-encode the tag + // map to match the wire shape NodeJS Thrift produces in + // `serializeQueryTags` (`{"key":"value", ...}`). + let merged_conf = build_merged_statement_conf(options)?; guarded(async move { let guard = inner.lock().await; let session = guard.as_ref().ok_or_else(connection_closed_err)?; let mut stmt = session.statement(); stmt.spec().sql(sql); + if let Some(conf) = merged_conf { + stmt.spec().statement_conf(conf); + } let executed = stmt.execute().await.map_err(napi_err_from_kernel)?; // Pass the parent kernel `Statement` into the JS wrapper. @@ -218,4 +339,121 @@ mod tests { }; assert_eq!(conn.session_id(), "session-survives-close"); } + + // ─── ExecuteOptions / build_merged_statement_conf ─────────────────── + + #[test] + fn merged_conf_none_when_options_is_none() { + let result = build_merged_statement_conf(None).unwrap(); + assert!(result.is_none(), "no options → no statement_conf"); + } + + #[test] + fn merged_conf_none_when_both_maps_empty() { + let result = build_merged_statement_conf(Some(ExecuteOptions { + statement_conf: Some(HashMap::new()), + query_tags: Some(HashMap::new()), + })) + .unwrap(); + assert!(result.is_none(), "empty maps → no statement_conf"); + } + + #[test] + fn merged_conf_passes_through_statement_conf() { + let mut conf = HashMap::new(); + conf.insert("ANSI_MODE".to_string(), "true".to_string()); + let result = build_merged_statement_conf(Some(ExecuteOptions { + statement_conf: Some(conf), + query_tags: None, + })) + .unwrap() + .unwrap(); + assert_eq!(result.get("ANSI_MODE").map(String::as_str), Some("true")); + } + + #[test] + fn merged_conf_query_tags_serialised_into_query_tags_key() { + let mut tags = HashMap::new(); + tags.insert("team".to_string(), "platform".to_string()); + let result = build_merged_statement_conf(Some(ExecuteOptions { + statement_conf: None, + query_tags: Some(tags), + })) + .unwrap() + .unwrap(); + // Single-tag case is deterministic regardless of HashMap order. + assert_eq!( + result.get("query_tags").map(String::as_str), + Some("team:platform"), + ); + } + + #[test] + fn merged_conf_query_tags_escape_special_chars_in_values() { + let mut tags = HashMap::new(); + tags.insert("k".to_string(), "v:1,v\\2".to_string()); + let result = build_merged_statement_conf(Some(ExecuteOptions { + statement_conf: None, + query_tags: Some(tags), + })) + .unwrap() + .unwrap(); + let encoded = result.get("query_tags").unwrap(); + // `:` → `\:`, `,` → `\,`, `\` → `\\`. Order in the input is + // `v:1,v\2` so the encoded form is `v\:1\,v\\2`. + assert_eq!(encoded, "k:v\\:1\\,v\\\\2"); + } + + #[test] + fn merged_conf_query_tags_escape_backslash_in_keys() { + let mut tags = HashMap::new(); + tags.insert("k\\1".to_string(), "v".to_string()); + let result = build_merged_statement_conf(Some(ExecuteOptions { + statement_conf: None, + query_tags: Some(tags), + })) + .unwrap() + .unwrap(); + assert_eq!(result.get("query_tags").map(String::as_str), Some("k\\\\1:v")); + } + + #[test] + fn merged_conf_rejects_dual_query_tags_definition() { + let mut conf = HashMap::new(); + conf.insert("query_tags".to_string(), "explicit:value".to_string()); + let mut tags = HashMap::new(); + tags.insert("team".to_string(), "platform".to_string()); + let err = build_merged_statement_conf(Some(ExecuteOptions { + statement_conf: Some(conf), + query_tags: Some(tags), + })) + .err() + .expect("must reject when both are set"); + assert!( + err.reason.contains("cannot supply both"), + "error must explain the conflict: {}", + err.reason, + ); + } + + #[test] + fn merged_conf_empty_query_tags_does_not_collide_with_existing_key() { + // An empty `queryTags: {}` map should be ignored, so the + // caller can still pass an explicit + // `statementConf["query_tags"]` alongside `queryTags: {}` + // without tripping the ambiguity guard. Convention: empty + // input maps mean "not supplied". + let mut conf = HashMap::new(); + conf.insert("query_tags".to_string(), "explicit:value".to_string()); + let result = build_merged_statement_conf(Some(ExecuteOptions { + statement_conf: Some(conf), + query_tags: Some(HashMap::new()), + })) + .unwrap() + .unwrap(); + assert_eq!( + result.get("query_tags").map(String::as_str), + Some("explicit:value"), + ); + } } From a50b50c21bc3a882b03e809675794c681189d6e1 Mon Sep 17 00:00:00 2001 From: Madhavendra Rathore Date: Mon, 25 May 2026 22:20:42 +0000 Subject: [PATCH 2/3] =?UTF-8?q?fix(napi):=20F3=20fixup=20=E2=80=94=20clipp?= =?UTF-8?q?y=20err=5Fexpect=20+=20rustfmt=20on=20connection.rs?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit DA round 1 findings on F3: H1 (clippy `err_expect`): the `merged_conf_rejects_dual_query_tags_definition` test used `.err().expect(...)` which clippy 1.95+ flags. Switch to `.expect_err(...)` per the suggested help text. Behaviour unchanged; this was a stylistic clippy lint, not a logic defect. H2 (rustfmt): the `merged_conf_query_tags_escape_backslash_in_keys` test expressed a long `assert_eq!` on one line that exceeded rustfmt's max width. Break across three lines per the cargo fmt diff. Behaviour unchanged. Why I missed these initially: my prior gate verification ran inside a different worktree on the same branch (the F3b worktree, which had an in-progress amend), so my local `cargo clippy` + `cargo fmt --check` both reported green there. The origin branch (this PR's HEAD `79bba34`) didn't carry that amend. Lesson: never trust gate verification across worktrees without confirming the working tree matches the pushed SHA. Verified post-fix: - `cargo clippy --all-targets -- -D warnings` ✓ - `cargo +stable fmt --check` ✓ - `cargo test --lib` ✓ (32/32, same as before the fix) Co-authored-by: Isaac Signed-off-by: Madhavendra Rathore --- napi/src/connection.rs | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/napi/src/connection.rs b/napi/src/connection.rs index ebf49ac0..dff0f473 100644 --- a/napi/src/connection.rs +++ b/napi/src/connection.rs @@ -414,7 +414,10 @@ mod tests { })) .unwrap() .unwrap(); - assert_eq!(result.get("query_tags").map(String::as_str), Some("k\\\\1:v")); + assert_eq!( + result.get("query_tags").map(String::as_str), + Some("k\\\\1:v") + ); } #[test] @@ -427,8 +430,7 @@ mod tests { statement_conf: Some(conf), query_tags: Some(tags), })) - .err() - .expect("must reject when both are set"); + .expect_err("must reject when both are set"); assert!( err.reason.contains("cannot supply both"), "error must explain the conflict: {}", From be45ab2d8cf7a08718974e00baceb79f3f7d3794 Mon Sep 17 00:00:00 2001 From: Madhavendra Rathore Date: Mon, 25 May 2026 22:47:05 +0000 Subject: [PATCH 3/3] =?UTF-8?q?fix(napi):=20F3=20round-2=20=E2=80=94=20doc?= =?UTF-8?q?string=20+=20parity=20test=20fixups=20(DA=20M1/M4)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit DA round 2 findings on F3 (statement options + query tags): M1 docs: prior docstring claimed `queryTags` is "JSON-encoded into the conf overlay" — wrong. The actual implementation serialises to comma-separated `key:value` matching NodeJS Thrift's `serializeQueryTags` wire shape (`lib/utils/queryTags.ts`). Updated three sites that carried the stale "JSON" reference: - `ExecuteOptions` struct doc - `query_tags` field doc - `Connection::execute_statement` method doc + inline comment M2 dead code: the napi `queryTags` field is intentionally exported even though the JS adapter today pre-serialises via the Thrift helper and writes into `statementConf["query_tags"]` directly. The field stays as an alternate API surface for non- NodeJS consumers (future pyo3 reuse, direct napi consumers); the NodeJS adapter path is documented as the byte-identical-Thrift- parity route. Updated the struct doc to spell out the dual paths and their parity contracts. M4 parity: added a struct-level "Tag-order caveat" doc block that documents the HashMap-iteration-order vs `Object.keys`- insertion-order divergence between the napi `queryTags` path and Thrift's `serializeQueryTags`. The SEA server is order- insensitive on conf values so the two are functionally equivalent; callers needing byte-identical Thrift parity use the JS adapter path. Added 5 new Rust unit tests pinning the per-tag byte shape against the Thrift algorithm: - single-tag deterministic case - value-side escape ordering (`\` `:` `,`) - key-side backslash-only escape (NOT colons/commas — Thrift asymmetry pinned so a future "uniformity" refactor fails the test) - empty-map edge case - multi-tag order-insensitive set equality M3 lint: already clean — `cargo clippy --all-targets -- -D warnings` passes locally on this branch's tip. Test count: 32 → 37 (5 new). All passing. Co-authored-by: Isaac Signed-off-by: Madhavendra Rathore --- napi/src/connection.rs | 124 ++++++++++++++++++++++++++++++++++++----- 1 file changed, 111 insertions(+), 13 deletions(-) diff --git a/napi/src/connection.rs b/napi/src/connection.rs index dff0f473..4a20f490 100644 --- a/napi/src/connection.rs +++ b/napi/src/connection.rs @@ -46,14 +46,28 @@ use crate::util::guarded; /// (`StatementSpec.statement_conf` → SEA `parameters` / /// Thrift `confOverlay`) /// - `queryTags` — convenience wrapper over `statementConf` with -/// key `query_tags`; serialised to JSON before being placed in the -/// conf overlay. Mirrors NodeJS Thrift's `serializeQueryTags` -/// convention (`lib/DBSQLSession.ts::serializeQueryTags`). +/// key `query_tags`; serialised to the same comma-separated +/// `key:value` wire shape NodeJS Thrift's `serializeQueryTags` +/// produces (`lib/utils/queryTags.ts`). Backslashes in keys are +/// doubled; backslash/colon/comma in values are backslash-escaped. /// /// Positional parameters, named parameters, row limit, and wait /// timeout are deferred: they require either a non-trivial JS↔napi /// `TypedValue` mapping (params) or a kernel-side `StatementSpec` /// extension (`row_limit`/`wait_timeout`). Both land in follow-on PRs. +/// +/// **Tag-order caveat (M4 parity note).** The napi `queryTags` field +/// is a Rust `HashMap` whose iteration order is +/// non-deterministic, so the serialised `query_tags` value may have +/// a different key order than Thrift's `serializeQueryTags` (which +/// iterates `Object.keys(...)` in insertion order) for the same +/// input. The SEA server is order-insensitive on conf values, so +/// the two are functionally equivalent. If a caller needs +/// byte-identical Thrift parity, the JS adapter pre-serialises via +/// `serializeQueryTags` and writes the result into +/// `statementConf["query_tags"]` directly — see +/// `SeaSessionBackend.executeStatement` in the NodeJS driver. This +/// path is the one the production code uses. #[allow( dead_code, reason = "exported via napi macro codegen; not called from Rust" @@ -64,11 +78,17 @@ pub struct ExecuteOptions { /// session-level `sessionConf` at execute time; this map wins /// on key collisions. Unknown keys are rejected by the server. pub statement_conf: Option>, - /// Query tags as key→value pairs. JSON-encoded into the - /// `query_tags` conf overlay key, matching NodeJS Thrift's - /// `serializeQueryTags` shape. Passing both `queryTags` and a - /// `query_tags` key in `statementConf` raises `InvalidArgument` - /// — the explicit field wins to avoid silent overwrite. + /// Query tags as key→value pairs. Serialised to a comma- + /// separated `key:value` string (backslash-escaping `\`, `:`, + /// `,`) and placed into `statementConf["query_tags"]`, matching + /// NodeJS Thrift's `serializeQueryTags` wire shape. Passing + /// both `queryTags` AND a `query_tags` key in `statementConf` + /// raises `InvalidArgument` — the caller's intent is ambiguous + /// so we refuse to silently pick one over the other. + /// + /// See the struct-level "Tag-order caveat" for the + /// HashMap-iteration-order vs `Object.keys`-iteration-order + /// divergence and the byte-identical-Thrift-parity workaround. pub query_tags: Option>, } @@ -193,8 +213,9 @@ impl Connection { /// Catalog / schema / sessionConf are session-level /// (`openSession`). Per-statement options on `ExecuteOptions`: /// - `statementConf` — per-statement Spark conf overlay - /// - `queryTags` — JSON-encoded into `statement_conf["query_tags"]` - /// matching NodeJS Thrift's `serializeQueryTags` shape + /// - `queryTags` — serialised to a comma-separated `key:value` + /// string and placed in `statement_conf["query_tags"]`, + /// matching NodeJS Thrift's `serializeQueryTags` wire shape /// /// `options` is omitted/`None` for the no-options path; passing /// `{ statementConf: {} }` (an empty map) is treated the same as @@ -207,9 +228,10 @@ impl Connection { ) -> napi::Result { let inner = Arc::clone(&self.inner); // Merge `query_tags` into `statement_conf` at the napi boundary - // so the kernel sees a single conf map. JSON-encode the tag - // map to match the wire shape NodeJS Thrift produces in - // `serializeQueryTags` (`{"key":"value", ...}`). + // so the kernel sees a single conf map. Serialise the tag + // map to the comma-separated `key:value` wire shape NodeJS + // Thrift produces in `serializeQueryTags` + // (`lib/utils/queryTags.ts`). let merged_conf = build_merged_statement_conf(options)?; guarded(async move { let guard = inner.lock().await; @@ -458,4 +480,80 @@ mod tests { Some("explicit:value"), ); } + + // ─── DA round-2 M4 parity — byte-shape vs Thrift's serializeQueryTags ─ + + /// `serializeQueryTags` (NodeJS Thrift, `lib/utils/queryTags.ts`) + /// is the canonical wire shape for `query_tags`. Pin the + /// per-tag byte shape produced by the kernel-side serializer + /// against the algorithm Thrift uses, so a regression on either + /// side fails this test. + /// + /// Algorithm (per Thrift): + /// - Keys: backslash doubled (`\` → `\\`); no other escaping + /// - Values: backslash, colon, and comma each backslash-escaped + /// - Tags: joined with `,` + /// - Single-tag case is order-deterministic; multi-tag case + /// asserts each pair appears regardless of HashMap iteration + /// order (the documented order caveat). + #[test] + fn serialize_query_tags_matches_thrift_byte_shape_single_tag() { + let mut tags = HashMap::new(); + tags.insert("team".to_string(), "platform".to_string()); + assert_eq!(serialize_query_tags(&tags), "team:platform"); + } + + #[test] + fn serialize_query_tags_matches_thrift_byte_shape_escapes() { + // Per Thrift's `escapedValue.replace(/[\\:,]/g, c => '\\' + c)`: + // input `v:1,v\2` + // output `v\:1\,v\\2` + let mut tags = HashMap::new(); + tags.insert("k".to_string(), "v:1,v\\2".to_string()); + assert_eq!(serialize_query_tags(&tags), "k:v\\:1\\,v\\\\2"); + } + + #[test] + fn serialize_query_tags_matches_thrift_byte_shape_key_backslash_only() { + // Per Thrift's `escapedKey = key.replace(/\\/g, '\\\\')`: + // input `k\1` + // output `k\\1` + // Colons/commas in keys are NOT escaped on Thrift's path — + // they're only escaped in values. Test pins this asymmetry + // so a future "uniformity" refactor that escapes them in + // keys too gets caught. + let mut tags = HashMap::new(); + tags.insert("k\\1".to_string(), "v".to_string()); + assert_eq!(serialize_query_tags(&tags), "k\\\\1:v"); + } + + #[test] + fn serialize_query_tags_empty_map_yields_empty_string() { + // Thrift returns `undefined` for empty input, but Thrift's + // caller only invokes the serializer when input is non-empty + // (see `lib/DBSQLSession.ts:231` `if (serializedQueryTags + // !== undefined)`). Our serializer is called only by + // `build_merged_statement_conf` which already filters empty + // input out, so this test pins the never-called case for + // defense. + assert_eq!(serialize_query_tags(&HashMap::new()), ""); + } + + #[test] + fn serialize_query_tags_multi_tag_contains_each_pair_regardless_of_order() { + // Multi-tag case: HashMap iteration is non-deterministic, so + // we can't assert a single byte string. Assert each pair is + // present and the join uses `,`. SEA server treats conf + // values as order-insensitive, so this is functionally + // equivalent to the Thrift output regardless of order. + let mut tags = HashMap::new(); + tags.insert("a".to_string(), "1".to_string()); + tags.insert("b".to_string(), "2".to_string()); + let s = serialize_query_tags(&tags); + let pairs: std::collections::HashSet<&str> = s.split(',').collect(); + assert!( + pairs == ["a:1", "b:2"].iter().copied().collect(), + "got: {s}", + ); + } }