Skip to content

Commit 6943d50

Browse files
committed
feat(cubesql): Propagate joins from SQL query to join hints in CubeScan
1 parent cfb8594 commit 6943d50

File tree

14 files changed

+325
-81
lines changed

14 files changed

+325
-81
lines changed

rust/cubesql/cubesql/src/compile/engine/df/wrapper.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3369,8 +3369,7 @@ impl WrappedSelectNode {
33693369
subquery_joins: (!prepared_join_subqueries.is_empty())
33703370
.then_some(prepared_join_subqueries),
33713371

3372-
// TODO collect join_hints during rewrites and put them here
3373-
join_hints: None,
3372+
join_hints: load_request.join_hints.clone(),
33743373
};
33753374

33763375
// TODO time dimensions, filters, segments

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

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4665,6 +4665,13 @@ ORDER BY "ca_4" ASC
46654665
segments: Some(vec![]),
46664666
dimensions: Some(vec!["Logs.read".to_string()]),
46674667
order: Some(vec![]),
4668+
join_hints: Some(vec![
4669+
vec!["KibanaSampleDataEcommerce".to_string(), "Logs".to_string(),],
4670+
vec![
4671+
"KibanaSampleDataEcommerce".to_string(),
4672+
"NumberCube".to_string(),
4673+
],
4674+
]),
46684675
..Default::default()
46694676
}
46704677
);
@@ -4726,6 +4733,10 @@ ORDER BY
47264733
date_range: None,
47274734
}]),
47284735
order: Some(vec![]),
4736+
join_hints: Some(vec![vec![
4737+
"KibanaSampleDataEcommerce".to_string(),
4738+
"Logs".to_string(),
4739+
],]),
47294740
..Default::default()
47304741
}
47314742
);
@@ -8218,6 +8229,10 @@ ORDER BY "source"."str0" ASC
82188229
segments: Some(vec![]),
82198230
order: Some(vec![]),
82208231
ungrouped: Some(true),
8232+
join_hints: Some(vec![vec![
8233+
"KibanaSampleDataEcommerce".to_string(),
8234+
"Logs".to_string(),
8235+
],]),
82218236
..Default::default()
82228237
}
82238238
)
@@ -9794,6 +9809,10 @@ ORDER BY "source"."str0" ASC
97949809
segments: Some(vec![]),
97959810
order: Some(vec![]),
97969811
ungrouped: Some(true),
9812+
join_hints: Some(vec![vec![
9813+
"Logs".to_string(),
9814+
"KibanaSampleDataEcommerce".to_string(),
9815+
],]),
97979816
..Default::default()
97989817
},
97999818
);
@@ -11845,6 +11864,12 @@ ORDER BY "source"."str0" ASC
1184511864
}).to_string(),
1184611865
]),
1184711866
order: Some(vec![]),
11867+
join_hints: Some(vec![
11868+
vec![
11869+
"KibanaSampleDataEcommerce".to_string(),
11870+
"Logs".to_string(),
11871+
],
11872+
]),
1184811873
..Default::default()
1184911874
}
1185011875
);
@@ -12271,6 +12296,10 @@ ORDER BY "source"."str0" ASC
1227112296
]),
1227212297
segments: Some(vec![]),
1227312298
order: Some(vec![]),
12299+
join_hints: Some(vec![vec![
12300+
"KibanaSampleDataEcommerce".to_string(),
12301+
"Logs".to_string(),
12302+
],]),
1227412303
..Default::default()
1227512304
}
1227612305
)

