Skip to content

Commit 7bb4bdc

Browse files
Nikita-strKSDaemon
andauthored
fix(cubejs-schema-compiler): Stay unchanged __user / __cubejoinfield names in aliasing (#8303)
* dont change __user / __cubejoinfield names in aliasing * cast name to lower for `__cubeJoinField` case * reapply fix --------- Co-authored-by: Konstantin Burkalev <[email protected]>
1 parent 0d13673 commit 7bb4bdc

File tree

3 files changed

+7
-6
lines changed

3 files changed

+7
-6
lines changed

packages/cubejs-schema-compiler/src/adapter/BaseQuery.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3693,6 +3693,10 @@ export class BaseQuery {
36933693
}
36943694
// TODO: https://github.com/cube-js/cube.js/issues/4019
36953695
// use single underscore for pre-aggregations to avoid fail of pre-aggregation name replace
3696+
const lowercaseName = name.toLowerCase();
3697+
if (lowercaseName === '__user' || lowercaseName === '__cubejoinfield') {
3698+
return name;
3699+
}
36963700
return inflection.underscore(name).replace(/\./g, isPreAggregationName ? '_' : '__');
36973701
}
36983702

rust/cubesql/cubesql/src/compile/engine/df/wrapper.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -416,10 +416,7 @@ impl Remapper {
416416
LazyLock::new(|| Regex::new(r"[^a-zA-Z0-9_]").unwrap());
417417

418418
let alias = start_from;
419-
let mut truncated_alias = NON_ID_REGEX
420-
.replace_all(&alias, "_")
421-
.trim_start_matches("_")
422-
.to_lowercase();
419+
let mut truncated_alias = NON_ID_REGEX.replace_all(&alias, "_").to_lowercase();
423420
truncated_alias.truncate(16);
424421
let mut alias = truncated_alias.clone();
425422
for i in 1..10000 {

rust/cubesql/cubesql/src/compile/test/test_wrapper.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -925,9 +925,9 @@ async fn test_case_wrapper_with_system_fields() {
925925
.wrapped_sql
926926
.sql
927927
.contains(
928-
"\\\"cubeName\\\":\\\"KibanaSampleDataEcommerce\\\",\\\"alias\\\":\\\"user\\\""
928+
"\\\"cubeName\\\":\\\"KibanaSampleDataEcommerce\\\",\\\"alias\\\":\\\"__user\\\""
929929
),
930-
r#"SQL contains `\"cubeName\":\"KibanaSampleDataEcommerce\",\"alias\":\"user\"` {}"#,
930+
r#"SQL contains `\"cubeName\":\"KibanaSampleDataEcommerce\",\"alias\":\"__user\"` {}"#,
931931
logical_plan.find_cube_scan_wrapped_sql().wrapped_sql.sql
932932
);
933933

0 commit comments

Comments
 (0)