コード例 #1
0
 def _copy_table(self, write_disposition):
     self.connections.table_ref = self._table_ref
     source = BigQueryRelation.create(database='project',
                                      schema='dataset',
                                      identifier='table1')
     destination = BigQueryRelation.create(database='project',
                                           schema='dataset',
                                           identifier='table2')
     self.connections.copy_bq_table(source, destination, write_disposition)
コード例 #2
0
    def test_replace(self):

        kwargs = {
            'type': None,
            'path': {
                'database': 'test-project',
                'schema': 'test_schema',
                'identifier': 'my_view'
            },
            # test for #2188
            'quote_policy': {
                'database': False
            },
            'include_policy': {
                'database': True,
                'schema': True,
                'identifier': True,
            }
        }
        BigQueryRelation.validate(kwargs)
        relation = BigQueryRelation.from_dict(kwargs)
        info_schema = relation.information_schema()

        tables_schema = info_schema.replace(
            information_schema_view='__TABLES__')
        assert tables_schema.information_schema_view == '__TABLES__'
        assert tables_schema.include_policy.schema is True
        assert tables_schema.include_policy.identifier is False
        assert tables_schema.include_policy.database is True
        assert tables_schema.quote_policy.schema is True
        assert tables_schema.quote_policy.identifier is False
        assert tables_schema.quote_policy.database is False

        schemata_schema = info_schema.replace(
            information_schema_view='SCHEMATA')
        assert schemata_schema.information_schema_view == 'SCHEMATA'
        assert schemata_schema.include_policy.schema is False
        assert schemata_schema.include_policy.identifier is True
        assert schemata_schema.include_policy.database is True
        assert schemata_schema.quote_policy.schema is True
        assert schemata_schema.quote_policy.identifier is False
        assert schemata_schema.quote_policy.database is False

        other_schema = info_schema.replace(
            information_schema_view='SOMETHING_ELSE')
        assert other_schema.information_schema_view == 'SOMETHING_ELSE'
        assert other_schema.include_policy.schema is True
        assert other_schema.include_policy.identifier is True
        assert other_schema.include_policy.database is True
        assert other_schema.quote_policy.schema is True
        assert other_schema.quote_policy.identifier is False
        assert other_schema.quote_policy.database is False
コード例 #3
0
 def test_view_temp_relation(self):
     kwargs = {
         'type': None,
         'path': {
             'database': 'test-project',
             'schema': 'test_schema',
             'identifier': 'my_view'
         },
         'quote_policy': {
             'identifier': False
         }
     }
     BigQueryRelation.from_dict(kwargs)
コード例 #4
0
 def test_external_source_relation(self):
     kwargs = {
         'type': 'external',
         'path': {
             'database': 'test-project',
             'schema': 'test_schema',
             'identifier': 'sheet'
         },
         'quote_policy': {
             'identifier': True,
             'schema': True
         }
     }
     BigQueryRelation.from_dict(kwargs)
コード例 #5
0
 def test_table_relation(self):
     kwargs = {
         'type': 'table',
         'path': {
             'database': 'test-project',
             'schema': 'test_schema',
             'identifier': 'generic_table'
         },
         'quote_policy': {
             'identifier': True,
             'schema': True
         }
     }
     BigQueryRelation.from_dict(kwargs)
コード例 #6
0
 def test_view_relation(self):
     kwargs = {
         'type': 'view',
         'path': {
             'database': 'test-project',
             'schema': 'test_schema',
             'identifier': 'my_view'
         },
         'quote_policy': {
             'identifier': True,
             'schema': True
         }
     }
     BigQueryRelation.validate(kwargs)
コード例 #7
0
 def test_invalid_relation(self):
     kwargs = {
         'type': 'invalid-type',
         'path': {
             'database': 'test-project',
             'schema': 'test_schema',
             'identifier': 'my_invalid_id'
         },
         'quote_policy': {
             'identifier': False,
             'schema': True
         }
     }
     with self.assertRaises(hologram.ValidationError):
         BigQueryRelation.from_dict(kwargs)
コード例 #8
0
 def test_invalid_relation(self):
     kwargs = {
         'type': 'invalid-type',
         'path': {
             'database': 'test-project',
             'schema': 'test_schema',
             'identifier': 'my_invalid_id'
         },
         'table_name': 'my_invalid_id',
         'quote_policy': {
             'identifier': False,
             'schema': True
         }
     }
     with self.assertRaises(dbt.exceptions.ValidationException):
         BigQueryRelation(**kwargs)
コード例 #9
0
 def test_drop_schema(self, mock_check_schema):
     mock_check_schema.return_value = True
     relation = BigQueryRelation.create(database='db', schema='schema')
     self.adapter.drop_schema(relation)
     self.mock_connection_manager.drop_dataset.assert_called_once_with(
         'db', 'schema')
コード例 #10
0
 def test_create_schema(self):
     relation = BigQueryRelation.create(database='db', schema='schema')
     self.adapter.create_schema(relation)
     self.mock_connection_manager.create_dataset.assert_called_once_with(
         'db', 'schema')
コード例 #11
0
def _stub_relation(*args, **kwargs):
    return BigQueryRelation.create(database='',
                                   schema='',
                                   identifier='',
                                   quote_policy={},
                                   type=BigQueryRelation.Table)