Skip to content

Commit 17ba3e2

Browse files
committed
fix(cubesql): Support CAST in HAVING clause
1 parent 53ca05f commit 17ba3e2

File tree

2 files changed

+46
-0
lines changed

2 files changed

+46
-0
lines changed

rust/cubesql/cubesql/src/compile/mod.rs

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14727,4 +14727,46 @@ ORDER BY \"COUNT(count)\" DESC"
1472714727
}
1472814728
)
1472914729
}
14730+
14731+
#[tokio::test]
14732+
async fn test_thoughtspot_having_cast_float8() {
14733+
init_logger();
14734+
14735+
let logical_plan = convert_select_to_query_plan(
14736+
r#"
14737+
WITH "qt_0" AS (
14738+
SELECT "ta_1"."customer_gender" "ca_1"
14739+
FROM "KibanaSampleDataEcommerce" "ta_1"
14740+
GROUP BY "ca_1"
14741+
HAVING CAST(COUNT("ta_1"."count") AS FLOAT8) < 10.0
14742+
)
14743+
SELECT count(DISTINCT "ta_2"."ca_1") "ca_2"
14744+
FROM "qt_0" "ta_2"
14745+
"#
14746+
.to_string(),
14747+
DatabaseProtocol::PostgreSQL,
14748+
)
14749+
.await
14750+
.as_logical_plan();
14751+
14752+
assert_eq!(
14753+
logical_plan.find_cube_scan().request,
14754+
V1LoadRequestQuery {
14755+
measures: Some(vec![]),
14756+
dimensions: Some(vec!["KibanaSampleDataEcommerce.customer_gender".to_string()]),
14757+
segments: Some(vec![]),
14758+
time_dimensions: None,
14759+
order: None,
14760+
limit: None,
14761+
offset: None,
14762+
filters: Some(vec![V1LoadRequestQueryFilterItem {
14763+
member: Some("KibanaSampleDataEcommerce.count".to_string()),
14764+
operator: Some("lt".to_string()),
14765+
values: Some(vec!["10".to_string()]),
14766+
or: None,
14767+
and: None
14768+
}])
14769+
}
14770+
)
14771+
}
1473014772
}

rust/cubesql/cubesql/src/sql/statement.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -315,6 +315,10 @@ trait Visitor<'ast, E: Error> {
315315
self.visit_table_with_joins(from)?;
316316
}
317317

318+
if let Some(having) = &mut select.having {
319+
self.visit_expr(having)?;
320+
}
321+
318322
Ok(())
319323
}
320324

0 commit comments

Comments
 (0)