GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — BigQuery: Adds helper function for snake to camel case conversion by alixhami · Pull Request #4160 · googleapis/google-cloud-python

BigQuery: Adds helper function for snake to camel case conversion #4160

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.

Sign up for GitHub

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

Merged
tswast merged 2 commits into googleapis:bigquery-b2 from alixhami:bq-camel-case-helper
Oct 18, 2017

Uh oh!

There was an error while loading. Please reload this page.

Merged

BigQuery: Adds helper function for snake to camel case conversion #4160

Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
2 commits
Select commit Hold shift + click to select a range
5155e28
adds helper function for snake to camel case conversion
alixhami Oct 11, 2017
859fa9b
adds unit test
alixhami Oct 11, 2017
File filter
Filter by extension

Clear filters
Conversations
Failed to load comments.
Loading

Uh oh!

There was an error while loading. Please reload this page.

Jump to
Jump to file
Failed to load files.
Loading

Uh oh!

There was an error while loading. Please reload this page.

Diff view
Diff view

There are no files selected for viewing

6 changes: 6 additions & 0 deletions 6 bigquery/google/cloud/bigquery/_helpers.py
Show comments
View file
Open in desktop
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):
Comment thread

This comment was marked as spam.

Sign in to view

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

"""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 5 bigquery/google/cloud/bigquery/client.py
Show comments
View file
Open in desktop
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 7 bigquery/google/cloud/bigquery/table.py
Show comments
View file
Open in desktop
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 14 bigquery/tests/unit/test__helpers.py
Show comments
View file
Open in desktop
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
Add this suggestion to a batch that can be applied as a single commit. This suggestion is invalid because no changes were made to the code. Suggestions cannot be applied while the pull request is closed. Suggestions cannot be applied while viewing a subset of changes. Only one suggestion per line can be applied in a batch. Add this suggestion to a batch that can be applied as a single commit. Applying suggestions on deleted lines is not supported. You must change the existing code in this line in order to create a valid suggestion. Outdated suggestions cannot be applied. This suggestion has been applied or marked resolved. Suggestions cannot be applied from pending reviews. Suggestions cannot be applied on multi-line comments. Suggestions cannot be applied while the pull request is queued to merge. Suggestion cannot be applied right now. Please check back later.
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.