Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
130 commits
Select commit Hold shift + click to select a range
839965e
Rename refs in files
Jul 1, 2021
7b9dd6b
Move package
Jul 1, 2021
dc70785
more renaming
Jul 1, 2021
ca88aaa
Expose dialect and types
Jul 1, 2021
d0f9bd4
explain the weird registration
Jul 1, 2021
c35a686
fixed: No longer need `test_pybigquery_sqla` schema, we generte rando…
Jul 1, 2021
b2636d6
document that we obsolete pybigquery
Jul 2, 2021
9a82e92
get _type_map from the base module.
Jul 2, 2021
33da56c
fix import
Jul 2, 2021
073293f
Warn if an old (non-empty) version of pybigquery is installed.
Jul 2, 2021
3555943
Add __version__
Jul 2, 2021
b3d022b
fixed names
Jul 2, 2021
af5242a
Updated the way the path to __init__.py is computed
Jul 2, 2021
2a0f6a0
Updated copyright statements with new package name
Jul 2, 2021
b0458cc
Define the version in version.py
Jul 2, 2021
95c1bc3
skip coverage for code handling pybigquery hanging around
Jul 2, 2021
159f618
blacken/lint
Jul 2, 2021
e2d6021
Merge branch 'master' into sqlalchemy-bigquery-197
Jul 2, 2021
e5dc64b
merge upstream
Jul 6, 2021
a0eeeff
Merge remote-tracking branch 'origin/sqlalchemy-bigquery-197' into sq…
Jul 6, 2021
5975e16
merge upstream
Jul 7, 2021
132fcd1
Update .repo-metadata.json
jimfulton Jul 14, 2021
741f3a4
Merge branch 'master' into sqlalchemy-bigquery-197
Jul 15, 2021
20bc572
Merge branch 'master' into sqlalchemy-bigquery-197
Jul 16, 2021
8bfe4f9
Start at documentation.
Jul 12, 2021
840bd0a
system test that reproduces the GeoAlchemy2 core totorial.
Jul 12, 2021
d86d0cc
Added the geography extra
Jul 12, 2021
694d48f
Install geoalchemy2 and shapely for system tests when running Python 3.9
Jul 12, 2021
6624368
Initial geography support
Jul 12, 2021
7b22d8e
Added more examples and an installation note.
Jul 12, 2021
a574587
added wkb conversion prop and improved the wkr prop to return an object
Jul 15, 2021
f76ac54
Handle ST_GEOGFROMTEXT calls for bound geoography and GEOGRAPHY type …
Jul 20, 2021
a195937
Adjust imports and naming to reflect that we're not using custo class…
Jul 20, 2021
1a9f614
Added ORM test
Jul 20, 2021
4c6c745
MOAR tests
Jul 20, 2021
21a2148
blacken/lint and don't get Geography from .geography
Jul 20, 2021
2d10d1e
fixed type map, so introspection works.
Jul 21, 2021
374b8f7
Arrange that string arguments are coerced to geography when calling s…
Jul 21, 2021
d54059e
blacken
Jul 21, 2021
edab551
We don't need to explicitly convert strings to geography using WKT
Jul 21, 2021
dc0e2d1
Update to reflect automatic string coersion
Jul 21, 2021
eb9acc5
Added missing copyright header
Jul 22, 2021
96fcb0b
removed leftover from moving back to pybigquery
Jul 22, 2021
2c468f7
blacken
Jul 22, 2021
a166cd6
import WKY from geography
Jul 22, 2021
136e0d8
Added missing copyright
Jul 22, 2021
f2ff791
Go back to inheriting from geoalchemy2 classes
Jul 23, 2021
c08847e
Go back to using inherited types
Jul 23, 2021
0bf4a0d
Fixed RST heading level
Jul 23, 2021
3b4aac4
Tie in geography doc.
Jul 23, 2021
166d3fd
typo
Jul 23, 2021
6d4e763
need geoalchemy2 for unit tests too
Jul 23, 2021
0b451f5
comment tweak
Jul 23, 2021
c5cccb3
unit test version of the core system test
Jul 23, 2021
dedf4e0
added missing shapely imports and use WKB's wkt property in bind proc…
Jul 23, 2021
af67d86
Actually test inserting WKTs
Jul 23, 2021
8b730c2
Actually test inserting WKTs -- and more edge-case tests
Jul 23, 2021
111257c
Add last_query fixture to make it easier to look at recent queries
Jul 23, 2021
f4ab586
add a test for st_... functions that don't take geographies and lever…
Jul 23, 2021
9a90695
blacken/lint
Jul 23, 2021
55169fb
Merge branch 'master' into geography2
Jul 23, 2021
f8cb3bc
cleanup "extra" tables to limit test interaction
Jul 26, 2021
79e65f6
use lake as geography table name
Jul 26, 2021
047be9c
blacken
Jul 26, 2021
fa0233e
merge upstream
Jul 26, 2021
bae06c7
Add link to WGS83/SRID definition
Jul 28, 2021
0384a20
Refactored docs before including generated api documentation
Jul 28, 2021
cc085e1
MOAR documentation and refactored so WKB only takes a data argument
Jul 28, 2021
b9a84d3
install geoalchemy2 and shapely for docs so we can import and documen…
Jul 28, 2021
6ebfb51
refactored docs for for better navigation and to document the geograp…
Jul 28, 2021
c449885
added missing licence file
Jul 28, 2021
feb5910
Try to make owlbot/synth do the needsful for extras
Jul 28, 2021
c823c24
say the magic word
Jul 29, 2021
b0d0346
Updated some tests to reflect movement of responsibility.
Jul 29, 2021
74504ed
blacken
Jul 29, 2021
7908dd9
Updated owlbot to leverage extras config and added geoalchemy2 and sh…
Jul 29, 2021
2d71565
Added test for coverage
Jul 29, 2021
88f097b
explain why uppercase
Jul 30, 2021
6eb1c9c
simplify with importskip
Jul 30, 2021
0ce34d9
Use importskip rather than skipping based on Python version
Jul 30, 2021
22bff6b
Set up snippets
Jul 30, 2021
2e1fc9a
first wrong stab at README
Jul 30, 2021
c3bfb71
Revert "first wrong stab at README"
Jul 30, 2021
b07b95a
typo
Jul 30, 2021
8b9a0c3
Add geopandas example
Jul 30, 2021
bcac124
Merge branch 'master' into pandas-samples
Jul 30, 2021
5d95268
removed unused sys import
Jul 30, 2021
4105f7e
Added the missing CRS argument.
Jul 30, 2021
5b14b47
Merge branch 'pandas-samples' of github.com:jimfulton/python-bigquery…
Jul 30, 2021
01e8c99
Removed sphinx roles that aren't understood bt setuptools.
Jul 30, 2021
467569c
Added START and END, but I don't know what I'm doing. :)
Aug 3, 2021
02f4b54
merge upstream/master
Aug 5, 2021
0ab7d52
merge upstream/master
Aug 5, 2021
64a26a6
Keep pybigquery history pypi link
Aug 5, 2021
c6d1cc3
🦉 Updates from OwlBot
gcf-owl-bot[bot] Aug 5, 2021
47636fe
🦉 Updates from OwlBot
gcf-owl-bot[bot] Aug 5, 2021
6e6164e
Merge branch 'master' into pandas-samples
tswast Aug 5, 2021
0aed0cb
Removed the api module
Aug 5, 2021
3ac10f8
added missing comma
Aug 5, 2021
9b49a87
we decided not to have a shim, so get rid of the check for it.
Aug 5, 2021
9c31524
fixed indentation
Aug 5, 2021
117319f
typo
Aug 5, 2021
9481e4e
Update pybigquery/geography.py
jimfulton Aug 5, 2021
f8dd5b6
Merge branch 'master' into geography2
Aug 5, 2021
abe9886
Show how to install the extra
jimfulton Aug 5, 2021
b9987d4
More info on why we won't need pytest-rerunfailures
Aug 5, 2021
2a9715a
Merge branch 'geography2' of github.com:jimfulton/python-bigquery-sql…
Aug 5, 2021
382c226
removed extra rst file
Aug 5, 2021
5f821e3
Added missing import and added module docstring
Aug 6, 2021
24a7e59
More docs reorg
Aug 6, 2021
1b7be89
fixed some heading levels and also highlight that older versions are …
Aug 6, 2021
657054f
lint
Aug 6, 2021
b6067ef
Force unique column labels (shouldn't ne necessary)
Aug 6, 2021
9283c2c
typo
Aug 6, 2021
edff38d
fixed snippet tags
Aug 6, 2021
b32571b
merge geograph2
Aug 6, 2021
0dedb8f
rename pybigquery to sqlalchemy-bigquery
Aug 6, 2021
c0d6203
Merge branch 'pandas-samples' into geography3
Aug 6, 2021
6267b04
Remove samples we don't want people to see :)
Aug 6, 2021
3022b94
Fixed spelling of sqlalchemy_bigquery
Aug 6, 2021
6343bee
Changed the geometry doc to use snippets
Aug 6, 2021
04c09e5
Added missing licence file
Aug 6, 2021
8e9c35a
blacken
Aug 6, 2021
2b654f0
lint
Aug 6, 2021
79f8fe2
lint
Aug 6, 2021
6eec1f4
merge master
Aug 10, 2021
943a40b
compute all extras
Aug 10, 2021
f17d82e
blacken
Aug 10, 2021
8bc686e
use `use_labels` to work around another related flakey test.
Aug 16, 2021
23b631f
Merge branch 'master' into geography2
Aug 17, 2021
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
2 changes: 1 addition & 1 deletion docs/alembic.rst
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
Alembic support
---------------
^^^^^^^^^^^^^^^

`Alembic <https://alembic.sqlalchemy.org>`_ is a lightweight database
migration tool for usage with the SQLAlchemy Database Toolkit for
Expand Down
87 changes: 87 additions & 0 deletions docs/geography.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
Working with Geographic data
^^^^^^^^^^^^^^^^^^^^^^^^^^^^

BigQuery provides a `GEOGRAPHY data type
<https://cloud.google.com/bigquery/docs/reference/standard-sql/data-types#geography_type>`_
for `working with geographic data
<https://cloud.google.com/bigquery/docs/gis-data>`_, including:

- Points,
- Linestrings,
- Polygons, and
- Collections of points, linestrings, and polygons.

Geographic data uses the `WGS84
<https://earth-info.nga.mil/#tab_wgs84-data>`_ coordinate system.

To define a geography column, use the `GEOGRAPHY` data type imported
from the `sqlalchemy_bigquery` module:

.. literalinclude:: samples/snippets/geography.py
:language: python
:dedent: 4
:start-after: [START bigquery_sqlalchemy_create_table_with_geography]
:end-before: [END bigquery_sqlalchemy_create_table_with_geography]

BigQuery has a variety of `SQL geographic functions
<https://cloud.google.com/bigquery/docs/reference/standard-sql/geography_functions>`_
for working with geographic data. Among these are functions for
converting between SQL geometry objects and `standard text (WKT) and
binary (WKB) representations
<https://en.wikipedia.org/wiki/Well-known_text_representation_of_geometry>`_.

Geography data is typically represented in Python as text strings in
WKT format or as `WKB` objects, which contain binary data in WKB
format. Querying geographic data returns `WKB` objects and `WKB`
objects may be used in queries. When
calling spatial functions that expect geographic arguments, text
arguments are automatically coerced to geography.

Inserting data
~~~~~~~~~~~~~~

When inserting geography data, you can pass WKT strings, `WKT` objects,
or `WKB` objects:

.. literalinclude:: samples/snippets/geography.py
:language: python
:dedent: 4
:start-after: [START bigquery_sqlalchemy_insert_geography]
:end-before: [END bigquery_sqlalchemy_insert_geography]

Note that in the `lake3` example, we got a `WKB` object by creating a
`WKT` object and getting its `wkb` property. Normally, we'd get `WKB`
objects as results of previous queries.

Queries
~~~~~~~

When performing spacial queries, and geography objects are expected,
you can to pass `WKB` or `WKT` objects:

.. literalinclude:: samples/snippets/geography.py
:language: python
:dedent: 4
:start-after: [START bigquery_sqlalchemy_query_geography_wkb]
:end-before: [END bigquery_sqlalchemy_query_geography_wkb]

In this example, we passed the `geog` attribute of `lake2`, which is a WKB object.

Or you can pass strings in WKT format:

.. literalinclude:: samples/snippets/geography.py
:language: python
:dedent: 4
:start-after: [START bigquery_sqlalchemy_query_geography_text]
:end-before: [END bigquery_sqlalchemy_query_geography_text]

Installing geography support
~~~~~~~~~~~~~~~~~~~~~~~~~~~~

To get geography support, you need to install `sqlalchemy-bigquery`
with the `geography` extra, or separately install `GeoAlchemy2` and
`shapely`.

.. code-block:: console

pip install 'sqlalchemy-bigquery[geography]'
2 changes: 2 additions & 0 deletions docs/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
:maxdepth: 2

README
geography
alembic
reference

Changelog
---------
Expand Down
12 changes: 12 additions & 0 deletions docs/reference.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
API Reference
^^^^^^^^^^^^^

Geography
~~~~~~~~~

.. autoclass:: sqlalchemy_bigquery.geography.GEOGRAPHY
:exclude-members: bind_expression, ElementType, bind_processor

.. automodule:: sqlalchemy_bigquery.geography
:members: WKB, WKT
:exclude-members: GEOGRAPHY
1 change: 1 addition & 0 deletions docs/samples
53 changes: 30 additions & 23 deletions noxfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,22 +82,6 @@ def lint_setup_py(session):
session.run("python", "setup.py", "check", "--restructuredtext", "--strict")


def install_alembic_for_python_38(session, constraints_path):
"""
install alembic for Python 3.8 unit and system tests

We do not require alembic and most tests should run without it, however

- We run some unit tests (Python 3.8) to cover the alembic
registration that happens when alembic is installed.

- We have a system test that demonstrates working with alembic and
proves that the things we think should work do work. :)
"""
if session.python == "3.8":
session.install("alembic", "-c", constraints_path)


def default(session):
# Install all test dependencies, then install this package in-place.

Expand All @@ -114,8 +98,13 @@ def default(session):
constraints_path,
)

