Regularizes the ORDER BY clause of the window frame.
(&self, order_by: &mut Vec<Sort>)
| 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 { |
no test coverage detected