Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BigQuery: Add is_nullable method to check for NULLABLE mode #3620

Merged
merged 2 commits into from
Jul 18, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion bigquery/google/cloud/bigquery/dbapi/cursor.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ def _set_description(self, schema):
internal_size=None,
precision=None,
scale=None,
null_ok=field.mode == 'NULLABLE')
null_ok=field.is_nullable)
for field in schema])

def _set_rowcount(self, query_results):
Expand Down
5 changes: 5 additions & 0 deletions bigquery/google/cloud/bigquery/schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,11 @@ def mode(self):
"""
return self._mode

@property
def is_nullable(self):
"""Check whether 'mode' is 'nullable'."""
return self._mode == 'NULLABLE'

@property
def description(self):
"""Optional[str]: Description for the field."""
Expand Down
10 changes: 10 additions & 0 deletions bigquery/tests/unit/test_schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,16 @@ def test_mode_property(self):
schema_field = self._make_one('again', 'FLOAT', mode=mode)
self.assertIs(schema_field.mode, mode)

def test_is_nullable(self):
mode = 'NULLABLE'
schema_field = self._make_one('test', 'FLOAT', mode=mode)
self.assertTrue(schema_field.is_nullable)

def test_is_not_nullable(self):
mode = 'REPEATED'
schema_field = self._make_one('test', 'FLOAT', mode=mode)
self.assertFalse(schema_field.is_nullable)

def test_description_property(self):
description = 'It holds some data.'
schema_field = self._make_one(
Expand Down