Chalk home page
Docs
API
CLI
  1. Integrations
  2. Spanner

Chalk supports Spanner as a natively accelerated SQL source.

Adding Spanner

Follow the GCP instructions to give Chalk access to application credentials for your GCP account. Chalk will use these credentials to access Spanner. On the dashboard, you can plug in the configuration for your Spanner database:

Add Spanner

Add a Spanner integration. These parameters will also be available as environment variables.

Spanner
Environment

Learn more about Chalk's Spanner Integration

Single Integration

Add your Spanner data source in a Python file and give it a name. This line is required for all Spanner integrations. In this file, we’ll also define a User feature class with a transaction_volume feature which will be resolved with Spanner.

If you have only one Spanner connection that you’d like to add to Chalk, you do not need to specify any arguments to construct the source in your code.

from chalk.features import features
from chalk.sql import SpannerSource

spanner_source = SpannerSource()

@features
class User:
    id: str
    transaction_volume: float

Multiple Integrations

Chalk's injects environment variables to support data integrations. But what happens when you have two data sources of the same kind? When you create a new data source from your dashboard, you have an option to provide a name for the integration. You can then reference this name in the code directly.
from chalk.sql import SpannerSource

spanner_source_txns = SpannerSource(name="SPANNER_TRANSACTIONS")
spanner_source_marketing = SpannerSource(name="SPANNER_MARKETING")

Now, you are all set to use Spanner with SQL file resolvers.

-- type: online
-- resolves: User
-- source: SPANNER_TRANSACTIONS
SELECT
    id,
    TransactionVolume AS transaction_volume
FROM
    UserTable
LIMIT 10

This file resolves the User.transaction_volume feature. Please note that the --source: my_spanner line is necessary and should match the name provided to your SpannerSource. If you have a single integration, you should use the name that is defined in the dashboard.