Skip to content

Commit fd5bcd8

Browse files
committed
Handle spaced qualified quoted names in alias detection
Scan backwards past whitespace before a quote character to find a dot, so o . "year_total" is correctly treated as a qualified reference and does not trigger unnecessary query wrapping.
1 parent fff8cbc commit fd5bcd8

1 file changed

Lines changed: 9 additions & 1 deletion

File tree

yardstick-rs/src/sql/measures.rs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5734,7 +5734,12 @@ fn identifier_appears_in(text: &str, ident: &str) -> bool {
57345734
let before_ok = abs == 0 || {
57355735
let c = bytes[abs - 1];
57365736
if c == b'"' || c == b'`' {
5737-
abs < 2 || bytes[abs - 2] != b'.'
5737+
// Scan backwards past whitespace to check for a dot (e.g. o . "alias")
5738+
let mut k = abs.saturating_sub(2);
5739+
while k > 0 && bytes[k].is_ascii_whitespace() {
5740+
k -= 1;
5741+
}
5742+
abs < 2 || bytes[k] != b'.'
57385743
} else {
57395744
!c.is_ascii_alphanumeric() && c != b'_' && c != b'.'
57405745
}
@@ -8397,6 +8402,9 @@ GROUP BY s.year";
83978402
// Should not match qualified quoted names like o."year_total"
83988403
assert!(!identifier_appears_in(r#"o."year_total""#, "year_total"));
83998404
assert!(!identifier_appears_in(r#"o.`year_total`"#, "year_total"));
8405+
// Should not match spaced qualified quoted names like o . "year_total"
8406+
assert!(!identifier_appears_in(r#"o . "year_total""#, "year_total"));
8407+
assert!(!identifier_appears_in(r#"o . `year_total`"#, "year_total"));
84008408
// But bare quoted aliases like "year_total" should match
84018409
assert!(identifier_appears_in(r#""year_total""#, "year_total"));
84028410
assert!(identifier_appears_in(r#"`year_total`"#, "year_total"));

0 commit comments

Comments
 (0)