@@ -231,7 +231,9 @@ def __init__(
231
231
# Now that we're starting the session, don't allow the options to be
232
232
# changed.
233
233
context ._session_started = True
234
- self ._df_snapshot : Dict [bigquery .TableReference , datetime .datetime ] = {}
234
+ self ._df_snapshot : Dict [
235
+ bigquery .TableReference , Tuple [datetime .datetime , bigquery .Table ]
236
+ ] = {}
235
237
236
238
@property
237
239
def bqclient (self ):
@@ -698,16 +700,25 @@ def _get_snapshot_sql_and_primary_key(
698
700
column(s), then return those too so that ordering generation can be
699
701
avoided.
700
702
"""
701
- # If there are primary keys defined, the query engine assumes these
702
- # columns are unique, even if the constraint is not enforced. We make
703
- # the same assumption and use these columns as the total ordering keys.
704
- table = self .bqclient .get_table (table_ref )
703
+ (
704
+ snapshot_timestamp ,
705
+ table ,
706
+ ) = bigframes_io .get_snapshot_datetime_and_table_metadata (
707
+ self .bqclient ,
708
+ table_ref = table_ref ,
709
+ api_name = api_name ,
710
+ cache = self ._df_snapshot ,
711
+ use_cache = use_cache ,
712
+ )
705
713
706
714
if table .location .casefold () != self ._location .casefold ():
707
715
raise ValueError (
708
716
f"Current session is in { self ._location } but dataset '{ table .project } .{ table .dataset_id } ' is located in { table .location } "
709
717
)
710
718
719
+ # If there are primary keys defined, the query engine assumes these
720
+ # columns are unique, even if the constraint is not enforced. We make
721
+ # the same assumption and use these columns as the total ordering keys.
711
722
primary_keys = None
712
723
if (
713
724
(table_constraints := getattr (table , "table_constraints" , None )) is not None
@@ -718,37 +729,6 @@ def _get_snapshot_sql_and_primary_key(
718
729
):
719
730
primary_keys = columns
720
731
721
- job_config = bigquery .QueryJobConfig ()
722
- job_config .labels ["bigframes-api" ] = api_name
723
- if use_cache and table_ref in self ._df_snapshot .keys ():
724
- snapshot_timestamp = self ._df_snapshot [table_ref ]
725
-
726
- # Cache hit could be unexpected. See internal issue 329545805.
727
- # Raise a warning with more information about how to avoid the
728
- # problems with the cache.
729
- warnings .warn (
730
- f"Reading cached table from { snapshot_timestamp } to avoid "
731
- "incompatibilies with previous reads of this table. To read "
732
- "the latest version, set `use_cache=False` or close the "
733
- "current session with Session.close() or "
734
- "bigframes.pandas.close_session()." ,
735
- # There are many layers before we get to (possibly) the user's code:
736
- # pandas.read_gbq_table
737
- # -> with_default_session
738
- # -> Session.read_gbq_table
739
- # -> _read_gbq_table
740
- # -> _get_snapshot_sql_and_primary_key
741
- stacklevel = 6 ,
742
- )
743
- else :
744
- snapshot_timestamp = list (
745
- self .bqclient .query (
746
- "SELECT CURRENT_TIMESTAMP() AS `current_timestamp`" ,
747
- job_config = job_config ,
748
- ).result ()
749
- )[0 ][0 ]
750
- self ._df_snapshot [table_ref ] = snapshot_timestamp
751
-
752
732
try :
753
733
table_expression = self .ibis_client .sql (
754
734
bigframes_io .create_snapshot_sql (table_ref , snapshot_timestamp )
0 commit comments