From 3819ba2cb03eb3a2300cf0e73d240e4befd20944 Mon Sep 17 00:00:00 2001 From: Konstantin Burkalev Date: Thu, 26 Jun 2025 14:08:15 +0300 Subject: [PATCH] fix(cubesql): Fix incorrect underscore truncation for aliases --- .../cubesql/cubesql/src/compile/engine/df/wrapper.rs | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/rust/cubesql/cubesql/src/compile/engine/df/wrapper.rs b/rust/cubesql/cubesql/src/compile/engine/df/wrapper.rs index da04e1a4cbc20..4473834c3ce7a 100644 --- a/rust/cubesql/cubesql/src/compile/engine/df/wrapper.rs +++ b/rust/cubesql/cubesql/src/compile/engine/df/wrapper.rs @@ -415,8 +415,16 @@ impl Remapper { static NON_ID_REGEX: LazyLock = LazyLock::new(|| Regex::new(r"[^a-zA-Z0-9_]").unwrap()); - let alias = start_from; - let mut truncated_alias = NON_ID_REGEX.replace_all(&alias, "_").to_lowercase(); + let alias_lower = start_from.clone().to_lowercase(); + let mut truncated_alias = if alias_lower != "__user" && alias_lower != "__cubejoinfield" { + NON_ID_REGEX + .replace_all(&alias_lower, "_") + .trim_start_matches("_") + .to_string() + } else { + alias_lower + }; + truncated_alias.truncate(16); let mut alias = truncated_alias.clone(); for i in 1..10000 {