(frame: WindowFrame<rq::Expr>)
| 877 | } |
| 878 | |
| 879 | fn 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 | |
| 911 | pub(super) fn translate_column_sort( |
| 912 | sort: &ColumnSort<rq::CId>, |
no test coverage detected