@@ -100,9 +100,7 @@ def pull_latest_from_table_or_query(
100100 if created_timestamp_column :
101101 timestamps .append (created_timestamp_column )
102102 timestamp_desc_string = " DESC, " .join (timestamps ) + " DESC"
103- field_string = ", " .join (
104- set (join_key_columns + feature_name_columns + timestamps )
105- )
103+ field_string = ", " .join (join_key_columns + feature_name_columns + timestamps )
106104
107105 client = _get_bigquery_client (
108106 project = config .offline_store .project_id ,
@@ -126,6 +124,36 @@ def pull_latest_from_table_or_query(
126124 query = query , client = client , config = config , full_feature_names = False ,
127125 )
128126
127+ @staticmethod
128+ @log_exceptions_and_usage (offline_store = "bigquery" )
129+ def pull_all_from_table_or_query (
130+ config : RepoConfig ,
131+ data_source : DataSource ,
132+ join_key_columns : List [str ],
133+ feature_name_columns : List [str ],
134+ event_timestamp_column : str ,
135+ start_date : datetime ,
136+ end_date : datetime ,
137+ ) -> RetrievalJob :
138+ assert isinstance (data_source , BigQuerySource )
139+ from_expression = data_source .get_table_query_string ()
140+
141+ client = _get_bigquery_client (
142+ project = config .offline_store .project_id ,
143+ location = config .offline_store .location ,
144+ )
145+ field_string = ", " .join (
146+ join_key_columns + feature_name_columns + [event_timestamp_column ]
147+ )
148+ query = f"""
149+ SELECT { field_string }
150+ FROM { from_expression }
151+ WHERE { event_timestamp_column } BETWEEN TIMESTAMP('{ start_date } ') AND TIMESTAMP('{ end_date } ')
152+ """
153+ return BigQueryRetrievalJob (
154+ query = query , client = client , config = config , full_feature_names = False ,
155+ )
156+
129157 @staticmethod
130158 @log_exceptions_and_usage (offline_store = "bigquery" )
131159 def get_historical_features (
@@ -325,21 +353,13 @@ def _execute_query(
325353 block_until_done (client = self .client , bq_job = bq_job , timeout = timeout )
326354 return bq_job
327355
328- def persist (self , storage : SavedDatasetStorage ) -> "BigQueryRetrievalJob" :
356+ def persist (self , storage : SavedDatasetStorage ):
329357 assert isinstance (storage , SavedDatasetBigQueryStorage )
330358
331- persisted_table = self .to_bigquery (
359+ self .to_bigquery (
332360 bigquery .QueryJobConfig (destination = storage .bigquery_options .table_ref )
333361 )
334362
335- return BigQueryRetrievalJob (
336- query = f"select * from `{ persisted_table } `" ,
337- client = self .client ,
338- config = self .config ,
339- full_feature_names = self .full_feature_names ,
340- metadata = self .metadata ,
341- )
342-
343363 @property
344364 def metadata (self ) -> Optional [RetrievalMetadata ]:
345365 return self ._metadata
0 commit comments