View Source Avalanche (Avalanche v0.12.2)

Avalanche is an Elixir Snowflake Connector built on top of the Snowflake SQL API v2.

features

Features

  • Submit SQL statements for execution.

  • Check the status of the execution of a statement.

  • Cancel the execution of a statement.

  • Manage your deployment (e.g. provision users and roles, create tables, etc.)

installation

Installation

def deps do
  [
    {:avalanche, "~> 0.1.0"}
  ]
end

Link to this section Summary

Functions

List of available Req request options.

Returns default options.

Sets default options.

Submits SQL statements to Snowflake for execution.

Checks the status of a statement execution.

Link to this section Functions

@spec available_req_options() :: [atom()]

List of available Req request options.

See Req.request/1 for more information.

@spec default_options() :: keyword()

Returns default options.

See default_options/1 for more information.

Link to this function

default_options(options)

View Source
@spec default_options(keyword()) :: :ok | {:error, Avalanche.Error.t()}

Sets default options.

The default options are used by run/2 functions.

Avoid setting default options in libraries as they are global.

Link to this function

run(statement, params \\ [], run_options \\ [], request_options \\ [])

View Source
@spec run(String.t(), list(), keyword(), keyword()) ::
  any() | {:error, Avalanche.Error.t()}

Submits SQL statements to Snowflake for execution.

  • :statement - the SQL statement that you want to execute

  • :params - list of values for the bind variables in the statement

Run Options

  • :async - Set to true to execute the statement asynchronously and return the statement handle. The default value is false.

  • :request_id - Unique ID (a UUID) of the API request.

  • :retry - Set to true only when retrying the statement with a previous request_id.

Request Options

  • :server - Required. Snowflake server to send requests to.

  • :warehouse - Required. Snowflake warehouse for the statement execution.

  • :database - Required. Snowflake database for the statement execution.

  • :schema - Required. Snowflake schema for the statement execution.

  • :role - Required. Snowflake role for the statement execution.

  • :timeout - Snowflake timeout in seconds for the statement execution. 0 to 604800 (i.e. 7 days) — a value of 0 specifies that the maximum timeout value is enforced. The default value is 3600.

  • :token - Required. Snowflake authentication via OAuth token (string) or Key Pair (Keyword List):

    • :account - Snowflake Account ID

    • :user - User

    • :priv_key - RSA Private Key

  • :poll - Options to customize polling for the completion of a statement's execution. Synchronous statement execution will wait a maximum of 45 secondes plus the poll configuration (75 seconds) for a total of 2 minutes. The default value is [delay: 2500, max_attempts: 30].

    • :delay - Sleep this number of milliseconds between attempts.

    • :max_attempts - Maximum number of poll attempts.

  • :get_partitions - Options to customize retrieving all the partitions of data from a statement's execution. The default value is [timeout: 120000].

    • :max_concurrency - Sets the maximum number of tasks to run at the same time. The default value is System.schedulers_online/0.

    • :timeout - Maximum amount of time to wait (in milliseconds).

  • :decode_data - Options to customize how data is decoded from a statement's execution. The default value is [downcase_column_names: false].

    • :downcase_column_names - Downcase the result's column names.
  • :receive_timeout - Finch socket receive timeout in milliseconds. The default accounts for Snowflake's 45 second synchronous statement execution timeout. Use the poll options if you want to wait longer for a result. Otherwise a statement handle will be returned that you can use with Avalanche.status/3 to get the result. The default value is 50000.

The request_options are merged with default options set with default_options/1.

Link to this function

status(statement_handle, status_options \\ [], request_options \\ [])

View Source
@spec status(String.t(), keyword(), keyword()) ::
  any() | {:error, Avalanche.Error.t()}

Checks the status of a statement execution.

  • :statement_handle - the unique identifier for an executed statement

Status Options

  • :async - Set to true to disable polling and waiting for a statement to finish executing. The default value is false.

  • :partition - Number of the partition of results to return. The number can range from 0 to the total number of partitions minus 1. The default value is 0.

Request Options

  • :server - Required. Snowflake server to send requests to.

  • :warehouse - Required. Snowflake warehouse for the statement execution.

  • :database - Required. Snowflake database for the statement execution.

  • :schema - Required. Snowflake schema for the statement execution.

  • :role - Required. Snowflake role for the statement execution.

  • :timeout - Snowflake timeout in seconds for the statement execution. 0 to 604800 (i.e. 7 days) — a value of 0 specifies that the maximum timeout value is enforced. The default value is 3600.

  • :token - Required. Snowflake authentication via OAuth token (string) or Key Pair (Keyword List):

    • :account - Snowflake Account ID

    • :user - User

    • :priv_key - RSA Private Key

  • :poll - Options to customize polling for the completion of a statement's execution. Synchronous statement execution will wait a maximum of 45 secondes plus the poll configuration (75 seconds) for a total of 2 minutes. The default value is [delay: 2500, max_attempts: 30].

    • :delay - Sleep this number of milliseconds between attempts.

    • :max_attempts - Maximum number of poll attempts.

  • :get_partitions - Options to customize retrieving all the partitions of data from a statement's execution. The default value is [timeout: 120000].

    • :max_concurrency - Sets the maximum number of tasks to run at the same time. The default value is System.schedulers_online/0.

    • :timeout - Maximum amount of time to wait (in milliseconds).

  • :decode_data - Options to customize how data is decoded from a statement's execution. The default value is [downcase_column_names: false].

    • :downcase_column_names - Downcase the result's column names.
  • :receive_timeout - Finch socket receive timeout in milliseconds. The default accounts for Snowflake's 45 second synchronous statement execution timeout. Use the poll options if you want to wait longer for a result. Otherwise a statement handle will be returned that you can use with Avalanche.status/3 to get the result. The default value is 50000.

The request_options are merged with default options set with default_options/1.