Snowflakeは、クラウドベースの データストレージおよび分析サービスです。  CSVファイルやテーブルなどの構造化データと、JSON、Avro、Parquetなどの半構造化データの両方をサポートするリレーショナルデータベースを提供します。データソースとしても、分析ストレージとしても使用できます。

Connector Configuration

Snowflakeには以下のパラメータが必要です:

Parameter

Description

host

A Snowflake endpoint based on account name

user-name

Name of the user's account (provided by Snowflake)

password

Password for the specified user

db

Default database to use once connected.

Data source parameter importer.catalog is a default parameter and has the same value as the database. This parameter allows loading only the needed catalog in order to reduce the time for initializing the data source

warehouse

Virtual warehouse to use once connected

Example

CALL SYSADMIN.createConnection(name => 'snowflake', jbossCLITemplateName => 'snowflake', connectionOrResourceAdapterProperties => 'host=<your_account_name.snowflakecomputing.com,db=<database>,user-name=<user_name>,password=<user_password>,warehouse=<warehouse>') ;;
 
CALL SYSADMIN.createDataSource(name => 'snowflake', translator => 'snowflake', modelProperties => 'importer.defaultSchema=PUBLIC,importer.schemaPattern=PUBLIC,importer.useFullSchemaName=FALSE,importer.tableTypes="TABLE,VIEW"', translatorProperties => 'supportsNativeQueries=true') ;;

Translator Properties

Amazon AWS S3 Upload

標準のJDBCプロトコルを使用してSnowflakeにデータを挿入すると、非常に時間がかかることがあるため、生産的な使用にはAmazon AWS S3(S3LOAD)を構成して使用することをお勧めします。

S3LOADを構成するには、以下のトランスレータパラメータが必要です:

Parameter

Description

uploadMode=s3load

Explicitly specifies the S3LOAD mode

region

AWS S3 region endpoint

bucketName

Optional parameter; bucket name to upload data files to. It is not necessarily an already existing bucket: you can use the createBucket parameter to create a new bucket or the bucketPrefix parameter to use a temporary bucket (see the next two rows)

createBucket

Optional parameter; specifies if the bucket set in the bucketName parameter should be created if it does not exist. The default value is FALSE

bucketPrefix

Optional parameter; prefix of the temporary bucket to upload data files to if bucketName is not specified; must comply with Amazon S3 bucket naming rules (note: 36 characters would be added to the bucket prefix when creating a temporary bucket)

keyId

AWS S3 key ID

secretKey

AWS S3 secret key

Examples

1. データソースとしてのSnowflake

CALL SYSADMIN.createConnection(name => 'snowflake', jbossCLITemplateName => 'snowflake', connectionOrResourceAdapterProperties => 'host=<your_account_name.snowflakecomputing.com,db=<database>,user-name=<user_name>,password=<user_password>,warehouse=<warehouse>') ;;
 
CALL SYSADMIN.createDataSource(name => 'snowflake', translator => 'snowflake', modelProperties => 'importer.defaultSchema=PUBLIC,importer.schemaPattern=PUBLIC,importer.useFullSchemaName=FALSE,importer.tableTypes="TABLE,VIEW"', translatorProperties => 'supportsNativeQueries=true,uploadMode=s3Load,region=<region>,bucketName=<bucket_name>,createBucket=true,keyId=<key_ID>,secretKey="<secret_key>"') ;;

2. 分析ストレージとしてのSnowflake

CALL SYSADMIN.createConnection(name => 'snowflake', jbossCLITemplateName => 'snowflake', connectionOrResourceAdapterProperties => 'host=<your_account_name.snowflakecomputing.com,db=<database>,user-name=<user_name>,password=<user_password>,warehouse=<warehouse>') ;;
 
CALL SYSADMIN.createDataSource(name => 'snowflake', translator => 'snowflake', modelProperties => 'importer.defaultSchema=PUBLIC,importer.schemaPattern=PUBLIC,importer.useFullSchemaName=FALSE,importer.tableTypes="TABLE,VIEW"', translatorProperties => 'supportsNativeQueries=true,uploadMode=s3Load,region=<region>,bucketName=<bucket_name>,createBucket=true,keyId=<key_ID>,secretKey="<secret_key>"') ;;
 
