Skip to content
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
6 changes: 6 additions & 0 deletions bigquery/google/cloud/bigquery/_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -367,6 +367,12 @@ def _time_to_json(value):
_SCALAR_VALUE_TO_JSON_PARAM['TIMESTAMP'] = _timestamp_to_json_parameter


def _snake_to_camel_case(value):

This comment was marked as spam.

"""Convert snake case string to camel case."""
words = value.split('_')
return words[0] + ''.join(map(str.capitalize, words[1:]))


class _ApiResourceProperty(object):
"""Base property implementation.

Expand Down
5 changes: 2 additions & 3 deletions bigquery/google/cloud/bigquery/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
from google.cloud.bigquery._helpers import _field_to_index_mapping
from google.cloud.bigquery._helpers import _SCALAR_VALUE_TO_JSON_ROW
from google.cloud.bigquery._helpers import DEFAULT_RETRY
from google.cloud.bigquery._helpers import _snake_to_camel_case


_DEFAULT_CHUNKSIZE = 1048576 # 1024 * 1024 B = 1 MB
Expand Down Expand Up @@ -340,9 +341,7 @@ def update_dataset(self, dataset, fields, retry=DEFAULT_RETRY):
api_field = 'access'
else:
attr = getattr(dataset, f)
# snake case to camel case
words = f.split('_')
api_field = words[0] + ''.join(map(str.capitalize, words[1:]))
api_field = _snake_to_camel_case(f)
partial[api_field] = attr
if dataset.etag is not None:
headers = {'If-Match': dataset.etag}
Expand Down
7 changes: 2 additions & 5 deletions bigquery/google/cloud/bigquery/table.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@

from google.cloud._helpers import _datetime_from_microseconds
from google.cloud._helpers import _millis_from_datetime
from google.cloud.bigquery._helpers import _snake_to_camel_case
from google.cloud.bigquery.schema import SchemaField
from google.cloud.bigquery.schema import _build_schema_resource
from google.cloud.bigquery.schema import _parse_schema_resource
Expand Down Expand Up @@ -705,11 +706,7 @@ def _build_resource(self, filter_fields):
if f in self.custom_resource_fields:
self.custom_resource_fields[f](self, resource)
else:
# TODO(alixh) refactor to use in both Table and Dataset
# snake case to camel case
words = f.split('_')
api_field = words[0] + ''.join(
map(str.capitalize, words[1:]))
api_field = _snake_to_camel_case(f)
resource[api_field] = getattr(self, f)
return resource

Expand Down
14 changes: 14 additions & 0 deletions bigquery/tests/unit/test__helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -749,6 +749,20 @@ def test_w_datetime(self):
self.assertEqual(self._call_fut(when), '12:13:41')


class Test_snake_to_camel_case(unittest.TestCase):

def _call_fut(self, value):
from google.cloud.bigquery._helpers import _snake_to_camel_case

return _snake_to_camel_case(value)

def test_w_snake_case_string(self):
self.assertEqual(self._call_fut('friendly_name'), 'friendlyName')

def test_w_camel_case_string(self):
self.assertEqual(self._call_fut('friendlyName'), 'friendlyName')


class Test_TypedApiResourceProperty(unittest.TestCase):

@staticmethod
Expand Down