MCPcopy Create free account
hub / github.com/apache/datafusion / regularize_order_bys

Method regularize_order_bys

datafusion/expr/src/window_frame.rs:249–272  ·  view source on GitHub ↗

Regularizes the ORDER BY clause of the window frame.

(&self, order_by: &mut Vec<Sort>)

Source from the content-addressed store, hash-verified

247
248 /// Regularizes the ORDER BY clause of the window frame.
249 pub fn regularize_order_bys(&self, order_by: &mut Vec<Sort>) -> Result<()> {
250 match self.units {
251 // Normally, RANGE frames require an ORDER BY clause with exactly
252 // one column. However, an ORDER BY clause may be absent or have
253 // more than one column when the start/end bounds are UNBOUNDED or
254 // CURRENT ROW.
255 WindowFrameUnits::Range if self.free_range() && order_by.is_empty() => {
256 // If an ORDER BY clause is absent, it is equivalent to an
257 // ORDER BY clause with constant value as sort key. If an
258 // ORDER BY clause is present but has more than one column,
259 // it is unchanged. Note that this follows PostgreSQL behavior.
260 order_by.push(lit(1u64).sort(true, false));
261 }
262 WindowFrameUnits::Range if self.free_range() => {}
263 WindowFrameUnits::Range if order_by.len() != 1 => {
264 return plan_err!("RANGE requires exactly one ORDER BY column");
265 }
266 WindowFrameUnits::Groups if order_by.is_empty() => {
267 return plan_err!("GROUPS requires an ORDER BY clause");
268 }
269 _ => {}
270 }
271 Ok(())
272 }
273
274 /// Returns whether the window frame can accept multiple ORDER BY expressions.
275 pub fn can_accept_multi_orderby(&self) -> bool {

Callers 3

sql_function_to_exprMethod · 0.80
parse_exprFunction · 0.80
from_window_functionFunction · 0.80

Calls 6

free_rangeMethod · 0.80
litFunction · 0.70
is_emptyMethod · 0.45
pushMethod · 0.45
sortMethod · 0.45
lenMethod · 0.45

Tested by

no test coverage detected