install_alembic_for_python_38(session, constraints_path)
session.install("-e", ".", "-c", constraints_path)
if session.python == "3.8":
extras = "[alembic]"
elif session.python == "3.9":
extras = "[geography]"
else:
extras = ""
session.install("-e", f".{extras}", "-c", constraints_path)

# Run py.test against the unit tests.
session.run(
Expand Down Expand Up @@ -167,8 +156,13 @@ def system(session):
# Install all test dependencies, then install this package into the
# virtualenv's dist-packages.
session.install("mock", "pytest", "google-cloud-testutils", "-c", constraints_path)
install_alembic_for_python_38(session, constraints_path)
session.install("-e", ".", "-c", constraints_path)
if session.python == "3.8":
extras = "[alembic]"
elif session.python == "3.9":
extras = "[geography]"
else:
extras = ""
session.install("-e", f".{extras}", "-c", constraints_path)

# Run py.test against the system tests.
if system_test_exists:
Expand Down Expand Up @@ -216,7 +210,13 @@ def compliance(session):
"-c",
constraints_path,
)
session.install("-e", ".", "-c", constraints_path)
if session.python == "3.8":
extras = "[alembic]"
elif session.python == "3.9":
extras = "[geography]"
else:
extras = ""
session.install("-e", f".{extras}", "-c", constraints_path)

