Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support crossjoin in substrait. #8427

Merged
merged 3 commits into from
Dec 6, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions datafusion/substrait/src/logical_plan/consumer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -434,6 +434,16 @@ pub async fn from_substrait_rel(
None => plan_err!("JoinRel without join condition is not allowed"),
}
}
Some(RelType::Cross(cross)) => {
let left: LogicalPlanBuilder = LogicalPlanBuilder::from(
from_substrait_rel(ctx, cross.left.as_ref().unwrap(), extensions).await?,
);
let right = LogicalPlanBuilder::from(
from_substrait_rel(ctx, cross.right.as_ref().unwrap(), extensions)
.await?,
);
left.cross_join(right.build()?)?.build()
my-vegetable-has-exploded marked this conversation as resolved.
Show resolved Hide resolved
}
Some(RelType::Read(read)) => match &read.as_ref().read_type {
Some(ReadType::NamedTable(nt)) => {
let table_reference = match nt.names.len() {
Expand Down
13 changes: 13 additions & 0 deletions datafusion/substrait/src/logical_plan/producer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ use datafusion::logical_expr::{expr, Between, JoinConstraint, LogicalPlan, Opera
use datafusion::prelude::Expr;
use prost_types::Any as ProtoAny;
use substrait::proto::expression::window_function::BoundsType;
use substrait::proto::CrossRel;
use substrait::{
proto::{
aggregate_function::AggregationInvocation,
Expand Down Expand Up @@ -332,6 +333,18 @@ pub fn to_substrait_rel(
}))),
}))
}
LogicalPlan::CrossJoin(cross_join) => {
let left = to_substrait_rel(cross_join.left.as_ref(), ctx, extension_info)?;
my-vegetable-has-exploded marked this conversation as resolved.
Show resolved Hide resolved
let right = to_substrait_rel(cross_join.right.as_ref(), ctx, extension_info)?;
Ok(Box::new(Rel {
rel_type: Some(RelType::Cross(Box::new(CrossRel {
common: None,
left: Some(left),
right: Some(right),
advanced_extension: None,
}))),
}))
}
LogicalPlan::SubqueryAlias(alias) => {
// Do nothing if encounters SubqueryAlias
// since there is no corresponding relation type in Substrait
Expand Down
5 changes: 5 additions & 0 deletions datafusion/substrait/tests/cases/roundtrip_logical_plan.rs
Original file line number Diff line number Diff line change
Expand Up @@ -394,6 +394,11 @@ async fn roundtrip_inlist_4() -> Result<()> {
roundtrip("SELECT * FROM data WHERE f NOT IN ('a', 'b', 'c', 'd')").await
}

#[tokio::test]
async fn roundtrip_cross_join() -> Result<()> {
roundtrip("SELECT * FROM data CROSS JOIN data2").await
}

#[tokio::test]
async fn roundtrip_inner_join() -> Result<()> {
roundtrip("SELECT data.a FROM data JOIN data2 ON data.a = data2.a").await
Expand Down