Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Initial commit to catch nonexistent table
Signed-off-by: Cody Lin <codyjlin@yahoo.com>
Signed-off-by: Cody Lin <codyl@twitter.com>
  • Loading branch information
Cody Lin committed Jun 19, 2021
commit 1a91a330f8f33dfdb8637aecd30b16cb532cb901
18 changes: 18 additions & 0 deletions sdk/python/feast/data_source.py
Original file line number Diff line number Diff line change
Expand Up @@ -636,6 +636,13 @@ def __init__(
):
self._bigquery_options = BigQueryOptions(table_ref=table_ref, query=query)

if not self._table_exists():
raise NameError(
Comment thread
codyjlin marked this conversation as resolved.
Outdated
f"""
Unable to find table {table_ref} in BigQuery. Please check that table exists.
"""
)

super().__init__(
event_timestamp_column,
created_timestamp_column,
Expand Down Expand Up @@ -723,6 +730,17 @@ def get_table_column_names_and_types(self) -> Iterable[Tuple[str, str]]:

return name_type_pairs

def _table_exists(self) -> bool:
from google.api_core.exceptions import NotFound
from google.cloud import bigquery

client = bigquery.Client()
Comment thread
woop marked this conversation as resolved.
Outdated
try:
client.get_table(self.table_ref)
return True
except NotFound:
return False


class KafkaSource(DataSource):
def __init__(
Expand Down
20 changes: 20 additions & 0 deletions sdk/python/tests/test_data_source.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import pytest
from utils.data_source_utils import (
nonexistent_bq_source,
simple_bq_source_using_table_ref_arg,
)

from feast import Entity, ValueType
from feast.feature_view import FeatureView
from feast.inference import infer_entity_value_type_from_feature_views


@pytest.mark.integration
def test_existent_bq_source(simple_dataset_1):
existent_bq = simple_bq_source_using_table_ref_arg(simple_dataset_1)


@pytest.mark.integration
def test_nonexistent_bq_source():
with pytest.raises(NameError):
nonexistent_bq = nonexistent_bq_source()
6 changes: 6 additions & 0 deletions sdk/python/tests/utils/data_source_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,3 +54,9 @@ def simple_bq_source_using_query_arg(df, event_timestamp_column=None) -> BigQuer
query=f"SELECT * FROM {bq_source_using_table_ref.table_ref}",
event_timestamp_column=event_timestamp_column,
)


def nonexistent_bq_source() -> BigQuerySource:
client = bigquery.Client()
table_ref = "project.dataset.nonexistent_table"
return BigQuerySource(table_ref=table_ref, event_timestamp_column="")