def get_adapter(self, profile): project = self.project_cfg.copy() project['profile'] = profile config = config_from_parts_or_dicts( project=project, profile=self.raw_profile, ) return BigQueryAdapter(config)
def get_adapter(self, target): project = self.project_cfg.copy() profile = self.raw_profile.copy() profile['target'] = target config = config_from_parts_or_dicts( project=project, profile=profile, ) return BigQueryAdapter(config)
def test_convert_date_type(self): rows = [ ['', '2019-01-01', '2019-01-04'], ['', '2019-01-02', '2019-01-04'], ['', '2019-01-03', '2019-01-04'], ] agate_table = self._make_table_of(rows, agate.Date) expected = ['date', 'date', 'date'] for col_idx, expect in enumerate(expected): assert BigQueryAdapter.convert_date_type(agate_table, col_idx) == expect
def test_convert_boolean_type(self): rows = [ ['', 'false', 'true'], ['', 'false', 'false'], ['', 'false', 'true'], ] agate_table = self._make_table_of(rows, agate.Boolean) expected = ['bool', 'bool', 'bool'] for col_idx, expect in enumerate(expected): assert BigQueryAdapter.convert_boolean_type(agate_table, col_idx) == expect
def test_convert_number_type(self): rows = [ ['', '23.98', '-1'], ['', '12.78', '-2'], ['', '79.41', '-3'], ] agate_table = self._make_table_of(rows, agate.Number) expected = ['int64', 'float64', 'int64'] for col_idx, expect in enumerate(expected): assert BigQueryAdapter.convert_number_type(agate_table, col_idx) == expect
def test_convert_text_type(self): rows = [ ['', 'a1', 'stringval1'], ['', 'a2', 'stringvalasdfasdfasdfa'], ['', 'a3', 'stringval3'], ] agate_table = self._make_table_of(rows, agate.Text) expected = ['string', 'string', 'string'] for col_idx, expect in enumerate(expected): assert BigQueryAdapter.convert_text_type(agate_table, col_idx) == expect
def test_convert_datetime_type(self): rows = [ ['', '20190101T01:01:01Z', '2019-01-01 01:01:01'], ['', '20190102T01:01:01Z', '2019-01-01 01:01:01'], ['', '20190103T01:01:01Z', '2019-01-01 01:01:01'], ] agate_table = self._make_table_of( rows, [agate.DateTime, agate_helper.ISODateTime, agate.DateTime]) expected = ['datetime', 'datetime', 'datetime'] for col_idx, expect in enumerate(expected): assert BigQueryAdapter.convert_datetime_type(agate_table, col_idx) == expect
def test_convert_time_type(self): # dbt's default type testers actually don't have a TimeDelta at all. agate.TimeDelta rows = [ ['', '120s', '10s'], ['', '3m', '11s'], ['', '1h', '12s'], ] agate_table = self._make_table_of(rows, agate.TimeDelta) expected = ['time', 'time', 'time'] for col_idx, expect in enumerate(expected): assert BigQueryAdapter.convert_time_type(agate_table, col_idx) == expect
def test_acquire_connection_oauth_validations(self, mock_open_connection): try: connection = BigQueryAdapter.acquire_connection( self.oauth_profile, 'dummy') self.assertEquals(connection.get('type'), 'bigquery') except dbt.exceptions.ValidationException as e: self.fail('got ValidationException: {}'.format(str(e))) except BaseException as e: raise self.fail('validation failed with unknown exception: {}'.format( str(e))) mock_open_connection.assert_called_once()
def get_adapter(self, target): project = self.project_cfg.copy() profile = self.raw_profile.copy() profile['target'] = target config = config_from_parts_or_dicts( project=project, profile=profile, ) adapter = BigQueryAdapter(config) self.qh_patch = patch.object(adapter.connections.query_header, 'add') self.mock_query_header_add = self.qh_patch.start() self.mock_query_header_add.side_effect = lambda q: '/* dbt */\n{}'.format(q) inject_adapter(adapter) return adapter
def test__catalog_filter_table(self): manifest = MagicMock() manifest.get_used_schemas.return_value = [['a', 'B'], ['a', '1234']] column_names = [ 'table_name', 'table_database', 'table_schema', 'something' ] rows = [ ['foo', 'a', 'b', '1234'], # include ['foo', 'a', '1234', '1234'], # include, w/ table schema as str ['foo', 'c', 'B', '1234'], # skip ['1234', 'A', 'B', '1234'], # include, w/ table name as str ] table = agate.Table(rows, column_names, agate_helper.DEFAULT_TYPE_TESTER) result = BigQueryAdapter._catalog_filter_table(table, manifest) assert len(result) == 3 for row in result.rows: assert isinstance(row['table_schema'], str) assert isinstance(row['table_database'], str) assert isinstance(row['table_name'], str) assert isinstance(row['something'], decimal.Decimal)