Skip to main content

Crate adbc_spanner

Crate adbc_spanner 

Source
Expand description

§adbc-spanner

An ADBC (Arrow Database Connectivity) driver for Google Cloud Spanner, built on top of the official google-cloud-spanner preview client and the native Rust adbc_core traits.

The driver exposes Spanner through the standard ADBC object hierarchy:

SpannerDriver ──> SpannerDatabase ──> SpannerConnection ──> SpannerStatement

Query results are returned as Arrow RecordBatches, so they can be consumed by any Arrow-native tool without an intermediate row-by-row copy.

§Configuration

A database is configured through ADBC options. The Spanner database path is required and can be supplied either through the standard OptionDatabase::Uri option or the driver-specific OPTION_DATABASE key:

projects/<project>/instances/<instance>/databases/<database>

To talk to a Spanner emulator, either set the SPANNER_EMULATOR_HOST environment variable (the driver picks it up automatically and uses anonymous credentials) or set the OPTION_ENDPOINT and OPTION_EMULATOR options explicitly.

§Example

use adbc_core::{Driver, Database, Connection, Statement};
use adbc_core::options::{OptionDatabase, OptionValue};
use adbc_spanner::{SpannerDriver, OPTION_DATABASE};
use arrow_array::RecordBatchReader;

let mut driver = SpannerDriver::try_new()?;
let database = driver.new_database_with_opts([(
    OptionDatabase::Other(OPTION_DATABASE.into()),
    OptionValue::String("projects/p/instances/i/databases/d".into()),
)])?;
let mut connection = database.new_connection()?;
let mut statement = connection.new_statement()?;
statement.set_sql_query("SELECT 1 AS one")?;
let reader = statement.execute()?;
for batch in reader {
    let batch = batch?;
    println!("got {} rows", batch.num_rows());
}

Structs§

SpannerConnection
An ADBC connection to a Spanner database.
SpannerDatabase
A configured, but not yet connected, Spanner database.
SpannerDriver
The Spanner ADBC driver — the entry point for creating SpannerDatabase instances.
SpannerStatement
An ADBC statement bound to a Spanner DatabaseClient.

Constants§

DRIVER_NAME
The driver name reported by Connection::get_info.
DRIVER_VERSION
The version of this driver.
OPTION_DATABASE
Driver-specific database option: the fully-qualified Spanner database path, projects/<project>/instances/<instance>/databases/<database>.
OPTION_EMULATOR
Driver-specific database option: when set to true, connect with anonymous credentials (the mode used by the Spanner emulator). Automatically enabled when SPANNER_EMULATOR_HOST is present in the environment.
OPTION_ENDPOINT
Driver-specific database option: an explicit gRPC endpoint (for example the address of a Spanner emulator, http://localhost:9010). When unset the client connects to the production Spanner service.
VENDOR_NAME
The vendor name reported by Connection::get_info.