File tree Expand file tree Collapse file tree 2 files changed +42
-1
lines changed
rust/cubesql/cubesql/src/compile Expand file tree Collapse file tree 2 files changed +42
-1
lines changed Original file line number Diff line number Diff line change @@ -249,7 +249,8 @@ fn is_meta_predicate(predicate: &Expr) -> bool {
249249
250250/// Determines if the provided expression is meta column reference.
251251/// Currently, only `__user` is considered a meta column.
252- /// Additionally, `Lower` function over a meta column is also considered a meta column.
252+ /// Additionally, `Lower` function over a meta column or casting meta column
253+ /// is also considered a meta column.
253254fn is_meta_column ( expr : & Expr ) -> bool {
254255 match expr {
255256 Expr :: Column ( Column { name, .. } ) => name. eq_ignore_ascii_case ( "__user" ) ,
@@ -259,6 +260,7 @@ fn is_meta_column(expr: &Expr) -> bool {
259260 }
260261 false
261262 }
263+ Expr :: Cast { expr, .. } => is_meta_column ( expr) ,
262264 _ => false ,
263265 }
264266}
Original file line number Diff line number Diff line change @@ -280,6 +280,45 @@ GROUP BY 1
280280 assert_eq ! ( load_calls[ 0 ] . meta. change_user( ) , Some ( "gopher" . to_string( ) ) ) ;
281281}
282282
283+ /// This should test that query with CubeScanWrapper uses proper change_user for both SQL generation and execution calls
284+ #[ tokio:: test]
285+ async fn test_user_change_sql_generation_cast ( ) {
286+ if !Rewriter :: sql_push_down_enabled ( ) {
287+ return ;
288+ }
289+ init_testing_logger ( ) ;
290+
291+ let context = TestContext :: new ( DatabaseProtocol :: PostgreSQL ) . await ;
292+
293+ context
294+ . execute_query (
295+ // language=PostgreSQL
296+ r#"
297+ SELECT
298+ COALESCE(customer_gender, 'N/A'),
299+ AVG(avgPrice)
300+ FROM
301+ KibanaSampleDataEcommerce
302+ WHERE
303+ CAST(__user AS TEXT) = 'gopher'
304+ AND LOWER(customer_gender) = 'test'
305+ GROUP BY 1
306+ ;
307+ "#
308+ . to_string ( ) ,
309+ )
310+ . await
311+ . expect_err ( "Test transport does not support load with SQL" ) ;
312+
313+ let load_calls = context. load_calls ( ) . await ;
314+ assert_eq ! ( load_calls. len( ) , 1 ) ;
315+ let sql_query = load_calls[ 0 ] . sql_query . as_ref ( ) . unwrap ( ) ;
316+ // This should be placed from load meta to query by TestConnectionTransport::sql
317+ // It would mean that SQL generation used changed user
318+ assert ! ( sql_query. sql. contains( r#""changeUser": "gopher""# ) ) ;
319+ assert_eq ! ( load_calls[ 0 ] . meta. change_user( ) , Some ( "gopher" . to_string( ) ) ) ;
320+ }
321+
283322/// Repeated aggregation should be flattened even in presence of __user filter
284323#[ tokio:: test]
285324async fn flatten_aggregation_into_user_change ( ) {
You can’t perform that action at this time.
0 commit comments