rust/cubesql/cubesql/src/compile/rewrite/converter.rs

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,11 @@ use crate::{
1212
AggregateFunctionExprDistinct, AggregateFunctionExprFun, AggregateSplit,
1313
AggregateUDFExprFun, AliasExprAlias, AnyExprAll, AnyExprOp, BetweenExprNegated,
1414
BinaryExprOp, CastExprDataType, ChangeUserMemberValue, ColumnExprColumn,
15-
CubeScanAliasToCube, CubeScanLimit, CubeScanOffset, CubeScanUngrouped, CubeScanWrapped,
16-
DimensionName, EmptyRelationDerivedSourceTableName, EmptyRelationIsWrappable,
17-
EmptyRelationProduceOneRow, FilterMemberMember, FilterMemberOp, FilterMemberValues,
18-
FilterOpOp, GroupingSetExprType, GroupingSetType, InListExprNegated,
19-
InSubqueryExprNegated, JoinJoinConstraint, JoinJoinType, JoinLeftOn,
15+
CubeScanAliasToCube, CubeScanJoinHints, CubeScanLimit, CubeScanOffset,
16+
CubeScanUngrouped, CubeScanWrapped, DimensionName, EmptyRelationDerivedSourceTableName,
17+
EmptyRelationIsWrappable, EmptyRelationProduceOneRow, FilterMemberMember,
18+
FilterMemberOp, FilterMemberValues, FilterOpOp, GroupingSetExprType, GroupingSetType,
19+
InListExprNegated, InSubqueryExprNegated, JoinJoinConstraint, JoinJoinType, JoinLeftOn,
2020
JoinNullEqualsNull, JoinRightOn, LikeExprEscapeChar, LikeExprLikeType, LikeExprNegated,
2121
LikeType, LimitFetch, LimitSkip, LiteralExprValue, LiteralMemberRelation,
2222
LiteralMemberValue, LogicalPlanLanguage, MeasureName, MemberErrorError, OrderAsc,
@@ -2002,6 +2002,12 @@ impl LanguageToLogicalPlanConverter {
20022002
query.ungrouped = Some(true);
20032003
}
20042004

2005+
let join_hints =
2006+
match_data_node!(node_by_id, cube_scan_params[10], CubeScanJoinHints);
2007+
if join_hints.len() > 0 {
2008+
query.join_hints = Some(join_hints);
2009+
}
2010+
20052011
query.order = if !query_order.is_empty() {
20062012
Some(query_order)
20072013
} else {

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

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -303,6 +303,7 @@ crate::plan_to_language! {
303303
can_pushdown_join: bool,
304304
wrapped: bool,
305305
ungrouped: bool,
306+
join_hints: Vec<Vec<String>>,
306307
},
307308
CubeScanWrapper {
308309
input: Arc<LogicalPlan>,
@@ -2177,19 +2178,22 @@ fn cube_scan(
21772178
can_pushdown_join: impl Display,
21782179
wrapped: impl Display,
21792180
ungrouped: impl Display,
2181+
join_hints: impl Display,
21802182
) -> String {
21812183
format!(
2182-
"(CubeScan {} {} {} {} {} {} {} {} {} {})",
2183-
alias_to_cube,
2184-
members,
2185-
filters,
2186-
orders,
2187-
limit,
2188-
offset,
2189-
split,
2190-
can_pushdown_join,
2191-
wrapped,
2192-
ungrouped
2184+
r#"(CubeScan
2185+
{alias_to_cube}
2186+
{members}
2187+
{filters}
2188+
{orders}
2189+
{limit}
2190+
{offset}
2191+
{split}
2192+
{can_pushdown_join}
2193+
{wrapped}
2194+
{ungrouped}
2195+
{join_hints}
2196+
)"#
21932197
)
21942198
}
21952199

rust/cubesql/cubesql/src/compile/rewrite/rules/filters.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ impl RewriteRules for FilterRules {
8585
"?can_pushdown_join",
8686
"?wrapped",
8787
"?ungrouped",
88+
"?join_hints",
8889
),
8990
),
9091
cube_scan(
@@ -98,6 +99,7 @@ impl RewriteRules for FilterRules {
9899
"?can_pushdown_join",
99100
"?wrapped",
100101
"?ungrouped",
102+
"?join_hints",
101103
),
102104
self.push_down_filter_simplify("?expr"),
103105
),
@@ -117,6 +119,7 @@ impl RewriteRules for FilterRules {
117119
"?can_pushdown_join",
118120
"?wrapped",
119121
"?ungrouped",
122+
"?join_hints",
120123
),
121124
),
122125
limit(
@@ -133,6 +136,7 @@ impl RewriteRules for FilterRules {
133136
"?can_pushdown_join",
134137
"?wrapped",
135138
"?ungrouped",
139+
"?join_hints",
136140
),
137141
),
138142
self.push_down_limit_filter(
@@ -177,6 +181,7 @@ impl RewriteRules for FilterRules {
177181
"?can_pushdown_join",
178182
"?wrapped",
179183
"?ungrouped",
184+
"?join_hints",
180185
),
181186
),
182187
),
@@ -196,6 +201,7 @@ impl RewriteRules for FilterRules {
196201
"?can_pushdown_join",
197202
"?wrapped",
198203
"?ungrouped",
204+
"?join_hints",
199205
),
200206
),
201207
),
@@ -234,6 +240,7 @@ impl RewriteRules for FilterRules {
234240
"?can_pushdown_join",
235241
"?wrapped",
236242
"?ungrouped",
243+
"?join_hints",
237244
),
238245
),
239246
"?alias",
@@ -255,6 +262,7 @@ impl RewriteRules for FilterRules {
255262
"?can_pushdown_join",
256263
"?wrapped",
257264
"?ungrouped",
265+
"?join_hints",
258266
),
259267
"?alias",
260268
"?projection_split",
@@ -274,6 +282,7 @@ impl RewriteRules for FilterRules {
274282
"?can_pushdown_join",
275283
"?wrapped",
276284
"?ungrouped",
285+
"?join_hints",
277286
),
278287
cube_scan(
279288
"?alias_to_cube",
@@ -294,6 +303,7 @@ impl RewriteRules for FilterRules {
294303
"?can_pushdown_join",
295304
"?wrapped",
296305
"?ungrouped",
306+
"?join_hints",
297307
),
298308
self.push_down_filter("?alias_to_cube", "?filter_alias_to_cube", "?filter_aliases"),
299309
),
@@ -2468,6 +2478,7 @@ impl RewriteRules for FilterRules {
24682478
"?can_pushdown_join",
24692479
"?wrapped",
24702480
"?ungrouped",
2481+
"?join_hints",
24712482
),
24722483
cube_scan(
24732484
"?source_table_name",
@@ -2484,6 +2495,7 @@ impl RewriteRules for FilterRules {
24842495
"?can_pushdown_join",
24852496
"?wrapped",
24862497
"?ungrouped",
2498+
"?join_hints",
24872499
),
24882500
),
24892501
transforming_rewrite(

rust/cubesql/cubesql/src/compile/rewrite/rules/flatten/top_level.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ impl FlattenRules {
4444
"?can_pushdown_join",
4545
"CubeScanWrapped:false",
4646
"?ungrouped",
47+
"?join_hints",
4748
),
4849
),
4950
],
@@ -65,6 +66,7 @@ impl FlattenRules {
6566
"?can_pushdown_join",
6667
"CubeScanWrapped:false",
6768
"?ungrouped",
69+
"?join_hints",
6870
),
6971
"?new_projection_alias",
7072
"ProjectionSplit:false",
@@ -113,6 +115,7 @@ impl FlattenRules {
113115
"?can_pushdown_join",
114116
"CubeScanWrapped:false",
115117
"?ungrouped",
118+
"?join_hints",
116119
),
117120
),
118121
],
@@ -128,6 +131,7 @@ impl FlattenRules {
128131
"?can_pushdown_join",
129132
"CubeScanWrapped:false",
130133
"?ungrouped",
134+
"?join_hints",
131135
),
132136
flatten_pushdown_replacer(
133137
"?outer_group_expr",

0 commit comments

Comments
 (0)