@@ -713,7 +713,8 @@ def _read_gbq_table(
713713 # Fetch table metadata and validate
714714 # ---------------------------------
715715
716- (time_travel_timestamp , table ,) = bf_read_gbq_table .get_table_metadata (
716+ time_travel_timestamp : Optional [datetime .datetime ] = None
717+ time_travel_timestamp , table = bf_read_gbq_table .get_table_metadata (
717718 self .bqclient ,
718719 table_ref = table_ref ,
719720 api_name = api_name ,
@@ -795,9 +796,34 @@ def _read_gbq_table(
795796
796797 # Use a time travel to make sure the DataFrame is deterministic, even
797798 # if the underlying table changes.
798- # TODO(b/340540991): If a dry run query fails with time travel but
799+
800+ # If a dry run query fails with time travel but
799801 # succeeds without it, omit the time travel clause and raise a warning
800802 # about potential non-determinism if the underlying tables are modified.
803+ sql = bigframes .session ._io .bigquery .to_query (
804+ f"{ table_ref .project } .{ table_ref .dataset_id } .{ table_ref .table_id } " ,
805+ index_cols = index_cols ,
806+ columns = columns ,
807+ filters = filters ,
808+ time_travel_timestamp = time_travel_timestamp ,
809+ max_results = None ,
810+ )
811+ dry_run_config = bigquery .QueryJobConfig ()
812+ dry_run_config .dry_run = True
813+ try :
814+ self ._start_query (sql , job_config = dry_run_config )
815+ except google .api_core .exceptions .NotFound :
816+ # note that a notfound caused by a simple typo will be
817+ # caught above when the metadata is fetched, not here
818+ time_travel_timestamp = None
819+ warnings .warn (
820+ "NotFound error when reading table with time travel."
821+ " Attempting query without time travel. Warning: Without"
822+ " time travel, modifications to the underlying table may"
823+ " result in errors or unexpected behavior." ,
824+ category = bigframes .exceptions .TimeTravelDisabledWarning ,
825+ )
826+
801827 table_expression = bf_read_gbq_table .get_ibis_time_travel_table (
802828 ibis_client = self .ibis_client ,
803829 table_ref = table_ref ,
0 commit comments