@@ -528,3 +528,43 @@ def test_inspect_manifests(spark: SparkSession, session_catalog: Catalog, format
528528 for column in df .column_names :
529529 for left , right in zip (lhs [column ].to_list (), rhs [column ].to_list ()):
530530 assert left == right , f"Difference in column { column } : { left } != { right } "
531+
532+
533+ @pytest .mark .integration
534+ @pytest .mark .parametrize ("format_version" , [1 , 2 ])
535+ def test_inspect_metadata_log_entries (
536+ spark : SparkSession , session_catalog : Catalog , arrow_table_with_null : pa .Table , format_version : int
537+ ) -> None :
538+ from pandas .testing import assert_frame_equal
539+
540+ identifier = "default.table_metadata_log_entries"
541+ try :
542+ session_catalog .drop_table (identifier = identifier )
543+ except NoSuchTableError :
544+ pass
545+
546+ tbl = _create_table (session_catalog , identifier , properties = {"format-version" : format_version })
547+
548+ # Write some data
549+ tbl .append (arrow_table_with_null )
550+ tbl .append (arrow_table_with_null )
551+ tbl .append (arrow_table_with_null )
552+
553+ df = tbl .inspect .metadata_log_entries ()
554+ spark_df = spark .sql (f"SELECT * FROM { identifier } .metadata_log_entries" )
555+ lhs = df .to_pandas ()
556+ rhs = spark_df .toPandas ()
557+
558+ # Timestamp in the last row of `metadata_log_entries` table is based on when the table was read
559+ # Therefore, the timestamp of the last row for pyiceberg dataframe and spark dataframe will be different
560+ left_before_last , left_last = lhs [:- 1 ], lhs [- 1 :]
561+ right_before_last , right_last = rhs [:- 1 ], rhs [- 1 :]
562+
563+ # compare all rows except for the last row
564+ assert_frame_equal (left_before_last , right_before_last , check_dtype = False )
565+ # compare the last row, except for the timestamp
566+ for column in df .column_names :
567+ for left , right in zip (left_last [column ], right_last [column ]):
568+ if column == "timestamp" :
569+ continue
570+ assert left == right , f"Difference in column { column } : { left } != { right } "
0 commit comments