Skip to main content

No project description provided

Project description

spanner-analytics

This package aims to facilitate common data-analytic operations in Python using data from Cloud Spanner. This includes integrations with Jupyter Notebooks.

Using

Installation

Install from PyPI:

pip install spanner-analytics

Developing

This package can be used from Python code. For example:

from spanner_analytics import Database
db = Database.connect('<project>', '<instance>', '<database>')
dataframe = db.execute_sql("SELECT * FROM my_table")

The package also offers a "magic" command that can be used within a Jupyter Notebook. For example:

%load_ext spanner_analytics.magic
%%spanner --project <project> --instance <instance> --database <database>

SELECT * FROM my_table

Queries are executed using Cloud Spanner DataBoost. DataBoost allocates dedicated compute resources to execute your query. So it won't compete for resources with other workloads on your production database. But you will be billed for compute resources consumed by a query. See the DataBoost Pricing page for more details.

Root-partitionable queries

Queries currently must be root-partitionable. This means that the query can be logically decomposed into independent operations that operate on collocated data, with no data shuffling and no final aggregation required. The query plan must specifically contain a DistributedUnion operator as its topmost operator, and otherwise follow the documentation on reading data in parallel. This enables Spanner's client to connect in parallel to multiple Spanner nodes to fetch data with maximum performance.

For example,

SELECT a + b FROM t

is root-partitionable because it operates on each row independently. Similarly,

SELECT a + b FROM t
WHERE c < 5

is root-partitionable because, while some nodes may not have any data that's relevant to the query, that determination can be made independently.

SELECT sum(a) FROM t   -- Nope!

is NOT root-partitionable: While each node can scan in parallel, the query requires bringing data back to a single node to compute the final sum. This can be implemented by reading all data from t and performing the sum using Pandas.

SELECT * FROM t1 JOIN t1 ON t1.x = t2.y

MAY be root-partitionable IF t1 and t2 are INTERLEAVED together. Interleaved tables are stored together, so joins between them can be performed locally. Non-interleaved tables require shuffling each affected record from one table over to the node that stores the corresponding record from the other table. Because of this requirement to send data between nodes, non-interleaved joins are generally not root-partitionable.

Building

This package uses the setuptools and build packages. cd into the repository's top-level directory and run:

python3 -m build

This will produce a .whl file under dist/. For more information about Python's build process, see Python's packaging documentation. Also see package_test.py.

Testing changes

This project uses pytest to test its code. To execute all tests, cd to the repository's top-level directory and run:

pytest .

The end-to-end tests in this suite depend on Google's gcloud command-line tool, and will be skipped if it's not available. The tool is used to launch a local Spanner Emulator process, to test that this code can correctly connect to a Spanner database and handle results that it returns. gcloud can be installed following these directions.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

spanner_analytics-1.0.0.tar.gz (15.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

spanner_analytics-1.0.0-py3-none-any.whl (18.4 kB view details)

Uploaded Python 3

File details

Details for the file spanner_analytics-1.0.0.tar.gz.

File metadata

  • Download URL: spanner_analytics-1.0.0.tar.gz
  • Upload date:
  • Size: 15.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.4

File hashes

Hashes for spanner_analytics-1.0.0.tar.gz
Algorithm Hash digest
SHA256 67ce4bb6ecdcc5b19ad035ed4721b207eb2dd71d0960a40465f6f39bf3724bec
MD5 508d6a656e43848dd17d0b39dc0a7784
BLAKE2b-256 71dbf864a10e8d15e1183d90f84b4147c35b45bb2d3753c453d376fb4bf64c25

See more details on using hashes here.

File details

Details for the file spanner_analytics-1.0.0-py3-none-any.whl.

File metadata

File hashes

Hashes for spanner_analytics-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 627c8306e9cf058cd0de9ef065ac26539707393bd9828c5533510d6c2dbf0a8e
MD5 2adfb34364a44a314d3735d58b9dd30a
BLAKE2b-256 a972ac38d881a930b82581e863507e2397d0c531bf4adec67ec3a60e8effdede

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page