Skip to content
This repository was archived by the owner on Jan 7, 2025. It is now read-only.

Commit e599545

Browse files
committed
refactor(df-repr): remove cross join, use inner join (#265)
Signed-off-by: Alex Chi Z <[email protected]>
1 parent b4b1aea commit e599545

File tree

9 files changed

+10
-43
lines changed

9 files changed

+10
-43
lines changed

Diff for: optd-datafusion-bridge/src/from_optd.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -476,7 +476,9 @@ impl OptdPlanContext<'_> {
476476
let physical_expr =
477477
self.conv_from_optd_expr(node.cond(), &Arc::new(filter_schema.clone()))?;
478478

479-
if *node.join_type() == JoinType::Cross {
479+
if node.join_type() == &JoinType::Inner
480+
&& node.cond() == ConstantPred::bool(true).into_pred_node()
481+
{
480482
return Ok(Arc::new(CrossJoinExec::new(left_exec, right_exec))
481483
as Arc<dyn ExecutionPlan + 'static>);
482484
}
@@ -491,7 +493,6 @@ impl OptdPlanContext<'_> {
491493
JoinType::LeftAnti => datafusion_expr::JoinType::LeftAnti,
492494
JoinType::RightAnti => datafusion_expr::JoinType::RightAnti,
493495
JoinType::LeftMark => datafusion_expr::JoinType::LeftMark,
494-
_ => unimplemented!(),
495496
};
496497

497498
let mut column_idxs = vec![];

Diff for: optd-datafusion-bridge/src/into_optd.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -547,7 +547,7 @@ impl OptdPlanContext<'_> {
547547
left,
548548
right,
549549
ConstantPred::bool(true).into_pred_node(),
550-
JoinType::Cross,
550+
JoinType::Inner,
551551
))
552552
} else if log_ops.len() == 1 {
553553
Ok(LogicalJoin::new(left, right, log_ops.remove(0), join_type))

Diff for: optd-datafusion-repr-adv-cost/src/adv_stats/join.rs

-7
Original file line numberDiff line numberDiff line change
@@ -191,13 +191,6 @@ impl<
191191
JoinType::Inner => inner_join_selectivity,
192192
JoinType::LeftOuter => f64::max(inner_join_selectivity, 1.0 / right_row_cnt),
193193
JoinType::RightOuter => f64::max(inner_join_selectivity, 1.0 / left_row_cnt),
194-
JoinType::Cross => {
195-
assert!(
196-
on_col_ref_pairs.is_empty(),
197-
"Cross joins should not have on columns"
198-
);
199-
join_filter_selectivity
200-
}
201194
// TODO: Does this make sense?
202195
JoinType::LeftMark => f64::max(inner_join_selectivity, 1.0 / right_row_cnt),
203196
_ => unimplemented!("join_typ={} is not implemented", join_typ),

Diff for: optd-datafusion-repr/src/plan_nodes/join.rs

-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ pub enum JoinType {
1515
FullOuter,
1616
LeftOuter,
1717
RightOuter,
18-
Cross,
1918
LeftSemi,
2019
RightSemi,
2120
LeftAnti,

Diff for: optd-datafusion-repr/src/properties/column_ref.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -471,7 +471,7 @@ impl LogicalPropertyBuilder<DfNodeType> for ColumnRefPropertyBuilder {
471471
//
472472
// Otherwise be conservative and discard all correlations.
473473
let output_correlation = match join_type {
474-
JoinType::Inner | JoinType::Cross => {
474+
JoinType::Inner => {
475475
// Merge the equal columns in the join condition into the those from the
476476
// children.
477477
if let Some(SemanticCorrelation {

Diff for: optd-datafusion-repr/src/properties/schema.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ impl LogicalPropertyBuilder<DfNodeType> for SchemaPropertyBuilder {
180180
DfNodeType::Join(join_type) => {
181181
use crate::plan_nodes::JoinType::*;
182182
match join_type {
183-
Inner | LeftOuter | RightOuter | FullOuter | Cross => {
183+
Inner | LeftOuter | RightOuter | FullOuter => {
184184
let mut schema = children[0].clone();
185185
let schema2 = children[1].clone();
186186
schema.fields.extend(schema2.fields);

Diff for: optd-datafusion-repr/src/rules/filter_pushdown.rs

-26
Original file line numberDiff line numberDiff line change
@@ -160,20 +160,6 @@ fn apply_filter_merge(
160160
vec![new_filter.into_plan_node().into()]
161161
}
162162

163-
// TODO: define_rule! should be able to match on any join type, ideally...
164-
define_rule!(
165-
FilterCrossJoinTransposeRule,
166-
apply_filter_cross_join_transpose,
167-
(Filter, (Join(JoinType::Cross), child_a, child_b))
168-
);
169-
170-
fn apply_filter_cross_join_transpose(
171-
optimizer: &impl Optimizer<DfNodeType>,
172-
binding: ArcDfPlanNode,
173-
) -> Vec<PlanNodeOrGroup<DfNodeType>> {
174-
filter_join_transpose(optimizer, binding)
175-
}
176-
177163
define_rule!(
178164
FilterInnerJoinTransposeRule,
179165
apply_filter_inner_join_transpose,
@@ -256,18 +242,6 @@ fn filter_join_transpose(
256242
let new_conds = merge_conds(and_expr_list_to_expr(join_conds), old_cond);
257243
LogicalJoin::new_unchecked(new_left, new_right, new_conds, JoinType::Inner)
258244
}
259-
JoinType::Cross => {
260-
if !join_conds.is_empty() {
261-
LogicalJoin::new_unchecked(
262-
new_left,
263-
new_right,
264-
and_expr_list_to_expr(join_conds),
265-
JoinType::Inner,
266-
)
267-
} else {
268-
LogicalJoin::new_unchecked(new_left, new_right, join_cond, JoinType::Cross)
269-
}
270-
}
271245
_ => {
272246
// We don't support modifying the join condition for other join types yet
273247
LogicalJoin::new_unchecked(new_left, new_right, join_cond, *join_typ)

Diff for: optd-datafusion-repr/src/rules/joins.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ fn apply_eliminate_join(
8181
left,
8282
right,
8383
ConstantPred::bool(true).into_pred_node(),
84-
JoinType::Cross,
84+
JoinType::Inner,
8585
);
8686
return vec![node.into_plan_node().into()];
8787
} else {

Diff for: optd-datafusion-repr/src/rules/subquery/depjoin_pushdown.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ fn apply_dep_initial_distinct(
8686
left,
8787
right,
8888
ConstantPred::bool(true).into_pred_node(),
89-
JoinType::Cross,
89+
JoinType::Inner,
9090
)
9191
.into_plan_node(),
9292
SubqueryType::Exists => {
@@ -122,7 +122,7 @@ fn apply_dep_initial_distinct(
122122
left,
123123
count_star_to_bool_proj,
124124
ConstantPred::bool(true).into_pred_node(),
125-
JoinType::Cross,
125+
JoinType::Inner,
126126
)
127127
.into_plan_node()
128128
}
@@ -147,7 +147,7 @@ fn apply_dep_initial_distinct(
147147
left,
148148
right,
149149
ConstantPred::bool(true).into_pred_node(),
150-
JoinType::Cross,
150+
JoinType::Inner,
151151
);
152152

153153
return vec![new_join.into_plan_node().into()];

0 commit comments

Comments
 (0)