Skip to content

Commit

Permalink
feat(cubesql): Add float8, bool casts
Browse files Browse the repository at this point in the history
  • Loading branch information
MazterQyou committed Sep 30, 2022
1 parent a86771d commit b345ade
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 1 deletion.
33 changes: 33 additions & 0 deletions rust/cubesql/cubesql/src/compile/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12097,4 +12097,37 @@ ORDER BY \"COUNT(count)\" DESC"
}
);
}

#[tokio::test]
async fn test_thoughtspot_casts() {
init_logger();

let logical_plan = convert_select_to_query_plan(
r#"
SELECT CAST("ta_4"."ca_3" AS FLOAT8), CAST("ta_4"."ca_3" AS INT2), CAST("ta_4"."ca_3" AS BOOL)
FROM (
SELECT sum("ta_1"."count") AS "ca_3"
FROM "db"."public"."KibanaSampleDataEcommerce" "ta_1"
) AS "ta_4"
"#
.to_string(),
DatabaseProtocol::PostgreSQL,
)
.await
.as_logical_plan();

assert_eq!(
logical_plan.find_cube_scan().request,
V1LoadRequestQuery {
measures: Some(vec!["KibanaSampleDataEcommerce.count".to_string(),]),
dimensions: Some(vec![]),
segments: Some(vec![]),
time_dimensions: None,
order: None,
limit: None,
offset: None,
filters: None,
}
)
}
}
12 changes: 11 additions & 1 deletion rust/cubesql/cubesql/src/sql/statement.rs
Original file line number Diff line number Diff line change
Expand Up @@ -765,7 +765,7 @@ impl<'ast> Visitor<'ast, ConnectionError> for CastReplacer {
} = expr
{
match data_type {
ast::DataType::Custom(name) => match name.to_string().as_str() {
ast::DataType::Custom(name) => match name.to_string().to_lowercase().as_str() {
"name" | "oid" | "information_schema.cardinal_number" | "regproc" => {
self.visit_expr(&mut *cast_expr)?;

Expand All @@ -786,6 +786,16 @@ impl<'ast> Visitor<'ast, ConnectionError> for CastReplacer {

*data_type = ast::DataType::BigInt(None)
}
"float8" => {
self.visit_expr(&mut *cast_expr)?;

*data_type = ast::DataType::Double;
}
"bool" => {
self.visit_expr(&mut *cast_expr)?;

*data_type = ast::DataType::Boolean;
}
"timestamptz" => {
self.visit_expr(&mut *cast_expr)?;

Expand Down

0 comments on commit b345ade

Please sign in to comment.