def from_dict(value):
     schema = value.get('schema', None)
     if schema:
         schema = tuple(BigQuerySchemaField.from_dict(s) for s in schema)
     expires = value.get('expires', None)
     if expires:
         expires = parse_expires(expires)
     return BigQueryTable(
         table_id=value.get('table_id', None),
         friendly_name=value.get('friendly_name', None),
         description=value.get('description', None),
         expires=expires,
         partitioning_type=value.get('partitioning_type', None),
         view_use_legacy_sql=value.get('view_use_legacy_sql', None),
         view_query=value.get('view_query', None),
         schema=schema,
         labels=value.get('labels', None),
     )
Ejemplo n.º 2
0
    def test_from_dict(self):
        expected_schema_field1 = BigQuerySchemaField(
            name='test',
            field_type='STRING',
            mode='NULLABLE',
            description='test_description')
        actual_schema_field1_1 = BigQuerySchemaField.from_dict({
            'name':
            'test',
            'field_type':
            'STRING',
            'mode':
            'NULLABLE',
            'description':
            'test_description'
        })
        self.assertEqual(expected_schema_field1, actual_schema_field1_1)
        actual_schema_field1_2 = BigQuerySchemaField.from_dict({
            'name':
            'test',
            'field_type':
            'INTEGER',
            'mode':
            'REQUIRED',
            'description':
            'foo_bar'
        })
        self.assertNotEqual(expected_schema_field1, actual_schema_field1_2)

        expected_schema_field2 = BigQuerySchemaField(
            name='test',
            field_type='RECORD',
            mode='NULLABLE',
            description='test_description',
            fields=(expected_schema_field1, ))
        actual_schema_field2_1 = BigQuerySchemaField.from_dict({
            'name':
            'test',
            'field_type':
            'RECORD',
            'mode':
            'NULLABLE',
            'description':
            'test_description',
            'fields': [{
                'name': 'test',
                'field_type': 'STRING',
                'mode': 'NULLABLE',
                'description': 'test_description'
            }]
        })
        self.assertEqual(expected_schema_field2, actual_schema_field2_1)
        actual_schema_field2_2 = BigQuerySchemaField.from_dict({
            'name':
            'test',
            'field_type':
            'RECORD',
            'mode':
            'NULLABLE',
            'description':
            'test_description',
            'fields': [{
                'name': 'test',
                'field_type': 'INTEGER',
                'mode': 'REQUIRED',
                'description': 'foo_bar'
            }]
        })
        self.assertNotEqual(expected_schema_field2, actual_schema_field2_2)