11use chrono:: prelude:: * ;
22use deltalake:: arrow:: array:: RecordBatch ;
3- use deltalake:: arrow:: datatypes:: Schema as ArrowSchema ;
43use deltalake:: arrow:: error:: ArrowError ;
54use deltalake:: arrow:: json:: reader:: ReaderBuilder ;
65use deltalake:: writer:: { DeltaWriter , record_batch:: RecordBatchWriter } ;
@@ -45,18 +44,15 @@ pub async fn append_values(
4544 mut table : DeltaTable ,
4645 values : impl IntoIterator < Item : AsRef < str > > ,
4746) -> DeltaResult < DeltaTable > {
48- let schema = table. get_schema ( ) ?;
47+ let schema = table. snapshot ( ) ?. snapshot ( ) . arrow_schema ( ) ;
4948 debug ! ( "Attempting to append values with schema: {schema:?}" ) ;
50- let schema = ArrowSchema :: try_from ( schema) ?;
5149
5250 let mut writer = RecordBatchWriter :: for_table ( & table) ?;
5351 let mut written = false ;
5452
5553 for value in values {
5654 let cursor: Cursor < & str > = Cursor :: new ( value. as_ref ( ) ) ;
57- let reader = ReaderBuilder :: new ( schema. clone ( ) . into ( ) )
58- . build ( cursor)
59- . unwrap ( ) ;
55+ let reader = ReaderBuilder :: new ( schema. clone ( ) ) . build ( cursor) . unwrap ( ) ;
6056
6157 for res in reader {
6258 match res {
@@ -131,8 +127,7 @@ mod tests {
131127 use deltalake:: * ;
132128
133129 async fn setup_test_table ( ) -> DeltaResult < DeltaTable > {
134- DeltaOps :: try_from_uri ( "memory://" )
135- . await ?
130+ DeltaOps :: new_in_memory ( )
136131 . create ( )
137132 . with_table_name ( "test" )
138133 . with_column ( "id" , DataType :: INTEGER , true , None )
@@ -146,8 +141,7 @@ mod tests {
146141 use std:: fs:: File ;
147142 use std:: io:: BufReader ;
148143
149- let table = DeltaOps :: try_from_uri ( "memory://" )
150- . await ?
144+ let table = DeltaOps :: new_in_memory ( )
151145 . create ( )
152146 . with_table_name ( "test" )
153147 . with_column ( "current" , DataType :: BOOLEAN , true , None )
@@ -157,12 +151,12 @@ mod tests {
157151
158152 let buf = File :: open ( "../../tests/data/senators.jsonl" ) ?;
159153 let reader = BufReader :: new ( buf) ;
160- let schema = ArrowSchema :: try_from ( table. get_schema ( ) ?) ? ;
154+ let schema = table. snapshot ( ) ?. snapshot ( ) . arrow_schema ( ) ;
161155
162- let json = deltalake:: arrow:: json:: ReaderBuilder :: new ( schema. into ( ) ) . build ( reader) ?;
156+ let json = deltalake:: arrow:: json:: ReaderBuilder :: new ( schema) . build ( reader) ?;
163157
164158 let table = append_batches ( table, json) . await ?;
165- assert_eq ! ( table. version( ) , 1 ) ;
159+ assert_eq ! ( table. version( ) , Some ( 1 ) ) ;
166160 Ok ( ( ) )
167161 }
168162
@@ -178,7 +172,7 @@ mod tests {
178172 . await
179173 . expect ( "Failed to do nothing" ) ;
180174
181- assert_eq ! ( table. version( ) , 1 ) ;
175+ assert_eq ! ( table. version( ) , Some ( 1 ) ) ;
182176 Ok ( ( ) )
183177 }
184178
@@ -191,9 +185,8 @@ mod tests {
191185 "# ;
192186
193187 let cursor = Cursor :: new ( jsonl) ;
194- let schema = table. get_schema ( ) ?;
195- let schema = ArrowSchema :: try_from ( schema) ?;
196- let mut reader = ReaderBuilder :: new ( schema. into ( ) ) . build ( cursor) . unwrap ( ) ;
188+ let schema = table. snapshot ( ) ?. snapshot ( ) . arrow_schema ( ) ;
189+ let mut reader = ReaderBuilder :: new ( schema) . build ( cursor) . unwrap ( ) ;
197190
198191 while let Some ( Ok ( batch) ) = reader. next ( ) {
199192 let batch = augment_with_ds ( batch) ?;
@@ -215,12 +208,13 @@ mod tests {
215208 . await
216209 . expect ( "Failed to do nothing" ) ;
217210
218- assert_eq ! ( table. version( ) , 1 ) ;
211+ assert_eq ! ( table. version( ) , Some ( 1 ) ) ;
219212 Ok ( ( ) )
220213 }
221214
222215 #[ tokio:: test]
223216 async fn test_append_values_checkpoint ( ) -> DeltaResult < ( ) > {
217+ use deltalake:: table:: config:: TablePropertiesExt ;
224218 let mut table = setup_test_table ( ) . await ?;
225219
226220 for _ in 0 ..101 {
@@ -235,7 +229,7 @@ mod tests {
235229
236230 if let Some ( state) = table. state . as_ref ( ) {
237231 // The default is expected to be 100
238- assert_eq ! ( 100 , state. table_config( ) . checkpoint_interval( ) ) ;
232+ assert_eq ! ( 100 , state. table_config( ) . checkpoint_interval( ) . get ( ) ) ;
239233 }
240234
241235 use deltalake:: Path ;
@@ -245,7 +239,7 @@ mod tests {
245239 . await ?;
246240
247241 assert_ne ! ( 0 , checkpoint. size) ;
248- assert_eq ! ( table. version( ) , 101 ) ;
242+ assert_eq ! ( table. version( ) , Some ( 101 ) ) ;
249243 Ok ( ( ) )
250244 }
251245}
0 commit comments