Skip to content

fix: specify roottype in substrait fieldreference #13647

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

Merged
merged 3 commits into from
Dec 13, 2024
Merged
Changes from all commits
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
26 changes: 24 additions & 2 deletions datafusion/substrait/src/logical_plan/producer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ use datafusion::prelude::Expr;
use pbjson_types::Any as ProtoAny;
use substrait::proto::exchange_rel::{ExchangeKind, RoundRobin, ScatterFields};
use substrait::proto::expression::cast::FailureBehavior;
use substrait::proto::expression::field_reference::{RootReference, RootType};
use substrait::proto::expression::literal::interval_day_to_second::PrecisionMode;
use substrait::proto::expression::literal::map::KeyValue;
use substrait::proto::expression::literal::{
Expand Down Expand Up @@ -2150,7 +2151,7 @@ fn try_to_substrait_field_reference(
}),
)),
})),
root_type: None,
root_type: Some(RootType::RootReference(RootReference {})),
})
}
_ => substrait_err!("Expect a `Column` expr, but found {expr:?}"),
Expand Down Expand Up @@ -2192,13 +2193,14 @@ fn substrait_field_ref(index: usize) -> Result<Expression> {
}),
)),
})),
root_type: None,
root_type: Some(RootType::RootReference(RootReference {})),
}))),
})
}

#[cfg(test)]
mod test {

use super::*;
use crate::logical_plan::consumer::{
from_substrait_extended_expr, from_substrait_literal_without_names,
Expand Down Expand Up @@ -2422,6 +2424,26 @@ mod test {
Ok(())
}

#[test]
fn to_field_reference() -> Result<()> {
let expression = substrait_field_ref(2)?;

match &expression.rex_type {
Some(RexType::Selection(field_ref)) => {
assert_eq!(
field_ref
.root_type
.clone()
.expect("root type should be set"),
RootType::RootReference(RootReference {})
);
}

_ => panic!("Should not be anything other than field reference"),
}
Ok(())
}

#[test]
fn named_struct_names() -> Result<()> {
let schema = DFSchemaRef::new(DFSchema::try_from(Schema::new(vec![
Expand Down
Loading