Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FSTORE-1548] BigQuery connector is using the wrong project when quer… #1383

Merged
merged 2 commits into from
Sep 24, 2024
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
3 changes: 1 addition & 2 deletions python/hsfs/storage_connector.py
Original file line number Diff line number Diff line change
Expand Up @@ -1574,9 +1574,8 @@ def connector_options(self) -> Dict[str, Any]:
"""Return options to be passed to an external BigQuery connector library"""
props = {
"key_path": self._key_path,
"project_id": self._query_project,
"project_id": self._parent_project,
"dataset_id": self._dataset,
"parent_project": self._parent_project,
}
return props

Expand Down
28 changes: 27 additions & 1 deletion python/tests/fixtures/storage_connector_fixtures.json
Original file line number Diff line number Diff line change
Expand Up @@ -495,7 +495,7 @@
},
"headers": null
},
"get_big_query": {
"get_big_query_table": {
"response": {
"type": "featurestoreBigQueryConnectorDTO",
"description": "BigQuery connector description",
Expand All @@ -508,6 +508,32 @@
"dataset": "test_dataset",
"query_table": "test_query_table",
"query_project": "test_query_project",
"arguments": [{"name": "test_name", "value": "test_value"}]
},
"method": "GET",
"path_params": [
"project",
"119",
"featurestores",
67,
"storageconnectors",
"test_big_query"
],
"query_params": {
"temporaryCredentials": true
},
"headers": null
},
"get_big_query_query": {
"response": {
"type": "featurestoreBigQueryConnectorDTO",
"description": "BigQuery connector description",
"featurestoreId": 67,
"id": 1,
"name": "test_big_query",
"storageConnectorType": "BIGQUERY",
"key_path": "test_key_path",
"parent_project": "test_parent_project",
"materialization_dataset": "test_materialization_dataset",
"arguments": [{"name": "test_name", "value": "test_value"}]
},
Expand Down
21 changes: 15 additions & 6 deletions python/tests/test_storage_connector.py
Original file line number Diff line number Diff line change
Expand Up @@ -800,7 +800,7 @@ def test_default_path(self, mocker):
class TestBigQueryConnector:
def test_from_response_json(self, backend_fixtures):
# Arrange
json = backend_fixtures["storage_connector"]["get_big_query"]["response"]
json = backend_fixtures["storage_connector"]["get_big_query_table"]["response"]

# Act
sc = storage_connector.StorageConnector.from_response_json(json)
Expand All @@ -815,7 +815,6 @@ def test_from_response_json(self, backend_fixtures):
assert sc.dataset == "test_dataset"
assert sc.query_table == "test_query_table"
assert sc.query_project == "test_query_project"
assert sc.materialization_dataset == "test_materialization_dataset"
assert sc.arguments == {"test_name": "test_value"}

def test_from_response_json_basic_info(self, backend_fixtures):
Expand Down Expand Up @@ -850,7 +849,7 @@ def test_credentials_base64_encoded(self, mocker, backend_fixtures, tmp_path):
credentialsFile = tmp_path / "bigquery.json"
credentialsFile.write_text(credentials)

json = backend_fixtures["storage_connector"]["get_big_query"]["response"]
json = backend_fixtures["storage_connector"]["get_big_query_table"]["response"]
if isinstance(tmp_path, WindowsPath):
json["key_path"] = "file:///" + str(credentialsFile.resolve()).replace(
"\\", "/"
Expand Down Expand Up @@ -891,9 +890,7 @@ def test_query_validation(self, mocker, backend_fixtures, tmp_path):
credentials = '{"type": "service_account", "project_id": "test"}'
credentialsFile = tmp_path / "bigquery.json"
credentialsFile.write_text(credentials)
json = backend_fixtures["storage_connector"]["get_big_query"]["response"]
# remove property for query
json.pop("materialization_dataset")
json = backend_fixtures["storage_connector"]["get_big_query_table"]["response"]
if isinstance(tmp_path, WindowsPath):
json["key_path"] = "file:///" + str(credentialsFile.resolve()).replace(
"\\", "/"
Expand All @@ -905,3 +902,15 @@ def test_query_validation(self, mocker, backend_fixtures, tmp_path):
# Assert
with pytest.raises(ValueError):
sc.read(query="select * from")

def test_connector_options(self, backend_fixtures):
# Arrange
engine.set_instance("python", python.Engine())
json = backend_fixtures["storage_connector"]["get_big_query_query"]["response"]
sc = storage_connector.StorageConnector.from_response_json(json)

# Act
options = sc.connector_options()

# Assert
assert options["project_id"] == "test_parent_project"
Loading