use std::sync::Arc;
use crate::input::proto::substrait;
use crate::output::diagnostic;
use crate::output::type_system::data;
use crate::parse::context;
use crate::parse::expressions;
pub fn parse_project_rel(
x: &substrait::ProjectRel,
y: &mut context::Context,
) -> diagnostic::Result<()> {
let mut schema = handle_rel_input!(x, y);
y.set_schema(schema.clone());
let expressions = proto_required_repeated_field!(
x,
y,
expressions,
expressions::parse_expression,
|_x, y, _i, n, _r| {
if let Some(mut fields) = schema.unwrap_struct() {
fields.push(n.data_type());
schema = data::new_struct(fields, false);
y.set_schema(schema.clone());
} else {
y.set_schema(Arc::default());
}
}
)
.1;
describe!(y, Relation, "Projection");
if expressions.len() > 1 {
summary!(
y,
"This relation generates {} new columns by projecting the existing columns using scalar expressions.",
expressions.len()
);
} else {
summary!(
y,
"This relation generates a new column by projecting the existing columns using a scalar expression."
);
}
handle_rel_common!(x, y);
handle_advanced_extension!(x, y);
Ok(())
}