apache_beam.io.external.snowflake module¶
Snowflake transforms tested against Flink portable runner.
Setup
Transforms provided in this module are cross-language transforms implemented in the Beam Java SDK. During the pipeline construction, Python SDK will connect to a Java expansion service to expand these transforms. To facilitate this, a small amount of setup is needed before using these transforms in a Beam Python pipeline.
There are several ways to setup cross-language Snowflake transforms.
- Option 1: use the default expansion service
- Option 2: specify a custom expansion service
See below for details regarding each of these options.
Option 1: Use the default expansion service
This is the recommended and easiest setup option for using Python Snowflake transforms.This option requires following pre-requisites before running the Beam pipeline.
- Install Java runtime in the computer from where the pipeline is constructed and make sure that ‘java’ command is available.
In this option, Python SDK will either download (for released Beam version) or build (when running from a Beam Git clone) a expansion service jar and use that to expand transforms. Currently Snowflake transforms use the ‘beam-sdks-java-io-expansion-service’ jar for this purpose.
Option 2: specify a custom expansion service
In this option, you startup your own expansion service and provide that as a parameter when using the transforms provided in this module.
This option requires following pre-requisites before running the Beam pipeline.
- Startup your own expansion service.
- Update your pipeline to provide the expansion service address when initiating Snowflake transforms provided in this module.
Flink Users can use the built-in Expansion Service of the Flink Runner’s Job Server. If you start Flink’s Job Server, the expansion service will be started on port 8097. For a different address, please set the expansion_service parameter.
More information
For more information regarding cross-language transforms see: - https://beam.apache.org/roadmap/portability/
For more information specific to Flink runner see: - https://beam.apache.org/documentation/runners/flink/
-
class
apache_beam.io.external.snowflake.
ReadFromSnowflakeSchema
(server_name, schema, database, staging_bucket_name, storage_integration_name, username, password, private_key_path, private_key_passphrase, o_auth_token, table, query)¶ Bases:
tuple
Create new instance of ReadFromSnowflakeSchema(server_name, schema, database, staging_bucket_name, storage_integration_name, username, password, private_key_path, private_key_passphrase, o_auth_token, table, query)
-
database
¶ Alias for field number 2
-
o_auth_token
¶ Alias for field number 9
-
password
¶ Alias for field number 6
-
private_key_passphrase
¶ Alias for field number 8
-
private_key_path
¶ Alias for field number 7
-
query
¶ Alias for field number 11
-
schema
¶ Alias for field number 1
-
server_name
¶ Alias for field number 0
-
staging_bucket_name
¶ Alias for field number 3
-
storage_integration_name
¶ Alias for field number 4
-
table
¶ Alias for field number 10
-
username
¶ Alias for field number 5
-
-
class
apache_beam.io.external.snowflake.
ReadFromSnowflake
(server_name, schema, database, staging_bucket_name, storage_integration_name, csv_mapper, username=None, password=None, private_key_path=None, private_key_passphrase=None, o_auth_token=None, table=None, query=None, expansion_service=None)[source]¶ Bases:
apache_beam.transforms.ptransform.PTransform
An external PTransform which reads from Snowflake.
Initializes a read operation from Snowflake.
Required parameters:
Parameters: - server_name – full Snowflake server name with the following format account.region.gcp.snowflakecomputing.com.
- schema – name of the Snowflake schema in the database to use.
- database – name of the Snowflake database to use.
- staging_bucket_name – name of the Google Cloud Storage bucket.:: Bucket will be used as a temporary location for storing CSV files. Those temporary directories will be named ‘sf_copy_csv_DATE_TIME_RANDOMSUFFIX’ and they will be removed automatically once Read operation finishes.
- storage_integration_name – is the name of storage integration object created according to Snowflake documentation.
- csv_mapper – specifies a function which must translate user-defined object to array of strings. SnowflakeIO uses a COPY INTO <location> statement to move data from a Snowflake table to Google Cloud Storage as CSV files.These files are then downloaded via FileIO and processed line by line. Each line is split into an array of Strings using the OpenCSV The csv_mapper function job is to give the user the possibility to convert the array of Strings to a user-defined type, ie. GenericRecord for Avro or Parquet files, or custom objects. Example: def csv_mapper(strings_array) return User(strings_array[0], int(strings_array[1])))
- table – specifies a Snowflake table name.
- query – specifies a Snowflake custom SQL query.
- expansion_service – specifies URL of expansion service.
Authentication parameters:
Parameters: - username – specifies username for username/password authentication method.
- password – specifies password for username/password authentication method.
- private_key_path – specifies a private key file for key/ pair authentication method.
- private_key_passphrase – specifies password for key/ pair authentication method.
- o_auth_token – specifies access token for OAuth authentication method.
-
URN
= 'beam:external:java:snowflake:read:v1'¶