1
- use cubeclient:: models:: V1LoadRequestQuery ;
2
- use datafusion:: physical_plan:: displayable;
1
+ use cubeclient:: models:: { V1LoadRequestQuery , V1LoadRequestQueryTimeDimension } ;
2
+ use datafusion:: { physical_plan:: displayable, scalar :: ScalarValue } ;
3
3
use pretty_assertions:: assert_eq;
4
4
use regex:: Regex ;
5
5
use serde_json:: json;
6
6
use std:: sync:: Arc ;
7
7
8
8
use crate :: {
9
9
compile:: {
10
+ engine:: df:: scan:: MemberField ,
10
11
rewrite:: rewriter:: Rewriter ,
11
12
test:: {
12
13
convert_select_to_query_plan, convert_select_to_query_plan_customized,
@@ -1167,6 +1168,12 @@ cube_scan_subq AS (
1167
1168
SELECT
1168
1169
logs_alias.content logs_content,
1169
1170
DATE_TRUNC('month', kibana_alias.last_mod) last_mod_month,
1171
+ kibana_alias.__user AS cube_user,
1172
+ 1 AS literal,
1173
+ -- Columns without aliases should also work
1174
+ DATE_TRUNC('month', kibana_alias.order_date),
1175
+ kibana_alias.__cubeJoinField,
1176
+ 2,
1170
1177
CASE
1171
1178
WHEN sum(kibana_alias."sumPrice") IS NOT NULL
1172
1179
THEN sum(kibana_alias."sumPrice")
@@ -1175,9 +1182,7 @@ cube_scan_subq AS (
1175
1182
FROM KibanaSampleDataEcommerce kibana_alias
1176
1183
JOIN Logs logs_alias
1177
1184
ON kibana_alias.__cubeJoinField = logs_alias.__cubeJoinField
1178
- GROUP BY
1179
- logs_content,
1180
- last_mod_month
1185
+ GROUP BY 1,2,3,4,5,6,7
1181
1186
),
1182
1187
filter_subq AS (
1183
1188
SELECT
@@ -1187,7 +1192,12 @@ filter_subq AS (
1187
1192
logs_content_filter
1188
1193
)
1189
1194
SELECT
1190
- logs_content
1195
+ -- Should use SELECT * here to reference columns without aliases.
1196
+ -- But it's broken ATM in DF, initial plan contains `Projection: ... #__subquery-0.logs_content_filter` on top, but it should not be there
1197
+ -- TODO fix it
1198
+ logs_content,
1199
+ cube_user,
1200
+ literal
1191
1201
FROM cube_scan_subq
1192
1202
WHERE
1193
1203
-- This subquery filter should trigger wrapping of whole query
@@ -1216,6 +1226,43 @@ WHERE
1216
1226
. unwrap ( )
1217
1227
. sql ;
1218
1228
1229
+ assert_eq ! (
1230
+ logical_plan. find_cube_scan( ) . request,
1231
+ V1LoadRequestQuery {
1232
+ measures: Some ( vec![ "KibanaSampleDataEcommerce.sumPrice" . to_string( ) , ] ) ,
1233
+ dimensions: Some ( vec![ "Logs.content" . to_string( ) , ] ) ,
1234
+ time_dimensions: Some ( vec![
1235
+ V1LoadRequestQueryTimeDimension {
1236
+ dimension: "KibanaSampleDataEcommerce.last_mod" . to_string( ) ,
1237
+ granularity: Some ( "month" . to_string( ) ) ,
1238
+ date_range: None ,
1239
+ } ,
1240
+ V1LoadRequestQueryTimeDimension {
1241
+ dimension: "KibanaSampleDataEcommerce.order_date" . to_string( ) ,
1242
+ granularity: Some ( "month" . to_string( ) ) ,
1243
+ date_range: None ,
1244
+ } ,
1245
+ ] ) ,
1246
+ segments: Some ( vec![ ] ) ,
1247
+ order: Some ( vec![ ] ) ,
1248
+ ..Default :: default ( )
1249
+ }
1250
+ ) ;
1251
+
1252
+ assert_eq ! (
1253
+ logical_plan. find_cube_scan( ) . member_fields,
1254
+ vec![
1255
+ MemberField :: Member ( "Logs.content" . to_string( ) ) ,
1256
+ MemberField :: Member ( "KibanaSampleDataEcommerce.last_mod.month" . to_string( ) ) ,
1257
+ MemberField :: Literal ( ScalarValue :: Utf8 ( None ) ) ,
1258
+ MemberField :: Literal ( ScalarValue :: Int64 ( Some ( 1 ) ) ) ,
1259
+ MemberField :: Member ( "KibanaSampleDataEcommerce.order_date.month" . to_string( ) ) ,
1260
+ MemberField :: Literal ( ScalarValue :: Utf8 ( None ) ) ,
1261
+ MemberField :: Literal ( ScalarValue :: Int64 ( Some ( 2 ) ) ) ,
1262
+ MemberField :: Member ( "KibanaSampleDataEcommerce.sumPrice" . to_string( ) ) ,
1263
+ ] ,
1264
+ ) ;
1265
+
1219
1266
// Check that all aliases from different tables have same qualifier, and that names are simple and short
1220
1267
// logs_content => logs_alias.content
1221
1268
// last_mod_month => DATE_TRUNC('month', kibana_alias.last_mod),
@@ -1228,6 +1275,10 @@ WHERE
1228
1275
let sum_price_re = Regex :: new ( r#"CASE WHEN "logs_alias"."[a-zA-Z0-9_]{1,16}" IS NOT NULL THEN "logs_alias"."[a-zA-Z0-9_]{1,16}" ELSE 0 END "sum_price""# )
1229
1276
. unwrap ( ) ;
1230
1277
assert ! ( sum_price_re. is_match( & sql) ) ;
1278
+ let cube_user_re = Regex :: new ( r#""logs_alias"."[a-zA-Z0-9_]{1,16}" "cube_user""# ) . unwrap ( ) ;
1279
+ assert ! ( cube_user_re. is_match( & sql) ) ;
1280
+ let literal_re = Regex :: new ( r#""logs_alias"."[a-zA-Z0-9_]{1,16}" "literal""# ) . unwrap ( ) ;
1281
+ assert ! ( literal_re. is_match( & sql) ) ;
1231
1282
}
1232
1283
1233
1284
/// Test that WrappedSelect(... limit=Some(0) ...) will render it correctly
0 commit comments