use crate::input::proto::substrait;
use crate::output::diagnostic;
use crate::parse::context;
use crate::parse::sorts;
pub fn parse_sort_rel(x: &substrait::SortRel, y: &mut context::Context) -> diagnostic::Result<()> {
let in_type = handle_rel_input!(x, y);
y.set_schema(in_type);
let keys = proto_required_repeated_field!(x, y, sorts, sorts::parse_sort_field).1;
describe!(
y,
Relation,
"Order by {}",
keys.first().cloned().flatten().unwrap_or_default()
);
if x.sorts.len() > 1 {
summary!(
y,
"This relation reorders or coalesces a dataset based on {} keys. \
For sorts, the first key has greatest priority; only if the first \
key is equivalent for two rows will the next key be checked.",
x.sorts.len()
);
} else {
summary!(
y,
"This relation reorders or coalesces a dataset based on the value of {}.",
keys.first().cloned().flatten().unwrap_or_default()
);
}
handle_rel_common!(x, y);
handle_advanced_extension!(x, y);
Ok(())
}