@@ -27,6 +27,8 @@ use lance::Error;
27
27
use lance_table:: format:: { DataFile , DeletionFile , DeletionFileType , Fragment , RowIdMeta } ;
28
28
use lance_table:: io:: deletion:: deletion_file_path;
29
29
use object_store:: path:: Path ;
30
+ use pyo3:: basic:: CompareOp ;
31
+ use pyo3:: types:: PyTuple ;
30
32
use pyo3:: { exceptions:: * , types:: PyDict } ;
31
33
use pyo3:: { intern, prelude:: * } ;
32
34
use snafu:: location;
@@ -507,6 +509,43 @@ impl PyDeletionFile {
507
509
} ;
508
510
Ok ( deletion_file_path ( & base_path, fragment_id, & self . 0 ) . to_string ( ) )
509
511
}
512
+
513
+ pub fn json ( & self ) -> PyResult < String > {
514
+ serde_json:: to_string ( & self . 0 ) . map_err ( |err| {
515
+ PyValueError :: new_err ( format ! (
516
+ "Could not dump CompactionPlan due to error: {}" ,
517
+ err
518
+ ) )
519
+ } )
520
+ }
521
+
522
+ #[ staticmethod]
523
+ pub fn from_json ( json : String ) -> PyResult < Self > {
524
+ let deletion_file = serde_json:: from_str ( & json) . map_err ( |err| {
525
+ PyValueError :: new_err ( format ! ( "Could not load DeletionFile due to error: {}" , err) )
526
+ } ) ?;
527
+ Ok ( Self ( deletion_file) )
528
+ }
529
+
530
+ fn __reduce__ ( & self , py : Python < ' _ > ) -> PyResult < ( PyObject , PyObject ) > {
531
+ let state = self . json ( ) ?;
532
+ let state = PyTuple :: new_bound ( py, vec ! [ state] ) . extract ( ) ?;
533
+ let from_json = PyModule :: import_bound ( py, "lance.fragment" ) ?
534
+ . getattr ( "DeletionFile" ) ?
535
+ . getattr ( "from_json" ) ?
536
+ . extract ( ) ?;
537
+ Ok ( ( from_json, state) )
538
+ }
539
+
540
+ pub fn __richcmp__ ( & self , other : PyRef < ' _ , Self > , op : CompareOp ) -> PyResult < bool > {
541
+ match op {
542
+ CompareOp :: Eq => Ok ( self . 0 == other. 0 ) ,
543
+ CompareOp :: Ne => Ok ( self . 0 != other. 0 ) ,
544
+ _ => Err ( PyNotImplementedError :: new_err (
545
+ "Only == and != are supported for CompactionTask" ,
546
+ ) ) ,
547
+ }
548
+ }
510
549
}
511
550
512
551
#[ pyclass( name = "RowIdMeta" , module = "lance.fragment" ) ]
@@ -519,6 +558,43 @@ impl PyRowIdMeta {
519
558
"PyRowIdMeta.asdict is not yet supported.s" ,
520
559
) )
521
560
}
561
+
562
+ pub fn json ( & self ) -> PyResult < String > {
563
+ serde_json:: to_string ( & self . 0 ) . map_err ( |err| {
564
+ PyValueError :: new_err ( format ! (
565
+ "Could not dump CompactionPlan due to error: {}" ,
566
+ err
567
+ ) )
568
+ } )
569
+ }
570
+
571
+ #[ staticmethod]
572
+ pub fn from_json ( json : String ) -> PyResult < Self > {
573
+ let row_id_meta = serde_json:: from_str ( & json) . map_err ( |err| {
574
+ PyValueError :: new_err ( format ! ( "Could not load RowIdMeta due to error: {}" , err) )
575
+ } ) ?;
576
+ Ok ( Self ( row_id_meta) )
577
+ }
578
+
579
+ fn __reduce__ ( & self , py : Python < ' _ > ) -> PyResult < ( PyObject , PyObject ) > {
580
+ let state = self . json ( ) ?;
581
+ let state = PyTuple :: new_bound ( py, vec ! [ state] ) . extract ( ) ?;
582
+ let from_json = PyModule :: import_bound ( py, "lance.fragment" ) ?
583
+ . getattr ( "RowIdMeta" ) ?
584
+ . getattr ( "from_json" ) ?
585
+ . extract ( ) ?;
586
+ Ok ( ( from_json, state) )
587
+ }
588
+
589
+ pub fn __richcmp__ ( & self , other : PyRef < ' _ , Self > , op : CompareOp ) -> PyResult < bool > {
590
+ match op {
591
+ CompareOp :: Eq => Ok ( self . 0 == other. 0 ) ,
592
+ CompareOp :: Ne => Ok ( self . 0 != other. 0 ) ,
593
+ _ => Err ( PyNotImplementedError :: new_err (
594
+ "Only == and != are supported for CompactionTask" ,
595
+ ) ) ,
596
+ }
597
+ }
522
598
}
523
599
524
600
impl FromPyObject < ' _ > for PyLance < Fragment > {
0 commit comments