Skip to content

Commit 0d7cab0

Browse files
Support crossjoin in substrait. (#8427)
* Support crossjoin in substrait. * use struct destructuring * remove useless builder.
1 parent fd92bcb commit 0d7cab0

File tree

3 files changed

+33
-1
lines changed

3 files changed

+33
-1
lines changed

datafusion/substrait/src/logical_plan/consumer.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -434,6 +434,15 @@ pub async fn from_substrait_rel(
434434
None => plan_err!("JoinRel without join condition is not allowed"),
435435
}
436436
}
437+
Some(RelType::Cross(cross)) => {
438+
let left: LogicalPlanBuilder = LogicalPlanBuilder::from(
439+
from_substrait_rel(ctx, cross.left.as_ref().unwrap(), extensions).await?,
440+
);
441+
let right =
442+
from_substrait_rel(ctx, cross.right.as_ref().unwrap(), extensions)
443+
.await?;
444+
left.cross_join(right)?.build()
445+
}
437446
Some(RelType::Read(read)) => match &read.as_ref().read_type {
438447
Some(ReadType::NamedTable(nt)) => {
439448
let table_reference = match nt.names.len() {

datafusion/substrait/src/logical_plan/producer.rs

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ use std::collections::HashMap;
1919
use std::ops::Deref;
2020
use std::sync::Arc;
2121

22-
use datafusion::logical_expr::{Distinct, Like, WindowFrameUnits};
22+
use datafusion::logical_expr::{CrossJoin, Distinct, Like, WindowFrameUnits};
2323
use datafusion::{
2424
arrow::datatypes::{DataType, TimeUnit},
2525
error::{DataFusionError, Result},
@@ -40,6 +40,7 @@ use datafusion::logical_expr::{expr, Between, JoinConstraint, LogicalPlan, Opera
4040
use datafusion::prelude::Expr;
4141
use prost_types::Any as ProtoAny;
4242
use substrait::proto::expression::window_function::BoundsType;
43+
use substrait::proto::CrossRel;
4344
use substrait::{
4445
proto::{
4546
aggregate_function::AggregationInvocation,
@@ -332,6 +333,23 @@ pub fn to_substrait_rel(
332333
}))),
333334
}))
334335
}
336+
LogicalPlan::CrossJoin(cross_join) => {
337+
let CrossJoin {
338+
left,
339+
right,
340+
schema: _,
341+
} = cross_join;
342+
let left = to_substrait_rel(left.as_ref(), ctx, extension_info)?;
343+
let right = to_substrait_rel(right.as_ref(), ctx, extension_info)?;
344+
Ok(Box::new(Rel {
345+
rel_type: Some(RelType::Cross(Box::new(CrossRel {
346+
common: None,
347+
left: Some(left),
348+
right: Some(right),
349+
advanced_extension: None,
350+
}))),
351+
}))
352+
}
335353
LogicalPlan::SubqueryAlias(alias) => {
336354
// Do nothing if encounters SubqueryAlias
337355
// since there is no corresponding relation type in Substrait

datafusion/substrait/tests/cases/roundtrip_logical_plan.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -394,6 +394,11 @@ async fn roundtrip_inlist_4() -> Result<()> {
394394
roundtrip("SELECT * FROM data WHERE f NOT IN ('a', 'b', 'c', 'd')").await
395395
}
396396

397+
#[tokio::test]
398+
async fn roundtrip_cross_join() -> Result<()> {
399+
roundtrip("SELECT * FROM data CROSS JOIN data2").await
400+
}
401+
397402
#[tokio::test]
398403
async fn roundtrip_inner_join() -> Result<()> {
399404
roundtrip("SELECT data.a FROM data JOIN data2 ON data.a = data2.a").await

0 commit comments

Comments
 (0)