Skip to content

Commit

Permalink
Add is_nullable method to check for NULLABLE mode (googleapis#3620)
Browse files Browse the repository at this point in the history
Resolves: googleapis#3548
  • Loading branch information
sonlac authored and landrito committed Aug 21, 2017
1 parent 28031cb commit 70621da
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 1 deletion.
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

0 comments on commit 70621da

Please sign in to comment.