CALL SYSADMIN.setCurrentDWH('dwh', 'PUBLIC') ;;

S3バケットからデータを読み取るには、バケットのセキュリティおよびアクセス管理ポリシーで、Snowflakeがバケットにアクセスすることを許可する必要があります。指定したS3バケットにアクセスするために必要なPermissionを持つIAM Userが存在する必要があります。この1回限りのセットアップでは、バケットにアクセス許可を設定し、必要な許可をIAM Userに関連付けます。アクセス管理については、 Configuring AWS IAM User Credentialsをご参照ください。

Amazon AWS S3アップロードのプロキシ設定は、System Propertiesを使用して設定できます。

Internal Stage Upload

Amazon AWS S3アップロードモードの代替として、Internal Stage経由でデータアップロードを構成することができます。

必要なTRANSLATIONプロパティはこちらです:

Parameter

Description

uploadMode=INTERNAL_STAGE

Explicitly specifies the INTERNAL_STAGE mode

tempFolder

Value: a path to a folder (relative or absolute).

Specifies the folder to be used for creating temporary files instead of the system configured one. If not specified, the default OS tmp folder is used

keepTempFiles

If set to TRUE, temporary files will not be deleted after uploading

internalStageName

The name of the internal stage that will be used or created for uploading the file.  If not set, a named stage with a unique name starting with TEMPORARY_NAMED_STAGE_ will be created for uploading the file and removed when done being used by the command

Example

CALL SYSADMIN.createConnection(name => 'snowflake', jbossCLITemplateName => 'snowflake', connectionOrResourceAdapterProperties => 'host=<your_account_name.snowflakecomputing.com,db=<database>,user-name=<user_name>,password=<user_password>,warehouse=<warehouse>') ;;
 
CALL SYSADMIN.createDataSource(name => 'snowflake', translator => 'snowflake', modelProperties => 'importer.defaultSchema=PUBLIC,importer.schemaPattern=PUBLIC,importer.useFullSchemaName=FALSE,importer.tableTypes="TABLE,VIEW"', translatorProperties => 'supportsNativeQueries=true, uploadMode=INTERNAL_STAGE, tempFolder=D:/tmp,keepTempFiles=true, internalStageName=justSomeName') ;;

INTERNAL_STAGE upload mode available since v4.8

Microsoft Azure Blob Storage Upload

上記のモードとは別に、Microsoft Azure Blob Storage経由でのデータアップロードを設定することもできます。

以下に必要な TRANSLATION パラメータを示します:

Parameter

Description

uploadMode

Microsoft Azure Blob Storage upload mode: blob_azureblob_azure_direct_write, or blob_azure_multi_thread

storageAccountName

Microsoft Azure Blob Storage account name

storageAccountKey

Microsoft Azure Blob Storage account key

containerName

Name of the container defined in the Microsoft Azure Blob Storage account. This property is case-sensitive as the container name is also case-sensitive in Microsoft Azure Blob Storage

defaultEndpointsProtocol

Endpoint protocol

tempFolder

Value: a path to a folder (relative or absolute).

Specifies the folder to be used for creating temporary files instead of the system configured one. If not specified, the default OS tmp folder is used

keepTempFiles

If set to TRUE, temporary files will not be deleted after uploading

uploadZipped

If set to TRUE, zipped files will be uploaded

azureKey

Key for encrypting data while it is stored in the Azure Blob Storage, must be a base64-encoded 128, 192, or 256-bit value. When set to an empty value (i.e. azureKey=), the data does not get encrypted. The default behaviour depends on the way the data source connects to the Azure Blob Storage (see below)

Microsoft Azure Blobコンテナ内のデータファイルへのセキュアアクセスを設定するには、SASトークンの作成またはSnowflake Storage統合の設定の2つのオプションのいずれかを使用します。

Connecting via SAS Token

SAS トークンを使用するには、sasTokenプロパティを、Snowflake から Microsoft Azure Blob Storage にアクセスする際に使用する SAS トークン( )で構成し、以下のパラメータを指定します:

Parameter

Description

sasToken

SAS token used to access the Microsoft Azure Blob Storage from Snowflake

createContainer

Specifies if the container set in the containerName parameter should be created if it does not exist; optional. Default: FALSE

