From 950daf39bb7287224930b270c5a7366fb9e02c61 Mon Sep 17 00:00:00 2001 From: Jiayu Liu Date: Thu, 3 Jun 2021 14:17:23 +0800 Subject: [PATCH] add default value for window frame --- src/ast/mod.rs | 24 ++++++++++++++++++++++++ tests/sqlparser_common.rs | 2 +- 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/src/ast/mod.rs b/src/ast/mod.rs index d5f929f1..57d671c4 100644 --- a/src/ast/mod.rs +++ b/src/ast/mod.rs @@ -444,6 +444,19 @@ pub struct WindowFrame { // TBD: EXCLUDE } +impl Default for WindowFrame { + /// returns default value for window frame + /// + /// see https://www.sqlite.org/windowfunctions.html#frame_specifications + fn default() -> Self { + Self { + units: WindowFrameUnits::Range, + start_bound: WindowFrameBound::Preceding(None), + end_bound: None, + } + } +} + #[derive(Debug, Clone, PartialEq, Eq, Hash)] #[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] pub enum WindowFrameUnits { @@ -1622,3 +1635,14 @@ impl fmt::Display for SqliteOnConflict { } } } + +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn test_window_frame_default() { + let window_frame = WindowFrame::default(); + assert_eq!(WindowFrameBound::Preceding(None), window_frame.start_bound); + } +} diff --git a/tests/sqlparser_common.rs b/tests/sqlparser_common.rs index 4de9d5c6..04143a1b 100644 --- a/tests/sqlparser_common.rs +++ b/tests/sqlparser_common.rs @@ -109,7 +109,7 @@ fn parse_insert_sqlite() { .unwrap() { Statement::Insert { or, .. } => assert_eq!(or, expected_action), - _ => panic!("{}", sql.to_string()), + _ => panic!("{}", sql), }; let sql = "INSERT INTO test_table(id) VALUES(1)";