1414
1515use std:: time:: Duration ;
1616
17+ use indexmap:: IndexMap ;
1718use itertools:: Itertools ;
18- use lru:: { Iter , LruCache } ;
1919use risingwave_sqlparser:: ast:: Statement ;
2020use risingwave_sqlparser:: parser:: Parser ;
2121use sqllogictest:: { DBOutput , DefaultColumnType } ;
@@ -33,33 +33,10 @@ pub struct RisingWave {
3333
3434/// `SetStmts` stores and compacts all `SET` statements that have been executed in the client
3535/// history.
36+ #[ derive( Default ) ]
3637pub struct SetStmts {
37- stmts_cache : LruCache < String , String > ,
38- }
39-
40- impl Default for SetStmts {
41- fn default ( ) -> Self {
42- Self {
43- stmts_cache : LruCache :: unbounded ( ) ,
44- }
45- }
46- }
47-
48- struct SetStmtsIterator < ' a , ' b >
49- where
50- ' a : ' b ,
51- {
52- _stmts : & ' a SetStmts ,
53- stmts_iter : core:: iter:: Rev < Iter < ' b , String , String > > ,
54- }
55-
56- impl < ' a > SetStmtsIterator < ' a , ' _ > {
57- fn new ( stmts : & ' a SetStmts ) -> Self {
58- Self {
59- _stmts : stmts,
60- stmts_iter : stmts. stmts_cache . iter ( ) . rev ( ) ,
61- }
62- }
38+ // variable name -> last set statement
39+ stmts : IndexMap < String , String > ,
6340}
6441
6542impl SetStmts {
@@ -78,19 +55,14 @@ impl SetStmts {
7855 } => {
7956 let key = variable. real_value ( ) . to_lowercase ( ) ;
8057 // store complete sql as value.
81- self . stmts_cache . put ( key, sql. to_owned ( ) ) ;
58+ self . stmts . insert ( key, sql. to_owned ( ) ) ;
8259 }
8360 _ => unreachable ! ( ) ,
8461 }
8562 }
86- }
87-
88- impl Iterator for SetStmtsIterator < ' _ , ' _ > {
89- type Item = String ;
9063
91- fn next ( & mut self ) -> Option < Self :: Item > {
92- let ( _, stmt) = self . stmts_iter . next ( ) ?;
93- Some ( stmt. clone ( ) )
64+ fn replay_iter ( & self ) -> impl Iterator < Item = & str > + ' _ {
65+ self . stmts . values ( ) . map ( |s| s. as_str ( ) )
9466 }
9567}
9668
@@ -130,8 +102,8 @@ impl RisingWave {
130102 }
131103 } ) ;
132104 // replay all SET statements
133- for stmt in SetStmtsIterator :: new ( set_stmts) {
134- client. simple_query ( & stmt) . await ?;
105+ for stmt in set_stmts. replay_iter ( ) {
106+ client. simple_query ( stmt) . await ?;
135107 }
136108 Ok ( ( client, task) )
137109 }
0 commit comments