@@ -58,3 +58,68 @@ impl fmt::Display for WindowOperator {
5858 Ok ( ( ) )
5959 }
6060}
61+
62+ // GRCOV_EXCL_START
63+ #[ cfg( all( test, not( target_arch = "wasm32" ) ) ) ]
64+ mod tests {
65+ use super :: * ;
66+ use crate :: expression:: window:: WindowFunctionKind ;
67+ use crate :: planner:: TableArena ;
68+ use crate :: serdes:: { ReferenceSerialization , ReferenceTables } ;
69+ use crate :: storage:: rocksdb:: RocksTransaction ;
70+ use crate :: types:: LogicalType ;
71+ use std:: io:: { Cursor , Seek , SeekFrom } ;
72+
73+ fn operator ( partition_by : Vec < ScalarExpression > , order_by : Vec < SortField > ) -> WindowOperator {
74+ WindowOperator {
75+ partition_by,
76+ order_by,
77+ functions : vec ! [ WindowFunction {
78+ kind: WindowFunctionKind :: RowNumber ,
79+ args: Vec :: new( ) ,
80+ ty: LogicalType :: Bigint ,
81+ } ] ,
82+ output_columns : Vec :: new ( ) ,
83+ }
84+ }
85+
86+ #[ test]
87+ fn display_window_spec ( ) {
88+ let function = "Window [WindowFunction { kind: RowNumber, args: [], ty: Bigint }]" ;
89+ assert_eq ! ( operator( Vec :: new( ) , Vec :: new( ) ) . to_string( ) , function) ;
90+ assert_eq ! (
91+ operator( vec![ 1 . into( ) ] , Vec :: new( ) ) . to_string( ) ,
92+ format!( "{function} -> Partition By [1]" )
93+ ) ;
94+ assert_eq ! (
95+ operator( Vec :: new( ) , vec![ ScalarExpression :: from( 2 ) . desc( ) ] ) . to_string( ) ,
96+ format!( "{function} -> Order By [2 Desc Nulls Last]" )
97+ ) ;
98+ assert_eq ! (
99+ operator( vec![ 1 . into( ) ] , vec![ ScalarExpression :: from( 2 ) . desc( ) ] ) . to_string( ) ,
100+ format!( "{function} -> Partition By [1] Order By [2 Desc Nulls Last]" )
101+ ) ;
102+ }
103+
104+ #[ test]
105+ fn serialization_roundtrip ( ) -> Result < ( ) , crate :: errors:: DatabaseError > {
106+ let source = operator ( vec ! [ 1 . into( ) ] , vec ! [ ScalarExpression :: from( 2 ) . desc( ) ] ) ;
107+ let mut cursor = Cursor :: new ( Vec :: new ( ) ) ;
108+ let mut reference_tables = ReferenceTables :: new ( ) ;
109+ let arena = TableArena :: default ( ) ;
110+ source. encode ( & mut cursor, false , & mut reference_tables, & arena) ?;
111+ cursor. seek ( SeekFrom :: Start ( 0 ) ) ?;
112+
113+ assert_eq ! (
114+ WindowOperator :: decode:: <RocksTransaction , _, _>(
115+ & mut cursor,
116+ None ,
117+ & reference_tables,
118+ & mut TableArena :: default ( ) ,
119+ ) ?,
120+ source
121+ ) ;
122+ Ok ( ( ) )
123+ }
124+ }
125+ // GRCOV_EXCL_STOP
0 commit comments