以下の点にご留意ください:

  • containerName パラメータは、このパラメータが設定されていない場合に使用される(トランザクションごとに作成および削除される)一時的な Azure Blob Storage コンテナーを指定します;
  • デフォルトでは、azureKeyが設定されていない場合、データはサーバーによって生成されたキーで暗号化されます。 
Example:
CALL SYSADMIN.createConnection(name => 'snowflake', jbossCLITemplateName => 'snowflake', connectionOrResourceAdapterProperties => 'host=<your_account_name.snowflakecomputing.com,db=<database>,user-name=<user_name>,password=<user_password>,warehouse=<warehouse>') ;;
 
CALL SYSADMIN.createDataSource(name => 'snowflake', translator => 'snowflake', modelProperties => 'importer.defaultSchema=PUBLIC,importer.schemaPattern=PUBLIC,importer.useFullSchemaName=FALSE,importer.tableTypes="TABLE,VIEW"', translatorProperties => 'uploadMode=blob_azure,supportsNativeQueries=true,storageAccountName=<storageAccountName>,storageAccountKey=<storageAccountKey>,sasToken="<sasToken>",defaultEndpointsProtocol=https,tempFolder=d:\tmp\azure\,keepTempFiles=false') ;;

Connecting via Snowflake Storage Integration

Snowflake Storage Integrationを使用するには、以下のプロパティを構成します:

Property

Description

externalStageName

Fully qualified name of the external stage predefined and configured in Snowflake

containerName

Name of the container defined in the Microsoft Azure Blob Storage account. Must be set to the same container as defined in externalStageName.

Please note that this property is case-sensitive as the container name is also case-sensitive in Microsoft Azure Blob Storage

以下の点にご留意ください:

  •  azureKeyパラメータの値は、外部ステージの master_key パラメータで定義された値と同じでなければなりません;
  • デフォルトでは、azureKeyが設定されていない場合、データは暗号化されません。  
Example:
CALL SYSADMIN.createConnection(name => 'snowflake', jbossCLITemplateName => 'snowflake', connectionOrResourceAdapterProperties => 'host=<your_account_name.snowflakecomputing.com,db=<database>,user-name=<user_name>,password=<user_password>,warehouse=<warehouse>') ;;
 
CALL SYSADMIN.createDataSource(name => 'snowflake', translator => 'snowflake', modelProperties => 'importer.defaultSchema=PUBLIC,importer.schemaPattern=PUBLIC,importer.useFullSchemaName=FALSE,importer.tableTypes="TABLE,VIEW"', translatorProperties => 'uploadMode=blob_azure,supportsNativeQueries=true,storageAccountName=<storageAccountName>,storageAccountKey=<storageAccountKey>,externalStageName=<fully_qualified_name>,containerName=<case_sensitive_test_containrer_name>,defaultEndpointsProtocol=https,tempFolder=d:\tmp\azure\,keepTempFiles=false') ;;

Session Keepalive

デフォルトでは、Snowflake はfour hours of inactivityの後、開いているセッションを終了します。これを防ぐには、JDBC パラメータ CLIENT_SESSION_KEEP_ALIVEを TRUEに設定します:

CALL SYSADMIN.createConnection(name => 'dwh', jbossCLITemplateName => 'snowflake', connectionOrResourceAdapterProperties => 'host=<your_account_name.snowflakecomputing.com,db=<database>,user-name=<user_name>,password=<user_password>,warehouse=<warehouse>,jdbc-properties="CLIENT_SESSION_KEEP_ALIVE=TRUE"') ;;
 
CALL SYSADMIN.createDataSource(name => 'dwh', translator => 'snowflake', modelProperties => 'importer.defaultSchema=PUBLIC,importer.schemaPattern=PUBLIC,importer.useFullSchemaName=FALSE,importer.tableTypes="TABLE,VIEW"', translatorProperties => 'supportsNativeQueries=true,uploadMode=s3Load,region=<region>,bucketName=<bucket_name>,keyId=<key_ID>,secretKey="<secret_key>"') ;;
 
CALL SYSADMIN.setCurrentDWH('dwh', 'PUBLIC') ;;

Miscellanea

Snowflakeデータソースでは、インデックスとネイティブ統計はサポートされていません。