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.1.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.1-py3-none-any.whl (18.4 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: spanner_analytics-1.0.1.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.1.tar.gz
Algorithm Hash digest
SHA256 d4b1eb6ec2e9fc5206c6bdeef312562a88bb1e131fc383c44f966b45301c9dcb
MD5 01681de436d6e4344d02bf464e2679a3
BLAKE2b-256 4568fa07b9a78e1180e3b6f5f921cf32114e9df05188f4d4d9571eecb9f3221d

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for spanner_analytics-1.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 d997914910d1442481b3996e371e2dc87a316a5ca1ab7b99ef5dc1d7c3388c51
MD5 7adc5e1b92e949a8066e6c818bb6e774
BLAKE2b-256 3db76dd58e81287122a615330aaec58cbcd073c640f2b2065f61c3a2f5a61250

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