Skip to content

Context tracer for flask #3573

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

Closed
wants to merge 100 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
100 commits
Select commit Hold shift + click to select a range
013949f
Fix broken link in the client Google Auth credentials help text (#3517)
parthea Jun 21, 2017
46ced00
Add back pylint as info-only for core (#3515)
Jun 22, 2017
27dcf5a
BigQuery _EnumProperty ValueError messages are not displayed properly…
smasue Jun 23, 2017
cbf073b
Re-enable pylint in info-only mode for all packages (#3519)
Jun 23, 2017
dbdc6a6
Pass 'user_project' if set for blob downloads w/ 'mediaLink' set (#3500)
tseaver Jun 26, 2017
89cfbc2
Back out support for 'requester pays' buckets. (#3538)
tseaver Jun 26, 2017
1d156e3
Prep core-0.25.0 release. (#3526)
tseaver Jun 26, 2017
25b987c
Prep datastore-1.1.0 release. (#3527)
tseaver Jun 26, 2017
67fad20
Prep logging-1.1.0 release. (#3528)
tseaver Jun 26, 2017
fc08ab0
Prep storage-1.2.0 release. (#3540)
tseaver Jun 26, 2017
d93921d
Prep bigquery-0.25.0 release. (#3530)
tseaver Jun 26, 2017
89ce0a6
Prep pubsub-0.26.0 release. (#3532)
tseaver Jun 26, 2017
c448403
Prep bigtable-0.25.0 release. (#3534)
tseaver Jun 26, 2017
cc4e685
Prep language-0.25.0 release. (#3535)
tseaver Jun 26, 2017
273b24f
Prep spanner-0.25.0 release. (#3536)
tseaver Jun 26, 2017
a42347a
Prep dns-0.25.0 release. (#3541)
tseaver Jun 26, 2017
92c468d
Prep monitoring-0.25.0 release. (#3543)
tseaver Jun 26, 2017
25c98d9
Prep resource-manager-0.25.0 release. (#3544)
tseaver Jun 26, 2017
0ac5a24
Prep runtimeconfig-0.25.0 release. (#3545)
tseaver Jun 26, 2017
e70423b
Prep speech-0.26.0 release. (#3546)
tseaver Jun 26, 2017
04ff662
Prep translate-0.25.0 release. (#3547)
tseaver Jun 26, 2017
9238a26
Prep error-reporting-0.25.0 release. (#3542)
tseaver Jun 26, 2017
f0bf9df
Prep vision-0.25.0 release. (#3537)
tseaver Jun 26, 2017
214aba6
Prep umbrella 0.26.0 release. (#3549)
tseaver Jun 26, 2017
14251d9
BQ: cleanup flake8 errors in tests (#3551)
tswast Jun 27, 2017
6ab3e01
Fix inclusion of tests in manifest.in (#3552)
Jun 27, 2017
8ab1afe
Add the ability to specify AnnotateImageRequest items in single-featu…
lukesneeringer Jun 27, 2017
eb03366
Strip base64 padding characters from urlsafe in Datastore's (to|from)…
Jun 28, 2017
39feb3e
Making all LICENSE headers "uniform". (#3563)
dhermes Jun 28, 2017
9068466
Fixes spelling typos (#3566)
rtkaleta Jun 29, 2017
3588f51
Removing google-cloud-core dependency in test_utils package. (#3550)
dhermes Jun 29, 2017
b9cb6d1
Skipping system tests when credentials env. var is unset. (#3475)
dhermes Jun 29, 2017
b22b02c
Remove `apt-get install openssl` from CircleCI config. (#3567)
dhermes Jun 29, 2017
2d81f88
DOC: developers.google.com -> cloud.google.com (#3569)
tswast Jun 29, 2017
2a4511c
Correct API spelling: 'speechContext' -> 'speechContexts'. (#3570)
Jun 30, 2017
8a0fd43
Context tracer for flask
liyanhui1228 Jun 30, 2017
14ff1f5
Update doc reference for setting up a service account (#3578)
SeanBE Jul 5, 2017
f621d17
Update 'QueryResponse.fetch_data' docstring to match changes from #34…
tseaver Jul 5, 2017
9d4524d
Fix stuff
liyanhui1228 Jul 5, 2017
bc7b0fd
Shorten nox virtualenv names to avoid hashing. (#3585)
tseaver Jul 6, 2017
7fa089c
Add support for creating a view with 'useLegacySql = False' (#3514)
richkadel Jul 6, 2017
e95dffe
Address Doug's comments
liyanhui1228 Jul 7, 2017
242b775
Fix stuff
liyanhui1228 Jul 7, 2017
582011c
Modify stuff
liyanhui1228 Jul 7, 2017
358a448
Add support for logging the trace-id in webapp2 apps. (#3593)
csilvers Jul 10, 2017
f69d704
Fixing "long line" lint violation in BigQuery unit tests. (#3596)
dhermes Jul 10, 2017
da3a7bb
Updating author_email in all setup.py. (#3598)
dhermes Jul 11, 2017
569e739
Patch in the version updates made when fixing #3579. (#3591)
dhermes Jul 11, 2017
68720f6
Implementation of DB-API for BigQuery. (#2921)
tswast Jul 12, 2017
66a9258
Spanner p0 system tests (batch #2) (#3604)
tseaver Jul 12, 2017
401bf40
Speech GAPIC to master (#3607)
lukesneeringer Jul 14, 2017
408f357
fix big query documentation broken link (#3611)
davidraleigh Jul 16, 2017
fe9b6cf
Fixing merge conflict in `setup.py` for Speech. (#3609)
dhermes Jul 17, 2017
67f4ba4
RPC retries (second PR) (#3324)
calpeyser Jul 17, 2017
46f519a
Using `CopyFrom` to set protobuf message fields (instead of `MergeFro…
dhermes Jul 17, 2017
59fd1e4
Add a __hash__ implementation to SchemaField (#3601)
azymnis Jul 17, 2017
df4b8eb
Add bigquery jobid to table (#3605)
evaogbe Jul 17, 2017
9c06b35
Add base future package to google.cloud (#3616)
Jul 17, 2017
ce3046e
Fix a typo in BigQuery usage documentation (#3621)
Maerig Jul 18, 2017
d07365f
Using assertEqual instead of assertEquals. (#3619)
dhermes Jul 18, 2017
86c77ef
Add `is_nullable` method to check for `NULLABLE` mode (#3620)
sonlac Jul 18, 2017
2767aa2
Fix "bad" storage unit tests. (#3627)
dhermes Jul 18, 2017
c565801
Add operation future (#3618)
Jul 19, 2017
827b41a
update the documentation link (#3630)
merla18 Jul 19, 2017
34bf003
Using assertIs in unit tests where appropriate. (#3629)
dhermes Jul 19, 2017
ada1cc3
update documentation link (#3633)
merla18 Jul 19, 2017
3d9461b
Fixing references to "dead" docs links. (#3631)
dhermes Jul 19, 2017
ffd7cca
Add keyword arguments to google.cloud.storage.Bucket.get_blob. (#3613)
tillahoffmann Jul 19, 2017
c262dbb
Removing JSON docs and unused images. (#3640)
dhermes Jul 20, 2017
14e570a
Changing all pypi.python.org links to warehouse links. (#3641)
dhermes Jul 20, 2017
419588c
Revert "RPC retries (second PR) (#3324)" (#3642)
Jul 20, 2017
4f4129d
Remove references to google.cloud.operation from spanner (#3625)
Jul 20, 2017
5ea61e4
Add Video Intelligence to README (#3628)
danoscarmike Jul 20, 2017
08021bd
Adding badge images to Video Intelligence README. (#3639)
dhermes Jul 20, 2017
6ff3725
Adding Bigtable Cluster location on create() request. (#3646)
dhermes Jul 20, 2017
1ed681b
Update bigtable to use future.operation (#3623)
Jul 20, 2017
2ed9426
Update auto-gen code for video intelligence (#3643)
lukesneeringer Jul 20, 2017
f8758df
Add systests for read/query w/ concurrent updates. (#3632)
tseaver Jul 20, 2017
c5ccca1
Switched to google-resumable-media in BigQuery. (#3555)
dhermes Jul 21, 2017
d2bc36d
Translate GA (#3650)
lukesneeringer Jul 21, 2017
6336e6c
Add Future interface to BigQuery jobs (#3626)
Jul 21, 2017
0414ef1
Removing vendored in google.cloud.streaming. (#3654)
dhermes Jul 21, 2017
d0479d6
Fix pylint for the main package
Jul 22, 2017
768d667
Revert "Fix pylint for the main package" - accidental push
Jul 22, 2017
506a304
Fix pylint for the main package (#3658)
Jul 24, 2017
40a3b49
Remove QueryJob.results() (#3661)
Jul 24, 2017
1598d5d
Split polling future into its own module (#3662)
Jul 24, 2017
c5922c6
Re-enable flake8 for core package and tests (#3664)
Jul 24, 2017
dd372df
Add systest for round-trip of NULL INT64. (#3665)
tseaver Jul 25, 2017
70088aa
Adding getter/setter note for Blob.metadata property. (#3647)
dhermes Jul 25, 2017
a88a334
Correctly url-encode list parameters (#3657)
isra17 Jul 25, 2017
c3ab2c0
Moving bytes signing helpers from `core` to `storage`. (#3668)
dhermes Jul 25, 2017
b56e8d4
Unbind transaction from session on commit/rollback. (#3669)
tseaver Jul 25, 2017
2083542
Removing `get_credentials()` from `core`. (#3667)
dhermes Jul 25, 2017
a813160
NL GAPIC (#3679)
lukesneeringer Jul 26, 2017
9cf5e9b
Cut release of vision API. (#3677)
dhermes Jul 26, 2017
86316d4
Auto-generated trace library (GAPIC only) (#3512)
liyanhui1228 Jul 26, 2017
9452572
Simplifying Client constructor's for Bigtable and Spanner. (#3672)
dhermes Jul 26, 2017
e273319
Implement multi-use snapshots (#3615)
tseaver Jul 26, 2017
586dab3
Merge branch 'master' of https://github.com/GoogleCloudPlatform/googl…
liyanhui1228 Jul 26, 2017
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
3 changes: 1 addition & 2 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,13 @@ version: 2
jobs:
build:
docker:
- image: googleapis/nox:0.11.2
- image: googleapis/nox:0.17.0
steps:
- checkout
- run:
name: Decrypt credentials
command: |
if [ -n "$GOOGLE_APPLICATION_CREDENTIALS" ]; then
apt-get update && apt-get install -y openssl
openssl aes-256-cbc -d -a -k "$GOOGLE_CREDENTIALS_PASSPHRASE" \
-in /var/code/gcp/test_utils/credentials.json.enc \
-out "$GOOGLE_APPLICATION_CREDENTIALS"
Expand Down
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,8 @@ coverage.xml
system_tests/local_test_setup

# Make sure a generated file isn't accidentally committed.
scripts/pylintrc_reduced
pylintrc
pylintrc.test

# Directories used for creating generated PB2 files
generated_python/
Expand Down
2 changes: 1 addition & 1 deletion CONTRIBUTING.rst
Original file line number Diff line number Diff line change
Expand Up @@ -402,7 +402,7 @@ instead of
``https://github.com/GoogleCloudPlatform/google-cloud-python/blob/master/CONTRIBUTING.rst``)
may cause problems creating links or rendering the description.

.. _description on PyPI: https://pypi.python.org/pypi/google-cloud
.. _description on PyPI: https://pypi.org/project/google-cloud/

********************************************
Travis Configuration and Build Optimizations
Expand Down
41 changes: 22 additions & 19 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ The following client libraries have **GA** support:
- `Google Cloud Datastore`_ (`Datastore README`_)
- `Stackdriver Logging`_ (`Logging README`_)
- `Google Cloud Storage`_ (`Storage README`_)
- `Google Cloud Translation`_ (`Translation README`_)

**GA** (general availability) indicates that the client library for a
particular service is stable, and that the code surface will not change in
Expand All @@ -33,7 +34,7 @@ The following client libraries have **beta** support:
- `Google BigQuery`_ (`BigQuery README`_)
- `Google Cloud Vision`_ (`Vision README`_)
- `Google Cloud Natural Language`_ (`Natural Language README`_)
- `Google Cloud Translation`_ (`Translation README`_)
- `Google Cloud Video Intelligence`_ (`Video Intelligence README`_)

**Beta** indicates that the client library for a particular service is
mostly stable and is being prepared for release. Issues and requests
Expand All @@ -57,40 +58,42 @@ Cloud Platform services:
still a work-in-progress and is more likely to get backwards-incompatible
updates. See `versioning`_ for more details.

.. _Google Cloud Datastore: https://pypi.python.org/pypi/google-cloud-datastore
.. _Google Cloud Datastore: https://pypi.org/project/google-cloud-datastore/
.. _Datastore README: https://github.com/GoogleCloudPlatform/google-cloud-python/tree/master/datastore
.. _Google Cloud Storage: https://pypi.python.org/pypi/google-cloud-storage
.. _Google Cloud Storage: https://pypi.org/project/google-cloud-storage/
.. _Storage README: https://github.com/GoogleCloudPlatform/google-cloud-python/tree/master/storage
.. _Google Cloud Pub/Sub: https://pypi.python.org/pypi/google-cloud-pubsub
.. _Google Cloud Pub/Sub: https://pypi.org/project/google-cloud-pubsub/
.. _Pub/Sub README: https://github.com/GoogleCloudPlatform/google-cloud-python/tree/master/pubsub
.. _Google BigQuery: https://pypi.python.org/pypi/google-cloud-bigquery
.. _Google BigQuery: https://pypi.org/project/google-cloud-bigquery/
.. _BigQuery README: https://github.com/GoogleCloudPlatform/google-cloud-python/tree/master/bigquery
.. _Google Cloud Resource Manager: https://pypi.python.org/pypi/google-cloud-resource-manager
.. _Google Cloud Resource Manager: https://pypi.org/project/google-cloud-resource-manager/
.. _Resource Manager README: https://github.com/GoogleCloudPlatform/google-cloud-python/tree/master/resource_manager
.. _Stackdriver Logging: https://pypi.python.org/pypi/google-cloud-logging
.. _Stackdriver Logging: https://pypi.org/project/google-cloud-logging/
.. _Logging README: https://github.com/GoogleCloudPlatform/google-cloud-python/tree/master/logging
.. _Stackdriver Monitoring: https://pypi.python.org/pypi/google-cloud-monitoring
.. _Stackdriver Monitoring: https://pypi.org/project/google-cloud-monitoring/
.. _Monitoring README: https://github.com/GoogleCloudPlatform/google-cloud-python/tree/master/monitoring
.. _Google Cloud Bigtable: https://pypi.python.org/pypi/google-cloud-bigtable
.. _Google Cloud Bigtable: https://pypi.org/project/google-cloud-bigtable/
.. _Bigtable README: https://github.com/GoogleCloudPlatform/google-cloud-python/tree/master/bigtable
.. _Google Cloud DNS: https://pypi.python.org/pypi/google-cloud-dns
.. _Google Cloud DNS: https://pypi.org/project/google-cloud-dns/
.. _DNS README: https://github.com/GoogleCloudPlatform/google-cloud-python/tree/master/dns
.. _Stackdriver Error Reporting: https://pypi.python.org/pypi/google-cloud-error-reporting
.. _Stackdriver Error Reporting: https://pypi.org/project/google-cloud-error-reporting/
.. _Error Reporting README: https://github.com/GoogleCloudPlatform/google-cloud-python/tree/master/error_reporting
.. _Google Cloud Natural Language: https://pypi.python.org/pypi/google-cloud-language
.. _Google Cloud Natural Language: https://pypi.org/project/google-cloud-language/
.. _Natural Language README: https://github.com/GoogleCloudPlatform/google-cloud-python/tree/master/language
.. _Google Cloud Translation: https://pypi.python.org/pypi/google-cloud-translate
.. _Google Cloud Translation: https://pypi.org/project/google-cloud-translate/
.. _Translation README: https://github.com/GoogleCloudPlatform/google-cloud-python/tree/master/translate
.. _Google Cloud Speech: https://pypi.python.org/pypi/google-cloud-speech
.. _Google Cloud Speech: https://pypi.org/project/google-cloud-speech/
.. _Speech README: https://github.com/GoogleCloudPlatform/google-cloud-python/tree/master/speech
.. _Google Cloud Vision: https://pypi.python.org/pypi/google-cloud-vision
.. _Google Cloud Vision: https://pypi.org/project/google-cloud-vision/
.. _Vision README: https://github.com/GoogleCloudPlatform/google-cloud-python/tree/master/vision
.. _Google Cloud Bigtable - HappyBase: https://pypi.python.org/pypi/google-cloud-happybase/
.. _Google Cloud Bigtable - HappyBase: https://pypi.org/project/google-cloud-happybase/
.. _HappyBase README: https://github.com/GoogleCloudPlatform/google-cloud-python-happybase
.. _Google Cloud Runtime Configuration: https://cloud.google.com/deployment-manager/runtime-configurator/
.. _Runtime Config README: https://github.com/GoogleCloudPlatform/google-cloud-python/tree/master/runtimeconfig
.. _Cloud Spanner: https://cloud.google.com/spanner/
.. _Cloud Spanner: https://pypi.python.org/pypi/google-cloud-spanner
.. _Cloud Spanner README: https://github.com/GoogleCloudPlatform/google-cloud-python/tree/master/spanner
.. _Google Cloud Video Intelligence: https://pypi.python.org/pypi/google-cloud-videointelligence
.. _Video Intelligence README: https://github.com/GoogleCloudPlatform/google-cloud-python/tree/master/videointelligence
.. _versioning: https://github.com/GoogleCloudPlatform/google-cloud-python/blob/master/CONTRIBUTING.rst#versioning

If you need support for other Google APIs, check out the
Expand Down Expand Up @@ -159,6 +162,6 @@ Apache 2.0 - See `the LICENSE`_ for more information.
.. |coverage| image:: https://coveralls.io/repos/GoogleCloudPlatform/google-cloud-python/badge.svg?branch=master
:target: https://coveralls.io/r/GoogleCloudPlatform/google-cloud-python?branch=master
.. |pypi| image:: https://img.shields.io/pypi/v/google-cloud.svg
:target: https://pypi.python.org/pypi/google-cloud
:target: https://pypi.org/project/google-cloud/
.. |versions| image:: https://img.shields.io/pypi/pyversions/google-cloud.svg
:target: https://pypi.python.org/pypi/google-cloud
:target: https://pypi.org/project/google-cloud/
2 changes: 1 addition & 1 deletion appveyor/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@
# pip will build them from source using the MSVC compiler matching the
# target Python version and architecture
wheel
nox-automation==0.11.2
nox-automation>=0.17.0
2 changes: 1 addition & 1 deletion bigquery/MANIFEST.in
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
include README.rst LICENSE
recursive-include unit_tests *
recursive-include tests *
global-exclude *.pyc __pycache__
10 changes: 5 additions & 5 deletions bigquery/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ Python Client for Google BigQuery

- `Documentation`_

.. _Documentation: https://googlecloudplatform.github.io/google-cloud-python/stable/bigquery-usage.html
.. _Documentation: https://googlecloudplatform.github.io/google-cloud-python/stable/bigquery/usage.html

Quick Start
-----------
Expand All @@ -26,7 +26,7 @@ possible. Check out the `Authentication section`_ in our documentation to
learn more. You may also find the `authentication document`_ shared by all
the ``google-cloud-*`` libraries to be helpful.

.. _Authentication section: http://google-cloud-python.readthedocs.io/en/latest/google-cloud-auth.html
.. _Authentication section: https://google-cloud-python.readthedocs.io/en/latest/core/auth.html
.. _authentication document: https://github.com/GoogleCloudPlatform/gcloud-common/tree/master/authentication

Using the API
Expand Down Expand Up @@ -86,9 +86,9 @@ Perform a synchronous query
See the ``google-cloud-python`` API `BigQuery documentation`_ to learn how
to connect to BigQuery using this Client Library.

.. _BigQuery documentation: https://googlecloudplatform.github.io/google-cloud-python/stable/bigquery-usage.html
.. _BigQuery documentation: https://googlecloudplatform.github.io/google-cloud-python/stable/bigquery/usage.html

.. |pypi| image:: https://img.shields.io/pypi/v/google-cloud-bigquery.svg
:target: https://pypi.python.org/pypi/google-cloud-bigquery
:target: https://pypi.org/project/google-cloud-bigquery/
.. |versions| image:: https://img.shields.io/pypi/pyversions/google-cloud-bigquery.svg
:target: https://pypi.python.org/pypi/google-cloud-bigquery
:target: https://pypi.org/project/google-cloud-bigquery/
2 changes: 1 addition & 1 deletion bigquery/google/cloud/bigquery/_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,7 @@ def _validate(self, value):
:raises: ValueError if value is not allowed.
"""
if value not in self.ALLOWED:
raise ValueError('Pass one of: %s' ', '.join(self.ALLOWED))
raise ValueError('Pass one of: %s' % ', '.join(self.ALLOWED))


class UDFResource(object):
Expand Down
70 changes: 70 additions & 0 deletions bigquery/google/cloud/bigquery/dbapi/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
# Copyright 2017 Google Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

"""Google BigQuery implementation of the Database API Specification v2.0.

This module implements the `Python Database API Specification v2.0 (DB-API)`_
for Google BigQuery.

.. _Python Database API Specification v2.0 (DB-API):
https://www.python.org/dev/peps/pep-0249/

.. warning::
The ``dbapi`` module is **alpha**. The implementation is not complete. It
might be changed in backward-incompatible ways and is not subject to any SLA
or deprecation policy.
"""

from google.cloud.bigquery.dbapi.connection import connect
from google.cloud.bigquery.dbapi.connection import Connection
from google.cloud.bigquery.dbapi.cursor import Cursor
from google.cloud.bigquery.dbapi.exceptions import Warning
from google.cloud.bigquery.dbapi.exceptions import Error
from google.cloud.bigquery.dbapi.exceptions import InterfaceError
from google.cloud.bigquery.dbapi.exceptions import DatabaseError
from google.cloud.bigquery.dbapi.exceptions import DataError
from google.cloud.bigquery.dbapi.exceptions import OperationalError
from google.cloud.bigquery.dbapi.exceptions import IntegrityError
from google.cloud.bigquery.dbapi.exceptions import InternalError
from google.cloud.bigquery.dbapi.exceptions import ProgrammingError
from google.cloud.bigquery.dbapi.exceptions import NotSupportedError
from google.cloud.bigquery.dbapi.types import Binary
from google.cloud.bigquery.dbapi.types import Date
from google.cloud.bigquery.dbapi.types import DateFromTicks
from google.cloud.bigquery.dbapi.types import Time
from google.cloud.bigquery.dbapi.types import TimeFromTicks
from google.cloud.bigquery.dbapi.types import Timestamp
from google.cloud.bigquery.dbapi.types import TimestampFromTicks
from google.cloud.bigquery.dbapi.types import BINARY
from google.cloud.bigquery.dbapi.types import DATETIME
from google.cloud.bigquery.dbapi.types import NUMBER
from google.cloud.bigquery.dbapi.types import ROWID
from google.cloud.bigquery.dbapi.types import STRING


apilevel = '2.0'

# Threads may share the module, but not connections.
threadsafety = 1

paramstyle = 'pyformat'

__all__ = [
'apilevel', 'threadsafety', 'paramstyle', 'connect', 'Connection',
'Cursor', 'Warning', 'Error', 'InterfaceError', 'DatabaseError',
'DataError', 'OperationalError', 'IntegrityError', 'InternalError',
'ProgrammingError', 'NotSupportedError', 'Binary', 'Date', 'DateFromTicks',
'Time', 'TimeFromTicks', 'Timestamp', 'TimestampFromTicks', 'BINARY',
'DATETIME', 'NUMBER', 'ROWID', 'STRING',
]
108 changes: 108 additions & 0 deletions bigquery/google/cloud/bigquery/dbapi/_helpers.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
# Copyright 2017 Google Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

import collections
import datetime
import numbers

import six

from google.cloud import bigquery
from google.cloud.bigquery.dbapi import exceptions


def scalar_to_query_parameter(value, name=None):
"""Convert a scalar value into a query parameter.

:type value: any
:param value: A scalar value to convert into a query parameter.

:type name: str
:param name: (Optional) Name of the query parameter.

:rtype: :class:`~google.cloud.bigquery.ScalarQueryParameter`
:returns:
A query parameter corresponding with the type and value of the plain
Python object.
:raises: :class:`~google.cloud.bigquery.dbapi.exceptions.ProgrammingError`
if the type cannot be determined.
"""
parameter_type = None

if isinstance(value, bool):
parameter_type = 'BOOL'
elif isinstance(value, numbers.Integral):
parameter_type = 'INT64'
elif isinstance(value, numbers.Real):
parameter_type = 'FLOAT64'
elif isinstance(value, six.text_type):
parameter_type = 'STRING'
elif isinstance(value, six.binary_type):
parameter_type = 'BYTES'
elif isinstance(value, datetime.datetime):
parameter_type = 'DATETIME' if value.tzinfo is None else 'TIMESTAMP'
elif isinstance(value, datetime.date):
parameter_type = 'DATE'
elif isinstance(value, datetime.time):
parameter_type = 'TIME'
else:
raise exceptions.ProgrammingError(
'encountered parameter {} with value {} of unexpected type'.format(
name, value))
return bigquery.ScalarQueryParameter(name, parameter_type, value)


def to_query_parameters_list(parameters):
"""Converts a sequence of parameter values into query parameters.

:type parameters: Sequence[Any]
:param parameters: Sequence of query parameter values.

:rtype: List[google.cloud.bigquery._helpers.AbstractQueryParameter]
:returns: A list of query parameters.
"""
return [scalar_to_query_parameter(value) for value in parameters]


def to_query_parameters_dict(parameters):
"""Converts a dictionary of parameter values into query parameters.

:type parameters: Mapping[str, Any]
:param parameters: Dictionary of query parameter values.

:rtype: List[google.cloud.bigquery._helpers.AbstractQueryParameter]
:returns: A list of named query parameters.
"""
return [
scalar_to_query_parameter(value, name=name)
for name, value
in six.iteritems(parameters)]


def to_query_parameters(parameters):
"""Converts DB-API parameter values into query parameters.

:type parameters: Mapping[str, Any] or Sequence[Any]
:param parameters: A dictionary or sequence of query parameter values.

:rtype: List[google.cloud.bigquery._helpers.AbstractQueryParameter]
:returns: A list of query parameters.
"""
if parameters is None:
return []

if isinstance(parameters, collections.Mapping):
return to_query_parameters_dict(parameters)

return to_query_parameters_list(parameters)
Loading