Skip to content

Commit eacf9fe

Browse files
committed
Removes client-side validation, simplifies some code
1 parent afcd892 commit eacf9fe

File tree

3 files changed

+9
-32
lines changed

3 files changed

+9
-32
lines changed

google/cloud/bigquery/enums.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -360,7 +360,7 @@ class DeterminismLevel:
360360
"""The UDF is not deterministic."""
361361

362362

363-
class RoundingMode(enum.Enum):
363+
class RoundingMode(str, enum.Enum):
364364
"""Rounding mode options that can be used when storing NUMERIC or BIGNUMERIC
365365
values.
366366
@@ -381,6 +381,9 @@ class RoundingMode(enum.Enum):
381381
* 2.5 => 2
382382
"""
383383

384-
ROUNDING_MODE_UNSPECIFIED = 0
385-
ROUND_HALF_AWAY_FROM_ZERO = 1
386-
ROUND_HALF_EVEN = 2
384+
def _generate_next_value_(name, start, count, last_values):
385+
return name
386+
387+
ROUNDING_MODE_UNSPECIFIED = enum.auto()
388+
ROUND_HALF_AWAY_FROM_ZERO = enum.auto()
389+
ROUND_HALF_EVEN = enum.auto()

google/cloud/bigquery/schema.py

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -241,21 +241,10 @@ def __init__(
241241
if isinstance(range_element_type, FieldElementType):
242242
self._properties["rangeElementType"] = range_element_type.to_api_repr()
243243
if rounding_mode is not None:
244-
if isinstance(rounding_mode, enums.RoundingMode):
245-
rounding_mode = rounding_mode.name
246244
self._properties["roundingMode"] = rounding_mode
247245
if isinstance(foreign_type_definition, str):
248246
self._properties["foreignTypeDefinition"] = foreign_type_definition
249247

250-
# The order of operations is important:
251-
# If field_type is FOREIGN, then foreign_type_definition must be set.
252-
if field_type != "FOREIGN":
253-
self._properties["type"] = field_type
254-
else:
255-
if self._properties.get("foreignTypeDefinition") is None:
256-
raise ValueError(
257-
"If the 'field_type' is 'FOREIGN', then 'foreign_type_definition' is required."
258-
)
259248
if fields: # Don't set the property if it's not set.
260249
self._properties["fields"] = [field.to_api_repr() for field in fields]
261250

tests/unit/test_schema.py

Lines changed: 2 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,6 @@ def test_constructor_defaults(self):
5555

5656
def test_constructor_explicit(self):
5757
FIELD_DEFAULT_VALUE_EXPRESSION = "This is the default value for this field"
58-
ROUNDINGMODE = enums.RoundingMode.ROUNDING_MODE_UNSPECIFIED
5958
field = self._make_one(
6059
"test",
6160
"STRING",
@@ -68,7 +67,7 @@ def test_constructor_explicit(self):
6867
)
6968
),
7069
default_value_expression=FIELD_DEFAULT_VALUE_EXPRESSION,
71-
rounding_mode=ROUNDINGMODE,
70+
rounding_mode=enums.RoundingMode.ROUNDING_MODE_UNSPECIFIED,
7271
foreign_type_definition="INTEGER",
7372
)
7473
self.assertEqual(field.name, "test")
@@ -86,7 +85,7 @@ def test_constructor_explicit(self):
8685
)
8786
),
8887
)
89-
self.assertEqual(field.rounding_mode, ROUNDINGMODE.name)
88+
self.assertEqual(field.rounding_mode, "ROUNDING_MODE_UNSPECIFIED")
9089
self.assertEqual(field.foreign_type_definition, "INTEGER")
9190

9291
def test_constructor_explicit_none(self):
@@ -303,12 +302,10 @@ def test_fields_property(self):
303302
self.assertEqual(schema_field.fields, fields)
304303

305304
def test_roundingmode_property_str(self):
306-
# via init
307305
ROUNDINGMODE = "ROUND_HALF_AWAY_FROM_ZERO"
308306
schema_field = self._make_one("test", "STRING", rounding_mode=ROUNDINGMODE)
309307
self.assertEqual(schema_field.rounding_mode, ROUNDINGMODE)
310308

311-
# via _properties
312309
del schema_field
313310
schema_field = self._make_one("test", "STRING")
314311
schema_field._properties["roundingMode"] = ROUNDINGMODE
@@ -514,18 +511,6 @@ def test_to_standard_sql_foreign_type_valid(self):
514511
self.assertEqual(standard_field.name, "some_field")
515512
self.assertEqual(standard_field.type.type_kind, standard_type)
516513

517-
def test_to_standard_sql_foreign_type_invalid(self):
518-
legacy_type = "FOREIGN"
519-
foreign_type_definition = None
520-
521-
with self.assertRaises(ValueError) as context:
522-
self._make_one(
523-
"some_field",
524-
field_type=legacy_type,
525-
foreign_type_definition=foreign_type_definition,
526-
)
527-
self.assertTrue("If the 'field_type'" in context.exception.args[0])
528-
529514
def test___eq___wrong_type(self):
530515
field = self._make_one("test", "STRING")
531516
other = object()

0 commit comments

Comments
 (0)