session.run(
"py.test",
Expand Down Expand Up @@ -251,7 +251,9 @@ def docs(session):
"""Build the docs for this library."""

session.install("-e", ".")
session.install("sphinx==4.0.1", "alabaster", "recommonmark")
session.install(
"sphinx==4.0.1", "alabaster", "geoalchemy2", "shapely", "recommonmark"
)

shutil.rmtree(os.path.join("docs", "_build"), ignore_errors=True)
session.run(
Expand All @@ -274,7 +276,12 @@ def docfx(session):

session.install("-e", ".")
session.install(
"sphinx==4.0.1", "alabaster", "recommonmark", "gcp-sphinx-docfx-yaml"
"sphinx==4.0.1",
"alabaster",
"geoalchemy2",
"shapely",
"recommonmark",
"gcp-sphinx-docfx-yaml",
)

shutil.rmtree(os.path.join("docs", "_build"), ignore_errors=True)
Expand Down
62 changes: 28 additions & 34 deletions owlbot.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

import synthtool as s
from synthtool import gcp

from synthtool.languages import python

REPO_ROOT = pathlib.Path(__file__).parent.absolute()

Expand All @@ -27,10 +27,19 @@
# ----------------------------------------------------------------------------
# Add templated files
# ----------------------------------------------------------------------------
extras = []
extras_by_python = {
"3.8": ["alembic"],
"3.9": ["geography"],
}
templated_files = common.py_library(
unit_test_python_versions=["3.6", "3.7", "3.8", "3.9"],
system_test_python_versions=["3.8", "3.9"],
cov_level=100
cov_level=100,
unit_test_extras=extras,
unit_test_extras_by_python=extras_by_python,
system_test_extras=extras,
system_test_extras_by_python=extras_by_python,
)
s.move(templated_files, excludes=[
# sqlalchemy-bigquery was originally licensed MIT
Expand Down Expand Up @@ -77,37 +86,6 @@ def place_before(path, text, *before_text, escape=None):
"nox.options.stop_on_first_error = True",
)

install_alembic_for_python_38 = '''
def install_alembic_for_python_38(session, constraints_path):
"""
install alembic for Python 3.8 unit and system tests

We do not require alembic and most tests should run without it, however

- We run some unit tests (Python 3.8) to cover the alembic
registration that happens when alembic is installed.

- We have a system test that demonstrates working with alembic and
proves that the things we think should work do work. :)
"""
if session.python == "3.8":
session.install("alembic", "-c", constraints_path)


'''

place_before(
"noxfile.py",
"def default",
install_alembic_for_python_38,
)

place_before(
"noxfile.py",
' session.install("-e", ".", ',
" install_alembic_for_python_38(session, constraints_path)",
escape='(')

old_sessions = '''
"unit",
"system",
Expand All @@ -125,6 +103,9 @@ def install_alembic_for_python_38(session, constraints_path):

s.replace( ["noxfile.py"], old_sessions, new_sessions)

# Maybe we can get rid of this when we don't need pytest-rerunfailures,
# which we won't need when BQ retries itself:
# https://github.com/googleapis/python-bigquery/pull/837
compliance = '''
@nox.session(python=SYSTEM_TEST_PYTHON_VERSIONS)
def compliance(session):
Expand Down Expand Up @@ -153,7 +134,13 @@ def compliance(session):
"-c",
constraints_path,
)
session.install("-e", ".", "-c", constraints_path)
if session.python == "3.8":
extras = "[alembic]"
elif session.python == "3.9":
extras = "[geography]"
else:
extras = ""
session.install("-e", f".{extras}", "-c", constraints_path)

session.run(
"py.test",
Expand All @@ -180,6 +167,7 @@ def compliance(session):
escape="()",
)

s.replace(["noxfile.py"], '"alabaster"', '"alabaster", "geoalchemy2", "shapely"')



Expand All @@ -201,6 +189,12 @@ def compliance(session):
"""
)

# ----------------------------------------------------------------------------
# Samples templates
# ----------------------------------------------------------------------------

python.py_samples(skip_readmes=True)

# ----------------------------------------------------------------------------
# Final cleanup
# ----------------------------------------------------------------------------
Expand Down
Empty file added samples/__init__.py
Empty file.
Empty file added samples/pytest.ini
Empty file.
20 changes: 20 additions & 0 deletions samples/snippets/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Copyright (c) 2021 The sqlalchemy-bigquery Authors
#
# Permission is hereby granted, free of charge, to any person obtaining a copy of
# this software and associated documentation files (the "Software"), to deal in
# the Software without restriction, including without limitation the rights to
# use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
# the Software, and to permit persons to whom the Software is furnished to do so,
# subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in all
# copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
# FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
# COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
# IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
# CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

__version__ = "1.0.0-a1"
48 changes: 48 additions & 0 deletions samples/snippets/conftest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
# Copyright (c) 2021 The sqlalchemy-bigquery Authors
#
# Permission is hereby granted, free of charge, to any person obtaining a copy of
# this software and associated documentation files (the "Software"), to deal in
# the Software without restriction, including without limitation the rights to
# use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
# the Software, and to permit persons to whom the Software is furnished to do so,
# subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in all
# copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
# FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
# COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
# IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
# CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
"""
SQLAlchemy dialect for Google BigQuery
"""

from google.cloud import bigquery
import pytest
import sqlalchemy
import test_utils.prefixer

prefixer = test_utils.prefixer.Prefixer("python-bigquery-sqlalchemy", "tests/system")


@pytest.fixture(scope="session")
def client():
return bigquery.Client()


@pytest.fixture(scope="session")
def dataset_id(client: bigquery.Client):
project_id = client.project
dataset_id = prefixer.create_prefix()
dataset = bigquery.Dataset(f"{project_id}.{dataset_id}")
dataset = client.create_dataset(dataset)
yield dataset_id
client.delete_dataset(dataset_id, delete_contents=True)


@pytest.fixture(scope="session")
def engine(dataset_id):
return sqlalchemy.create_engine(f"bigquery:///{dataset_id}")
Loading