Spanner Writer
For a hands-on tutorial, see Continuous data replication to Cloud Spanner using Striim on cloud.google.com.
Note
Spanner Writer supports only the GoogleSQL dialect. It does not support the PostgreSQL dialect.
Spanner Writer does not support named schemas. All tables must be in the default schema.
Spanner Writer properties
property | type | default value | notes |
|---|---|---|---|
Batch Policy | String | eventCount: 1000, Interval: 60s | The batch policy includes eventcount and interval (see Setting output names and rollover / upload policies for syntax). Events are buffered locally on the Striim server and sent as a batch to the target every time either of the specified values is exceeded. When the app is stopped, all remaining events are sent to the target. With the default setting, data will be written every 60 seconds or sooner if the buffer accumulates 1000 events. When Preserve Source Transaction Boundaries is False, Primary key updates are sent as a single-event batch. When Preserve Source Transaction Boundaries is True, a batch with many primary key updates may take some extra time to execute as a read row operation must be performed. When the batch policy event count or interval is reached, or Spanner's "Mutations per commit" limit (see Spanner > Documentation > Resources> Quotas & limits > Limits for creating, reading, updating, and deleting data) is reached, a transaction is created (see Spanner > Documentation > Guides > Transactions overview. When Preserve Source Transation Boundary is True and the source's Filter Source Transaction property (if any) is False, you may disable this property with the setting |
CDDL Action | String | Process | |
Checkpoint Table | String | CHKPOINT | To support recovery (see Recovering applications, a checkpoint table must be created in each target database using the following DDL: CREATE TABLE CHKPOINT ( ID STRING(MAX) NOT NULL, SOURCEPOSITION BYTES(MAX) ) PRIMARY KEY (ID); If the table does not exist and recovery is enabled, Striim will create the If necessary you may use a different table name, in which case change the value of this property. All databases must use the same checkpoint table name. |
Excluded Tables | String | If | |
Execute Insert As Update | Boolean | False | |
Execute Update As Insert | Boolean | False | |
Ignorable Exception Code | String | By default, if the target DBMS returns an error, Striim terminates the application. Use this property to specify one or more error codes (see Cloud Spanner > Documentation > Reference > Code) to ignore, separated by semicolons, for example, Ignored exceptions will be written to the application's exception store (see CREATE EXCEPTIONSTORE). This property is ignored when Preserve Source Transaction Boundary is True. | |
Instance ID | String | Specify the instance ID for the databases containing the tables to be written to. (Note: the instance ID may not be the same as the instance name.) | |
Parallel Threads | Integer | ||
Preserve Source Transaction Boundary | Boolean | False | See Using Preserve Source Transaction Boundary with Spanner targets. |
Private Service Connect Endpoint | String | If using Private Service Connect with Google Spanner, specify the endpoint created in the target Virtual Private Cloud, as described in Private Service Connect support for Google cloud adapters. | |
Project ID | String | To use a service account key other than the one associated with the Spanner instance's project, specify its project ID here. Otherwise leave blank. | |
Service Account Key | String | The path (from root or the Striim program directory) and file name to the .json credentials file downloaded from Google (see Service Accounts). This file must be copied to the same location on each Striim server that will run this adapter, or to a network location accessible by all servers. The associated service account must have the Cloud Spanner Database User or higher role for the instance (see Cloud Spanner Roles). To use a service account key other than the one associated with the Spanner instance's project, specify a value for the Project ID property. | |
Tables | String | Specify the name(s) of the table(s) to write to, in the format All tables must have primary keys. If the source is Database Reader, its Create Schema property is True, and a source table does not have a primary key, the application will terminate. If the source is Database Reader and its Create Schema property is True, databases corresponding to the specified schemas will be created in Spanner’s default schema and tables matching those in the source schemas will be created in those Spanner databases (see the discussion of Create Schema in Database Reader properties for more details). Otherwise, the table(s) must exist in the target when the application is started, and if a specified target table does not exist, the application will terminate with an error. To skip writes to missing tables without terminating, specify NOT_FOUND as an Ignorable Exception Code. To minimize latency, create a separate Spanner Writer for each database to be written to rather than writing to multiple databases with a single Spanner Writer. The target table name(s) specified here must match the case shown in the Spanner UI. See Naming conventions. When the target's input stream is a user-defined event, specify a single table. When the input stream of the target is the output of a DatabaseReader, IncrementalBatchReader, or SQL CDC source (that is, when replicating data from one database to another), it can write to multiple tables. In this case, specify the names of both the source and target tables. You may use the source.emp,target.emp source.db1,target.db1;source.db2,target.db2 source.%,target.% source.mydatabase.emp%,target.mydb.% source1.%,target1.%;source2.%,target2.% When a target table has a commit timestamp column, by default its value will be Spanner's current system time when the transaction is committed. To use a different value, use ColumnMap. For example, to use the time the source transaction was committed in Oracle: See Mapping columns, Defining relations between source and target using ColumnMap and KeyColumns, and Column mapping for partial JSON updates for additional options. |
Spanner Writer sample application
The following sample application will copy all tables from two Oracle source schemas to tables with the same names in two Spanner databases. All source and target tables must exist before the application is started.
CREATE SOURCE OracleSource1 USING OracleReader ( Username:'myname', Password:'******', ConnectionURL: 'localhost:1521:XE’, Tables:'MYDB1.%;MYDB2.%’ ) OUTPUT TO sourceStream; CREATE TARGET SpannerWriterTest USING SpannerWriter( Tables:'ORADB1.%,spandb1.%;ORADB2.%,spandb2.%', ServiceAccountKey: '<path>/<filename>.json', instanceId: 'myinstance', ExecuteInsertAsUpdate : ‘true’, ExecuteUpdateAsInsert : ‘true’ ) INPUT FROM sourceStream;
Spanner Writer data type support and correspondence
Note
ARRAY and JSON support: Spanner Writer supports GoogleSQL ARRAY and JSON target columns. For partial JSON updates, complete replacement, supported array types, and schema requirements, see Support for ARRAY data types in Spanner targets and Support for JSON data types in Spanner targets.
See also Data type support & mapping for schema conversion & evolution.
TQL type | Spanner type | notes |
|---|---|---|
Boolean | BOOL | |
byte[] | BYTES | |
DateTime | DATE, TIMESTAMP | |
Double, Float | FLOAT64, NUMERIC | |
Integer, Long | INT64 | |
String | STRING |
|
When the input of a Spanner Writer target is the output of an Oracle source (Database Reader, Incremental Batch Reader, Oracle Reader, or OJet):
Oracle type | Spanner type | notes |
|---|---|---|
BINARY_DOUBLE | FLOAT64, NUMERIC | |
BINARY | FLOAT64, NUMERIC | |
BLOB | BYTES | |
CHAR | STRING | maximum permitted length in Spanner is 2,621,440 |
CLOB | ||
DATE | DATE | |
FLOAT | FLOAT64, NUMERIC | |
LONG | STRING | maximum permitted length in Spanner is 2,621,440 |
NCHAR | STRING | maximum permitted length in Spanner is 2,621,440 |
NCLOB | STRING | maximum permitted length in Spanner is 2,621,440 |
NVARCHAR2 | STRING | maximum permitted length in Spanner is 2,621,440 |
NUMBER | INT64 | |
NUMBER(precision,scale) | FLOAT64, NUMERIC | |
RAW | BYTES | |
ROWID | STRING | maximum permitted length in Spanner is 2,621,440 |
TIMESTAMP | TIMESTAMP | TIMESTAMP |
TIMESTAMP WITH LOCAL TIMEZONE | TIMESTAMP | TIMESTAMP |
TIMESTAMP WITH TIMEZONE | TIMESTAMP | TIMESTAMP |
UROWID | STRING | maximum permitted length in Spanner is 2,621,440 |
VARCHAR2 | STRING | maximum permitted length in Spanner is 2,621,440 |
XMLTYPE |
When the input of a Spanner Writer target is the output of a SQL Server source (Database Reader, Incremental BatchReader, MS SQL Reader, or MSJet):
SQL Server type | Spanner type | |
|---|---|---|
bigint | INT64 | |
binary | BYTES | |
bit | not supported | |
char | STRING | maximum permitted length in Spanner is 2,621,440 |
date | DATE | |
datetime | TIMESTAMP | |
datetime2 | TIMESTAMP | |
datetimeoffset | TIMESTAMP | |
decimal | FLOAT64, NUMERIC | |
float | FLOAT64, NUMERIC | |
image | BYTES | |
int | INT64 | |
money | in Striim 4.2.0.4 or later: NUMERIC | |
nchar | STRING | |
ntext | STRING | |
numeric | in Striim 4.2.0.4 or later: NUMERIC | |
nvarchar | STRING | |
nvarchar(max) | not supported | |
real | not supported | |
smalldatetime | TIMESTAMP | |
smallint | INT64 | |
smallmoney | in Striim 4.2.0.4 or later: NUMERIC | |
text | STRING | maximum permitted length in Spanner is 2,621,440 |
time | STRING | |
tinyint | INT64 | |
uniqueidentifier | not supported | |
varbinary | BYTES | |
varchar | STRING | maximum permitted length in Spanner is 2,621,440 |
xml | STRING | maximum permitted length in Spanner is 2,621,440 |