MCPcopy Create free account
hub / github.com/PRQL/prql / try_into_window_frame

Function try_into_window_frame

prqlc/prqlc/src/sql/gen_expr.rs:879–909  ·  view source on GitHub ↗
(frame: WindowFrame<rq::Expr>)

Source from the content-addressed store, hash-verified

877}
878
879fn try_into_window_frame(frame: WindowFrame<rq::Expr>) -> Result<sql_ast::WindowFrame> {
880 fn parse_bound(bound: rq::Expr) -> Result<WindowFrameBound> {
881 let as_int = unpack_as_int_literal(bound)?;
882 Ok(match as_int {
883 0 => WindowFrameBound::CurrentRow,
884 1.. => WindowFrameBound::Following(Some(Box::new(sql_ast::Expr::Value(
885 sql_ast::Value::Number(as_int.to_string(), false).into(),
886 )))),
887 _ => WindowFrameBound::Preceding(Some(Box::new(sql_ast::Expr::Value(
888 sql_ast::Value::Number((-as_int).to_string(), false).into(),
889 )))),
890 })
891 }
892
893 Ok(sql_ast::WindowFrame {
894 units: match frame.kind {
895 WindowKind::Rows => sql_ast::WindowFrameUnits::Rows,
896 WindowKind::Range => sql_ast::WindowFrameUnits::Range,
897 },
898 start_bound: if let Some(start) = frame.range.start {
899 parse_bound(start)?
900 } else {
901 WindowFrameBound::Preceding(None)
902 },
903 end_bound: Some(if let Some(end) = frame.range.end {
904 parse_bound(end)?
905 } else {
906 WindowFrameBound::Following(None)
907 }),
908 })
909}
910
911pub(super) fn translate_column_sort(
912 sort: &ColumnSort<rq::CId>,

Callers 1

translate_windowedFunction · 0.85

Calls 1

parse_boundFunction · 0.85

Tested by

no test coverage detected