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 {
249
249
250
250
/// Determines if the provided expression is meta column reference.
251
251
/// 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.
253
254
fn is_meta_column ( expr : & Expr ) -> bool {
254
255
match expr {
255
256
Expr :: Column ( Column { name, .. } ) => name. eq_ignore_ascii_case ( "__user" ) ,
@@ -259,6 +260,7 @@ fn is_meta_column(expr: &Expr) -> bool {
259
260
}
260
261
false
261
262
}
263
+ Expr :: Cast { expr, .. } => is_meta_column ( expr) ,
262
264
_ => false ,
263
265
}
264
266
}
Original file line number Diff line number Diff line change @@ -280,6 +280,45 @@ GROUP BY 1
280
280
assert_eq ! ( load_calls[ 0 ] . meta. change_user( ) , Some ( "gopher" . to_string( ) ) ) ;
281
281
}
282
282
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
+
283
322
/// Repeated aggregation should be flattened even in presence of __user filter
284
323
#[ tokio:: test]
285
324
async fn flatten_aggregation_into_user_change ( ) {
You can’t perform that action at this time.
0 commit comments