Skip to content
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

feat: Add geography support #228

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

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs/alembic.rst
@@ -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
@@ -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.
jimfulton marked this conversation as resolved.
Show resolved Hide resolved

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`.
jimfulton marked this conversation as resolved.
Show resolved Hide resolved

.. code-block:: console

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

README
geography
alembic
reference

Changelog
---------
Expand Down
12 changes: 12 additions & 0 deletions docs/reference.rst
@@ -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
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 @@ -106,8 +90,13 @@ def default(session):
)
session.install("mock", "pytest", "pytest-cov", "-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 unit tests.
session.run(
Expand Down Expand Up @@ -159,8 +148,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 @@ -208,7 +202,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 @@ -243,7 +243,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 @@ -266,7 +268,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
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 = {
jimfulton marked this conversation as resolved.
Show resolved Hide resolved
"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
@@ -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
@@ -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}")