@@ -26,7 +26,9 @@ use lance::dataset::transaction::{Operation, Transaction};
2626use lance:: dataset:: { InsertBuilder , NewColumnTransform } ;
2727use lance:: Error ;
2828use lance_io:: utils:: CachedFileSize ;
29- use lance_table:: format:: { DataFile , DeletionFile , DeletionFileType , Fragment , RowIdMeta } ;
29+ use lance_table:: format:: {
30+ DataFile , DeletionFile , DeletionFileType , Fragment , RowDatasetVersionMeta , RowIdMeta ,
31+ } ;
3032use lance_table:: io:: deletion:: deletion_file_path;
3133use object_store:: path:: Path ;
3234use pyo3:: basic:: CompareOp ;
@@ -593,6 +595,9 @@ impl PyDeletionFile {
593595#[ pyclass( name = "RowIdMeta" , module = "lance.fragment" ) ]
594596pub struct PyRowIdMeta ( pub RowIdMeta ) ;
595597
598+ #[ pyclass( name = "RowDatasetVersionMeta" , module = "lance.fragment" ) ]
599+ pub struct PyRowDatasetVersionMeta ( pub RowDatasetVersionMeta ) ;
600+
596601#[ pymethods]
597602impl PyRowIdMeta {
598603 fn asdict ( & self ) -> PyResult < Bound < ' _ , PyDict > > {
@@ -639,6 +644,55 @@ impl PyRowIdMeta {
639644 }
640645}
641646
647+ #[ pymethods]
648+ impl PyRowDatasetVersionMeta {
649+ fn asdict ( & self ) -> PyResult < Bound < ' _ , PyDict > > {
650+ Err ( PyNotImplementedError :: new_err (
651+ "PyRowDatasetVersionMeta.asdict is not yet supported." ,
652+ ) )
653+ }
654+
655+ pub fn json ( & self ) -> PyResult < String > {
656+ serde_json:: to_string ( & self . 0 ) . map_err ( |err| {
657+ PyValueError :: new_err ( format ! (
658+ "Could not serialize RowDatasetVersionMeta due to error: {}" ,
659+ err
660+ ) )
661+ } )
662+ }
663+
664+ #[ staticmethod]
665+ pub fn from_json ( json : String ) -> PyResult < Self > {
666+ let dataset_version_meta = serde_json:: from_str ( & json) . map_err ( |err| {
667+ PyValueError :: new_err ( format ! (
668+ "Could not load RowDatasetVersionMeta due to error: {}" ,
669+ err
670+ ) )
671+ } ) ?;
672+ Ok ( Self ( dataset_version_meta) )
673+ }
674+
675+ fn __reduce__ ( & self , py : Python < ' _ > ) -> PyResult < ( PyObject , PyObject ) > {
676+ let state = self . json ( ) ?;
677+ let state = PyTuple :: new ( py, vec ! [ state] ) ?. extract ( ) ?;
678+ let from_json = PyModule :: import ( py, "lance.fragment" ) ?
679+ . getattr ( "RowDatasetVersionMeta" ) ?
680+ . getattr ( "from_json" ) ?
681+ . extract ( ) ?;
682+ Ok ( ( from_json, state) )
683+ }
684+
685+ pub fn __richcmp__ ( & self , other : PyRef < ' _ , Self > , op : CompareOp ) -> PyResult < bool > {
686+ match op {
687+ CompareOp :: Eq => Ok ( self . 0 == other. 0 ) ,
688+ CompareOp :: Ne => Ok ( self . 0 != other. 0 ) ,
689+ _ => Err ( PyNotImplementedError :: new_err (
690+ "Only == and != are supported for RowDatasetVersionMeta" ,
691+ ) ) ,
692+ }
693+ }
694+ }
695+
642696#[ pyclass( name = "FragmentSession" , module = "_lib" , subclass) ]
643697#[ derive( Clone ) ]
644698pub struct FragmentSession {
@@ -670,13 +724,21 @@ impl FromPyObject<'_> for PyLance<Fragment> {
670724
671725 let row_id_meta: Option < PyRef < PyRowIdMeta > > = ob. getattr ( "row_id_meta" ) ?. extract ( ) ?;
672726 let row_id_meta = row_id_meta. map ( |r| r. 0 . clone ( ) ) ;
727+ let last_updated_at_version_meta: Option < PyRef < PyRowDatasetVersionMeta > > =
728+ ob. getattr ( "last_updated_at_version_meta" ) ?. extract ( ) ?;
729+ let last_updated_at_version_meta = last_updated_at_version_meta. map ( |r| r. 0 . clone ( ) ) ;
730+ let created_at_version_meta: Option < PyRef < PyRowDatasetVersionMeta > > =
731+ ob. getattr ( "created_at_version_meta" ) ?. extract ( ) ?;
732+ let created_at_version_meta = created_at_version_meta. map ( |r| r. 0 . clone ( ) ) ;
673733
674734 Ok ( Self ( Fragment {
675735 id : ob. getattr ( "id" ) ?. extract ( ) ?,
676736 files,
677737 deletion_file,
678738 physical_rows : ob. getattr ( "physical_rows" ) ?. extract ( ) ?,
679739 row_id_meta,
740+ last_updated_at_version_meta,
741+ created_at_version_meta,
680742 } ) )
681743 }
682744}
@@ -699,13 +761,25 @@ impl<'py> IntoPyObject<'py> for PyLance<&Fragment> {
699761 . as_ref ( )
700762 . map ( |f| PyDeletionFile ( f. clone ( ) ) ) ;
701763 let row_id_meta = self . 0 . row_id_meta . as_ref ( ) . map ( |r| PyRowIdMeta ( r. clone ( ) ) ) ;
764+ let last_updated_at_version_meta = self
765+ . 0
766+ . last_updated_at_version_meta
767+ . as_ref ( )
768+ . map ( |r| PyRowDatasetVersionMeta ( r. clone ( ) ) ) ;
769+ let created_at_version_meta = self
770+ . 0
771+ . created_at_version_meta
772+ . as_ref ( )
773+ . map ( |r| PyRowDatasetVersionMeta ( r. clone ( ) ) ) ;
702774
703775 cls. call1 ( (
704776 self . 0 . id ,
705777 files,
706778 self . 0 . physical_rows ,
707779 deletion_file,
708780 row_id_meta,
781+ created_at_version_meta,
782+ last_updated_at_version_meta,
709783 ) )
710784 }
711785}
0 commit comments