-
Notifications
You must be signed in to change notification settings - Fork 161
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
eb908d7
commit e2620c6
Showing
8 changed files
with
205 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
kind: Features | ||
body: add dataproc serverless config to profile | ||
time: 2023-03-03T13:25:09.02695-08:00 | ||
custom: | ||
Author: colin-rogers-dbt torkjel | ||
Issue: "530" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{% macro bigquery__resolve_model_name(input_model_name) -%} | ||
{{ input_model_name | string | replace('`', '') | replace('"', '\"') }} | ||
{%- endmacro -%} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -108,6 +108,43 @@ def setUp(self): | |
"threads": 1, | ||
"location": "Solar Station", | ||
}, | ||
'dataproc-serverless-configured' : { | ||
'type': 'bigquery', | ||
'method': 'oauth', | ||
'schema': 'dummy_schema', | ||
'threads': 1, | ||
'gcs_bucket': 'dummy-bucket', | ||
'dataproc_region': 'europe-west1', | ||
'submission_method': 'serverless', | ||
'dataproc_batch': { | ||
'environment_config' : { | ||
'execution_config' : { | ||
'service_account': '[email protected]', | ||
'subnetwork_uri': 'dataproc', | ||
'network_tags': [ "foo", "bar" ] | ||
} | ||
}, | ||
'labels': { | ||
'dbt': 'rocks', | ||
'number': '1' | ||
}, | ||
'runtime_config': { | ||
'properties': { | ||
'spark.executor.instances': '4', | ||
'spark.driver.memory': '1g' | ||
} | ||
} | ||
} | ||
}, | ||
'dataproc-serverless-default' : { | ||
'type': 'bigquery', | ||
'method': 'oauth', | ||
'schema': 'dummy_schema', | ||
'threads': 1, | ||
'gcs_bucket': 'dummy-bucket', | ||
'dataproc_region': 'europe-west1', | ||
'submission_method': 'serverless' | ||
} | ||
}, | ||
"target": "oauth", | ||
} | ||
|
@@ -184,6 +221,25 @@ def test_acquire_connection_oauth_validations(self, mock_open_connection): | |
connection.handle | ||
mock_open_connection.assert_called_once() | ||
|
||
@patch('dbt.adapters.bigquery.connections.get_bigquery_defaults', return_value=('credentials', 'project_id')) | ||
@patch('dbt.adapters.bigquery.BigQueryConnectionManager.open', return_value=_bq_conn()) | ||
def test_acquire_connection_dataproc_serverless(self, mock_open_connection, mock_get_bigquery_defaults): | ||
adapter = self.get_adapter('dataproc-serverless-configured') | ||
mock_get_bigquery_defaults.assert_called_once() | ||
try: | ||
connection = adapter.acquire_connection('dummy') | ||
self.assertEqual(connection.type, 'bigquery') | ||
|
||
except dbt.exceptions.ValidationException as e: | ||
self.fail('got ValidationException: {}'.format(str(e))) | ||
|
||
except BaseException as e: | ||
raise | ||
|
||
mock_open_connection.assert_not_called() | ||
connection.handle | ||
mock_open_connection.assert_called_once() | ||
|
||
@patch('dbt.adapters.bigquery.BigQueryConnectionManager.open', return_value=_bq_conn()) | ||
def test_acquire_connection_service_account_validations(self, mock_open_connection): | ||
adapter = self.get_adapter('service_account') | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
from unittest.mock import patch | ||
|
||
from dbt.adapters.bigquery.python_submissions import ServerlessDataProcHelper | ||
from google.cloud import dataproc_v1 | ||
|
||
from .test_bigquery_adapter import BaseTestBigQueryAdapter | ||
|
||
# Test application of dataproc_batch configuration to a | ||
# google.cloud.dataproc_v1.Batch object. | ||
# This reuses the machinery from BaseTestBigQueryAdapter to get hold of the | ||
# parsed credentials | ||
class TestConfigureDataprocBatch(BaseTestBigQueryAdapter): | ||
|
||
@patch('dbt.adapters.bigquery.connections.get_bigquery_defaults', return_value=('credentials', 'project_id')) | ||
def test_update_dataproc_serverless_batch(self, mock_get_bigquery_defaults): | ||
adapter = self.get_adapter('dataproc-serverless-configured') | ||
mock_get_bigquery_defaults.assert_called_once() | ||
|
||
credentials = adapter.acquire_connection('dummy').credentials | ||
self.assertIsNotNone(credentials) | ||
|
||
batchConfig = credentials.dataproc_batch | ||
self.assertIsNotNone(batchConfig) | ||
|
||
raw_batch_config = self.raw_profile['outputs']['dataproc-serverless-configured']['dataproc_batch'] | ||
raw_environment_config = raw_batch_config['environment_config'] | ||
raw_execution_config = raw_environment_config['execution_config'] | ||
raw_labels: dict[str, any] = raw_batch_config['labels'] | ||
raw_rt_config = raw_batch_config['runtime_config'] | ||
|
||
raw_batch_config = self.raw_profile['outputs']['dataproc-serverless-configured']['dataproc_batch'] | ||
|
||
batch = dataproc_v1.Batch() | ||
|
||
ServerlessDataProcHelper._update_batch_from_config(raw_batch_config, batch) | ||
|
||
# google's protobuf types expose maps as dict[str, str] | ||
to_str_values = lambda d: dict([(k, str(v)) for (k, v) in d.items()]) | ||
|
||
self.assertEqual(batch.environment_config.execution_config.service_account, raw_execution_config['service_account']) | ||
self.assertFalse(batch.environment_config.execution_config.network_uri) | ||
self.assertEqual(batch.environment_config.execution_config.subnetwork_uri, raw_execution_config['subnetwork_uri']) | ||
self.assertEqual(batch.environment_config.execution_config.network_tags, raw_execution_config['network_tags']) | ||
self.assertEqual(batch.labels, to_str_values(raw_labels)) | ||
self.assertEqual(batch.runtime_config.properties, to_str_values(raw_rt_config['properties'])) | ||
|
||
|
||
@patch('dbt.adapters.bigquery.connections.get_bigquery_defaults', return_value=('credentials', 'project_id')) | ||
def test_default_dataproc_serverless_batch(self, mock_get_bigquery_defaults): | ||
adapter = self.get_adapter('dataproc-serverless-default') | ||
mock_get_bigquery_defaults.assert_called_once() | ||
|
||
credentials = adapter.acquire_connection('dummy').credentials | ||
self.assertIsNotNone(credentials) | ||
|
||
batchConfig = credentials.dataproc_batch | ||
self.assertIsNone(batchConfig) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters