-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2060 from tseaver/bigquery-partition-tidy
Slightly more explicit coverage for partition-related methods.
- Loading branch information
Showing
11 changed files
with
268 additions
and
173 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,7 @@ | ||
Schemas | ||
~~~~~~~ | ||
|
||
.. automodule:: gcloud.bigquery.schema | ||
:members: | ||
:show-inheritance: | ||
|
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 |
---|---|---|
|
@@ -54,6 +54,7 @@ | |
bigquery-job | ||
bigquery-table | ||
bigquery-query | ||
bigquery-schema | ||
|
||
.. toctree:: | ||
:maxdepth: 0 | ||
|
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,52 @@ | ||
# Copyright 2015 Google Inc. All rights reserved. | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
"""Scheamas for BigQuery tables / queries.""" | ||
|
||
|
||
class SchemaField(object): | ||
"""Describe a single field within a table schema. | ||
:type name: str | ||
:param name: the name of the field | ||
:type field_type: str | ||
:param field_type: the type of the field (one of 'STRING', 'INTEGER', | ||
'FLOAT', 'BOOLEAN', 'TIMESTAMP' or 'RECORD') | ||
:type mode: str | ||
:param mode: the type of the field (one of 'NULLABLE', 'REQUIRED', | ||
or 'REPEATED') | ||
:type description: str | ||
:param description: optional description for the field | ||
:type fields: list of :class:`SchemaField`, or None | ||
:param fields: subfields (requires ``field_type`` of 'RECORD'). | ||
""" | ||
def __init__(self, name, field_type, mode='NULLABLE', description=None, | ||
fields=None): | ||
self.name = name | ||
self.field_type = field_type | ||
self.mode = mode | ||
self.description = description | ||
self.fields = fields | ||
|
||
def __eq__(self, other): | ||
return ( | ||
self.name == other.name and | ||
self.field_type.lower() == other.field_type.lower() and | ||
self.mode == other.mode and | ||
self.description == other.description and | ||
self.fields == other.fields) |
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
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,110 @@ | ||
# Copyright 2015 Google Inc. All rights reserved. | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
import unittest | ||
|
||
|
||
class TestSchemaField(unittest.TestCase): | ||
|
||
def _getTargetClass(self): | ||
from gcloud.bigquery.schema import SchemaField | ||
return SchemaField | ||
|
||
def _makeOne(self, *args, **kw): | ||
return self._getTargetClass()(*args, **kw) | ||
|
||
def test_ctor_defaults(self): | ||
field = self._makeOne('test', 'STRING') | ||
self.assertEqual(field.name, 'test') | ||
self.assertEqual(field.field_type, 'STRING') | ||
self.assertEqual(field.mode, 'NULLABLE') | ||
self.assertEqual(field.description, None) | ||
self.assertEqual(field.fields, None) | ||
|
||
def test_ctor_explicit(self): | ||
field = self._makeOne('test', 'STRING', mode='REQUIRED', | ||
description='Testing') | ||
self.assertEqual(field.name, 'test') | ||
self.assertEqual(field.field_type, 'STRING') | ||
self.assertEqual(field.mode, 'REQUIRED') | ||
self.assertEqual(field.description, 'Testing') | ||
self.assertEqual(field.fields, None) | ||
|
||
def test_ctor_subfields(self): | ||
field = self._makeOne('phone_number', 'RECORD', | ||
fields=[self._makeOne('area_code', 'STRING'), | ||
self._makeOne('local_number', 'STRING')]) | ||
self.assertEqual(field.name, 'phone_number') | ||
self.assertEqual(field.field_type, 'RECORD') | ||
self.assertEqual(field.mode, 'NULLABLE') | ||
self.assertEqual(field.description, None) | ||
self.assertEqual(len(field.fields), 2) | ||
self.assertEqual(field.fields[0].name, 'area_code') | ||
self.assertEqual(field.fields[0].field_type, 'STRING') | ||
self.assertEqual(field.fields[0].mode, 'NULLABLE') | ||
self.assertEqual(field.fields[0].description, None) | ||
self.assertEqual(field.fields[0].fields, None) | ||
self.assertEqual(field.fields[1].name, 'local_number') | ||
self.assertEqual(field.fields[1].field_type, 'STRING') | ||
self.assertEqual(field.fields[1].mode, 'NULLABLE') | ||
self.assertEqual(field.fields[1].description, None) | ||
self.assertEqual(field.fields[1].fields, None) | ||
|
||
def test___eq___name_mismatch(self): | ||
field = self._makeOne('test', 'STRING') | ||
other = self._makeOne('other', 'STRING') | ||
self.assertNotEqual(field, other) | ||
|
||
def test___eq___field_type_mismatch(self): | ||
field = self._makeOne('test', 'STRING') | ||
other = self._makeOne('test', 'INTEGER') | ||
self.assertNotEqual(field, other) | ||
|
||
def test___eq___mode_mismatch(self): | ||
field = self._makeOne('test', 'STRING', mode='REQUIRED') | ||
other = self._makeOne('test', 'STRING', mode='NULLABLE') | ||
self.assertNotEqual(field, other) | ||
|
||
def test___eq___description_mismatch(self): | ||
field = self._makeOne('test', 'STRING', description='Testing') | ||
other = self._makeOne('test', 'STRING', description='Other') | ||
self.assertNotEqual(field, other) | ||
|
||
def test___eq___fields_mismatch(self): | ||
sub1 = self._makeOne('sub1', 'STRING') | ||
sub2 = self._makeOne('sub2', 'STRING') | ||
field = self._makeOne('test', 'RECORD', fields=[sub1]) | ||
other = self._makeOne('test', 'RECORD', fields=[sub2]) | ||
self.assertNotEqual(field, other) | ||
|
||
def test___eq___hit(self): | ||
field = self._makeOne('test', 'STRING', mode='REQUIRED', | ||
description='Testing') | ||
other = self._makeOne('test', 'STRING', mode='REQUIRED', | ||
description='Testing') | ||
self.assertEqual(field, other) | ||
|
||
def test___eq___hit_case_diff_on_type(self): | ||
field = self._makeOne('test', 'STRING', mode='REQUIRED', | ||
description='Testing') | ||
other = self._makeOne('test', 'string', mode='REQUIRED', | ||
description='Testing') | ||
self.assertEqual(field, other) | ||
|
||
def test___eq___hit_w_fields(self): | ||
sub1 = self._makeOne('sub1', 'STRING') | ||
sub2 = self._makeOne('sub2', 'STRING') | ||
field = self._makeOne('test', 'RECORD', fields=[sub1, sub2]) | ||
other = self._makeOne('test', 'RECORD', fields=[sub1, sub2]) | ||
self.assertEqual(field, other) |
Oops, something went wrong.