Skip to content

Commit 78a444e

Browse files
chore: Deprecate table_ref parameter for BigQuerySource (feast-dev#2502)
Signed-off-by: Felix Wang <wangfelix98@gmail.com>
1 parent e083458 commit 78a444e

File tree

11 files changed

+51
-71
lines changed

11 files changed

+51
-71
lines changed

java/serving/src/test/java/feast/serving/util/DataGenerator.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -210,11 +210,10 @@ public static DataSource createFileDataSourceSpec(
210210
}
211211

212212
public static DataSource createBigQueryDataSourceSpec(
213-
String bigQueryTableRef, String timestampColumn, String datePartitionColumn) {
213+
String bigQueryTable, String timestampColumn, String datePartitionColumn) {
214214
return DataSource.newBuilder()
215215
.setType(DataSource.SourceType.BATCH_BIGQUERY)
216-
.setBigqueryOptions(
217-
DataSource.BigQueryOptions.newBuilder().setTableRef(bigQueryTableRef).build())
216+
.setBigqueryOptions(DataSource.BigQueryOptions.newBuilder().setTable(bigQueryTable).build())
218217
.setTimestampField(timestampColumn)
219218
.setDatePartitionColumn(datePartitionColumn)
220219
.build();

protos/feast/core/DataSource.proto

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ message DataSource {
9898
// Defines options for DataSource that sources features from a BigQuery Query
9999
message BigQueryOptions {
100100
// Full table reference in the form of [project:dataset.table]
101-
string table_ref = 1;
101+
string table = 1;
102102

103103
// SQL query that returns a table containing feature data. Must contain an event_timestamp column, and respective
104104
// entity columns

sdk/python/feast/infra/offline_stores/bigquery.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -361,7 +361,7 @@ def persist(self, storage: SavedDatasetStorage):
361361
assert isinstance(storage, SavedDatasetBigQueryStorage)
362362

363363
self.to_bigquery(
364-
bigquery.QueryJobConfig(destination=storage.bigquery_options.table_ref)
364+
bigquery.QueryJobConfig(destination=storage.bigquery_options.table)
365365
)
366366

367367
@property

sdk/python/feast/infra/offline_stores/bigquery_source.py

Lines changed: 28 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ def __init__(
1818
self,
1919
event_timestamp_column: Optional[str] = "",
2020
table: Optional[str] = None,
21-
table_ref: Optional[str] = None,
2221
created_timestamp_column: Optional[str] = "",
2322
field_mapping: Optional[Dict[str, str]] = None,
2423
date_partition_column: Optional[str] = None,
@@ -33,14 +32,13 @@ def __init__(
3332
3433
Args:
3534
table (optional): The BigQuery table where features can be found.
36-
table_ref (optional): (Deprecated) The BigQuery table where features can be found.
3735
event_timestamp_column: (Deprecated) Event timestamp column used for point in time joins of feature values.
3836
created_timestamp_column (optional): Timestamp column when row was created, used for deduplicating rows.
3937
field_mapping: A dictionary mapping of column names in this data source to feature names in a feature table
4038
or view. Only used for feature columns, not entities or timestamp columns.
4139
date_partition_column (deprecated): Timestamp column used for partitioning.
4240
query (optional): SQL query to execute to generate data for this data source.
43-
name (optional): Name for the source. Defaults to the table_ref if not specified.
41+
name (optional): Name for the source. Defaults to the table if not specified.
4442
description (optional): A human-readable description.
4543
tags (optional): A dictionary of key-value pairs to store arbitrary metadata.
4644
owner (optional): The owner of the bigquery source, typically the email of the primary
@@ -51,18 +49,10 @@ def __init__(
5149
>>> from feast import BigQuerySource
5250
>>> my_bigquery_source = BigQuerySource(table="gcp_project:bq_dataset.bq_table")
5351
"""
54-
if table is None and table_ref is None and query is None:
52+
if table is None and query is None:
5553
raise ValueError('No "table" or "query" argument provided.')
56-
if not table and table_ref:
57-
warnings.warn(
58-
(
59-
"The argument 'table_ref' is being deprecated. Please use 'table' "
60-
"instead. Feast 0.20 and onwards will not support the argument 'table_ref'."
61-
),
62-
DeprecationWarning,
63-
)
64-
table = table_ref
65-
self.bigquery_options = BigQueryOptions(table_ref=table, query=query)
54+
55+
self.bigquery_options = BigQueryOptions(table=table, query=query)
6656

6757
if date_partition_column:
6858
warnings.warn(
@@ -73,13 +63,11 @@ def __init__(
7363
DeprecationWarning,
7464
)
7565

76-
# If no name, use the table_ref as the default name
66+
# If no name, use the table as the default name
7767
_name = name
7868
if not _name:
7969
if table:
8070
_name = table
81-
elif table_ref:
82-
_name = table_ref
8371
else:
8472
warnings.warn(
8573
(
@@ -111,7 +99,7 @@ def __eq__(self, other):
11199

112100
return (
113101
self.name == other.name
114-
and self.bigquery_options.table_ref == other.bigquery_options.table_ref
102+
and self.bigquery_options.table == other.bigquery_options.table
115103
and self.bigquery_options.query == other.bigquery_options.query
116104
and self.timestamp_field == other.timestamp_field
117105
and self.created_timestamp_column == other.created_timestamp_column
@@ -122,8 +110,8 @@ def __eq__(self, other):
122110
)
123111

124112
@property
125-
def table_ref(self):
126-
return self.bigquery_options.table_ref
113+
def table(self):
114+
return self.bigquery_options.table
127115

128116
@property
129117
def query(self):
@@ -137,7 +125,7 @@ def from_proto(data_source: DataSourceProto):
137125
return BigQuerySource(
138126
name=data_source.name,
139127
field_mapping=dict(data_source.field_mapping),
140-
table_ref=data_source.bigquery_options.table_ref,
128+
table=data_source.bigquery_options.table,
141129
timestamp_field=data_source.timestamp_field,
142130
created_timestamp_column=data_source.created_timestamp_column,
143131
query=data_source.bigquery_options.query,
@@ -169,14 +157,14 @@ def validate(self, config: RepoConfig):
169157

170158
client = bigquery.Client()
171159
try:
172-
client.get_table(self.table_ref)
160+
client.get_table(self.table)
173161
except NotFound:
174-
raise DataSourceNotFoundException(self.table_ref)
162+
raise DataSourceNotFoundException(self.table)
175163

176164
def get_table_query_string(self) -> str:
177165
"""Returns a string that can directly be used to reference this table in SQL"""
178-
if self.table_ref:
179-
return f"`{self.table_ref}`"
166+
if self.table:
167+
return f"`{self.table}`"
180168
else:
181169
return f"({self.query})"
182170

@@ -190,8 +178,8 @@ def get_table_column_names_and_types(
190178
from google.cloud import bigquery
191179

192180
client = bigquery.Client()
193-
if self.table_ref is not None:
194-
schema = client.get_table(self.table_ref).schema
181+
if self.table is not None:
182+
schema = client.get_table(self.table).schema
195183
if not isinstance(schema[0], bigquery.schema.SchemaField):
196184
raise TypeError("Could not parse BigQuery table schema.")
197185
else:
@@ -215,9 +203,9 @@ class BigQueryOptions:
215203
"""
216204

217205
def __init__(
218-
self, table_ref: Optional[str], query: Optional[str],
206+
self, table: Optional[str], query: Optional[str],
219207
):
220-
self._table_ref = table_ref
208+
self._table = table
221209
self._query = query
222210

223211
@property
@@ -235,18 +223,18 @@ def query(self, query):
235223
self._query = query
236224

237225
@property
238-
def table_ref(self):
226+
def table(self):
239227
"""
240228
Returns the table ref of this BQ table
241229
"""
242-
return self._table_ref
230+
return self._table
243231

244-
@table_ref.setter
245-
def table_ref(self, table_ref):
232+
@table.setter
233+
def table(self, table):
246234
"""
247235
Sets the table ref of this BQ table
248236
"""
249-
self._table_ref = table_ref
237+
self._table = table
250238

251239
@classmethod
252240
def from_proto(cls, bigquery_options_proto: DataSourceProto.BigQueryOptions):
@@ -261,8 +249,7 @@ def from_proto(cls, bigquery_options_proto: DataSourceProto.BigQueryOptions):
261249
"""
262250

263251
bigquery_options = cls(
264-
table_ref=bigquery_options_proto.table_ref,
265-
query=bigquery_options_proto.query,
252+
table=bigquery_options_proto.table, query=bigquery_options_proto.query,
266253
)
267254

268255
return bigquery_options
@@ -276,7 +263,7 @@ def to_proto(self) -> DataSourceProto.BigQueryOptions:
276263
"""
277264

278265
bigquery_options_proto = DataSourceProto.BigQueryOptions(
279-
table_ref=self.table_ref, query=self.query,
266+
table=self.table, query=self.query,
280267
)
281268

282269
return bigquery_options_proto
@@ -287,15 +274,13 @@ class SavedDatasetBigQueryStorage(SavedDatasetStorage):
287274

288275
bigquery_options: BigQueryOptions
289276

290-
def __init__(self, table_ref: str):
291-
self.bigquery_options = BigQueryOptions(table_ref=table_ref, query=None)
277+
def __init__(self, table: str):
278+
self.bigquery_options = BigQueryOptions(table=table, query=None)
292279

293280
@staticmethod
294281
def from_proto(storage_proto: SavedDatasetStorageProto) -> SavedDatasetStorage:
295282
return SavedDatasetBigQueryStorage(
296-
table_ref=BigQueryOptions.from_proto(
297-
storage_proto.bigquery_storage
298-
).table_ref
283+
table=BigQueryOptions.from_proto(storage_proto.bigquery_storage).table
299284
)
300285

301286
def to_proto(self) -> SavedDatasetStorageProto:
@@ -304,4 +289,4 @@ def to_proto(self) -> SavedDatasetStorageProto:
304289
)
305290

306291
def to_data_source(self) -> DataSource:
307-
return BigQuerySource(table_ref=self.bigquery_options.table_ref)
292+
return BigQuerySource(table=self.bigquery_options.table)

sdk/python/feast/templates/gcp/driver_repo.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
# datasets or materializing features into an online store.
2121
driver_stats_source = BigQuerySource(
2222
# The BigQuery table where features can be found
23-
table_ref="feast-oss.demo_data.driver_hourly_stats_2",
23+
table="feast-oss.demo_data.driver_hourly_stats_2",
2424
# The event timestamp is used for point-in-time joins and for ensuring only
2525
# features within the TTL are returned
2626
timestamp_field="event_timestamp",

sdk/python/tests/example_repos/example_feature_repo_1.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,12 @@
3030

3131
customer_profile_source = BigQuerySource(
3232
name="customer_profile_source",
33-
table_ref="feast-oss.public.customers",
33+
table="feast-oss.public.customers",
3434
timestamp_field="event_timestamp",
3535
)
3636

3737
customer_driver_combined_source = BigQuerySource(
38-
table_ref="feast-oss.public.customer_driver", timestamp_field="event_timestamp",
38+
table="feast-oss.public.customer_driver", timestamp_field="event_timestamp",
3939
)
4040

4141
driver_locations_push_source = PushSource(

sdk/python/tests/integration/feature_repos/universal/data_sources/bigquery.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ def create_data_source(
7474
self.tables.append(destination_name)
7575

7676
return BigQuerySource(
77-
table_ref=destination_name,
77+
table=destination_name,
7878
timestamp_field=timestamp_field,
7979
created_timestamp_column=created_timestamp_column,
8080
field_mapping=field_mapping or {"ts_1": "ts"},
@@ -84,7 +84,7 @@ def create_saved_dataset_destination(self) -> SavedDatasetBigQueryStorage:
8484
table = self.get_prefixed_table_name(
8585
f"persisted_{str(uuid.uuid4()).replace('-', '_')}"
8686
)
87-
return SavedDatasetBigQueryStorage(table_ref=table)
87+
return SavedDatasetBigQueryStorage(table=table)
8888

8989
def get_prefixed_table_name(self, suffix: str) -> str:
9090
return f"{self.client.project}.{self.project_name}.{suffix}"

sdk/python/tests/integration/registration/test_feature_store.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
from tests.utils.data_source_utils import (
3434
prep_file_source,
3535
simple_bq_source_using_query_arg,
36-
simple_bq_source_using_table_ref_arg,
36+
simple_bq_source_using_table_arg,
3737
)
3838

3939

@@ -234,7 +234,7 @@ def test_feature_view_inference_success(test_feature_store, dataframe_source):
234234
entities=["id"],
235235
ttl=timedelta(minutes=5),
236236
online=True,
237-
batch_source=simple_bq_source_using_table_ref_arg(dataframe_source, "ts_1"),
237+
batch_source=simple_bq_source_using_table_arg(dataframe_source, "ts_1"),
238238
tags={},
239239
)
240240

@@ -255,7 +255,7 @@ def test_feature_view_inference_success(test_feature_store, dataframe_source):
255255
actual_file_source = {
256256
(feature.name, feature.dtype) for feature in feature_view_1.features
257257
}
258-
actual_bq_using_table_ref_arg_source = {
258+
actual_bq_using_table_arg_source = {
259259
(feature.name, feature.dtype) for feature in feature_view_2.features
260260
}
261261
actual_bq_using_query_arg_source = {
@@ -270,7 +270,7 @@ def test_feature_view_inference_success(test_feature_store, dataframe_source):
270270
assert (
271271
expected
272272
== actual_file_source
273-
== actual_bq_using_table_ref_arg_source
273+
== actual_bq_using_table_arg_source
274274
== actual_bq_using_query_arg_source
275275
)
276276

sdk/python/tests/integration/registration/test_inference.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
from tests.utils.data_source_utils import (
3232
prep_file_source,
3333
simple_bq_source_using_query_arg,
34-
simple_bq_source_using_table_ref_arg,
34+
simple_bq_source_using_table_arg,
3535
)
3636

3737

@@ -120,7 +120,7 @@ def test_update_file_data_source_with_inferred_event_timestamp_col(simple_datase
120120
with prep_file_source(df=simple_dataset_1) as file_source:
121121
data_sources = [
122122
file_source,
123-
simple_bq_source_using_table_ref_arg(simple_dataset_1),
123+
simple_bq_source_using_table_arg(simple_dataset_1),
124124
simple_bq_source_using_query_arg(simple_dataset_1),
125125
]
126126
update_data_sources_with_inferred_event_timestamp_col(

sdk/python/tests/integration/scaffolding/test_partial_apply.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ def test_partial() -> None:
2020
) as store:
2121

2222
driver_locations_source = BigQuerySource(
23-
table_ref="feast-oss.public.drivers",
23+
table="feast-oss.public.drivers",
2424
timestamp_field="event_timestamp",
2525
created_timestamp_column="created_timestamp",
2626
)

0 commit comments

Comments
 (0)