File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 11use crate :: jstable;
22use crate :: log:: { LogEntry , Logger , Operation } ;
33use crate :: storage:: MemTable ;
4- use serde_json:: { json , Value } ;
4+ use serde_json:: Value ;
55use std:: fs;
66use uuid:: Uuid ;
77
Original file line number Diff line number Diff line change @@ -37,7 +37,6 @@ impl Logger {
3737 let path = path. as_ref ( ) . to_path_buf ( ) ;
3838 let file = OpenOptions :: new ( )
3939 . create ( true )
40- . write ( true )
4140 . append ( true )
4241 . open ( & path) ?;
4342 Ok ( Logger {
@@ -64,7 +63,6 @@ impl Logger {
6463 fs:: rename ( & self . path , new_path) ?;
6564 self . file = OpenOptions :: new ( )
6665 . create ( true )
67- . write ( true )
6866 . append ( true )
6967 . open ( & self . path ) ?;
7068 Ok ( ( ) )
Original file line number Diff line number Diff line change @@ -74,7 +74,7 @@ pub fn infer_schema(doc: &Value) -> Schema {
7474 }
7575 Value :: String ( _) => Schema :: new ( SchemaType :: String ) ,
7676 Value :: Array ( arr) => {
77- let mut items_schema = if let Some ( first) = arr. get ( 0 ) {
77+ let mut items_schema = if let Some ( first) = arr. first ( ) {
7878 infer_schema ( first)
7979 } else {
8080 // Empty array, we can't infer the type.
Original file line number Diff line number Diff line change @@ -8,6 +8,12 @@ pub struct MemTable {
88 schema : Schema ,
99}
1010
11+ impl Default for MemTable {
12+ fn default ( ) -> Self {
13+ Self :: new ( )
14+ }
15+ }
16+
1117impl MemTable {
1218 pub fn new ( ) -> Self {
1319 MemTable {
@@ -24,6 +30,10 @@ impl MemTable {
2430 self . documents . len ( )
2531 }
2632
33+ pub fn is_empty ( & self ) -> bool {
34+ self . documents . is_empty ( )
35+ }
36+
2737 pub fn flush ( & self , path : & str ) -> std:: io:: Result < ( ) > {
2838 let timestamp = std:: time:: SystemTime :: now ( )
2939 . duration_since ( std:: time:: UNIX_EPOCH )
You can’t perform that action at this time.
0 commit comments