diff --git a/packages/cubejs-schema-compiler/src/adapter/BaseQuery.js b/packages/cubejs-schema-compiler/src/adapter/BaseQuery.js index 5dd34176028ce..41b54704c90e5 100644 --- a/packages/cubejs-schema-compiler/src/adapter/BaseQuery.js +++ b/packages/cubejs-schema-compiler/src/adapter/BaseQuery.js @@ -3693,6 +3693,10 @@ export class BaseQuery { } // TODO: https://github.com/cube-js/cube.js/issues/4019 // use single underscore for pre-aggregations to avoid fail of pre-aggregation name replace + const lowercaseName = name.toLowerCase(); + if (lowercaseName === '__user' || lowercaseName === '__cubejoinfield') { + return name; + } return inflection.underscore(name).replace(/\./g, isPreAggregationName ? '_' : '__'); } diff --git a/rust/cubesql/cubesql/src/compile/engine/df/wrapper.rs b/rust/cubesql/cubesql/src/compile/engine/df/wrapper.rs index 67d94e6547b52..da04e1a4cbc20 100644 --- a/rust/cubesql/cubesql/src/compile/engine/df/wrapper.rs +++ b/rust/cubesql/cubesql/src/compile/engine/df/wrapper.rs @@ -416,10 +416,7 @@ impl Remapper { LazyLock::new(|| Regex::new(r"[^a-zA-Z0-9_]").unwrap()); let alias = start_from; - let mut truncated_alias = NON_ID_REGEX - .replace_all(&alias, "_") - .trim_start_matches("_") - .to_lowercase(); + let mut truncated_alias = NON_ID_REGEX.replace_all(&alias, "_").to_lowercase(); truncated_alias.truncate(16); let mut alias = truncated_alias.clone(); for i in 1..10000 { diff --git a/rust/cubesql/cubesql/src/compile/test/test_wrapper.rs b/rust/cubesql/cubesql/src/compile/test/test_wrapper.rs index 6419939a1f90a..5db62bc5d772f 100644 --- a/rust/cubesql/cubesql/src/compile/test/test_wrapper.rs +++ b/rust/cubesql/cubesql/src/compile/test/test_wrapper.rs @@ -925,9 +925,9 @@ async fn test_case_wrapper_with_system_fields() { .wrapped_sql .sql .contains( - "\\\"cubeName\\\":\\\"KibanaSampleDataEcommerce\\\",\\\"alias\\\":\\\"user\\\"" + "\\\"cubeName\\\":\\\"KibanaSampleDataEcommerce\\\",\\\"alias\\\":\\\"__user\\\"" ), - r#"SQL contains `\"cubeName\":\"KibanaSampleDataEcommerce\",\"alias\":\"user\"` {}"#, + r#"SQL contains `\"cubeName\":\"KibanaSampleDataEcommerce\",\"alias\":\"__user\"` {}"#, logical_plan.find_cube_scan_wrapped_sql().wrapped_sql.sql );