View Source Avalanche (Avalanche v0.13.0)
Avalanche is an Elixir Snowflake Connector built on top of the Snowflake SQL API v2.
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
def deps do
[
{:avalanche, "~> 0.1.0"}
]
end
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.
Functions
@spec available_req_options() :: [atom()]
List of available Req request options.
See Req.request/1
for more information.
@spec default_options() :: Keyword.t()
Returns default options.
See default_options/1
for more information.
@spec default_options(Keyword.t()) :: :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.
run(statement, params \\ [], run_options \\ [], request_options \\ [])
View Source@spec run(String.t(), list(), Keyword.t(), Keyword.t()) :: {:ok, Avalanche.Result.t()} | {: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
(boolean/0
) - Set to true to execute the statement asynchronously and return the statement handle. The default value isfalse
.:request_id
(String.t/0
) - Unique ID (a UUID) of the API request.:retry
(boolean/0
) - Set to true only when retrying the statement with a previousrequest_id
.
Request Options
:server
(String.t/0
) - Required. Snowflake server to send requests to.:warehouse
(String.t/0
) - Required. Snowflake warehouse for the statement execution.:database
(String.t/0
) - Required. Snowflake database for the statement execution.:schema
(String.t/0
) - Required. Snowflake schema for the statement execution.:role
(String.t/0
) - Required. Snowflake role for the statement execution.:timeout
(non_neg_integer/0
) - 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 is3600
.:token
- Required. Snowflake authentication via OAuth token (string) or Key Pair (Keyword List)::account
(String.t/0
) - Snowflake Account ID:user
(String.t/0
) - User:priv_key
(String.t/0
) - RSA Private Key
:poll
(non-emptykeyword/0
) - Options to customize polling for the completion of a statement's execution. Synchronous statement execution will wait a maximum of 45 secondes plus thepoll
configuration (75 seconds) for a total of 2 minutes. The default value is[delay: 2500, max_attempts: 30]
.:delay
(pos_integer/0
) - Sleep this number of milliseconds between attempts.:max_attempts
(pos_integer/0
) - Maximum number of poll attempts.
:get_partitions
(non-emptykeyword/0
) - Options to customize retrieving all the partitions of data from a statement's execution. The default value is[timeout: 120000]
.:max_concurrency
(pos_integer/0
) - Sets the maximum number of tasks to run at the same time. The default value isSystem.schedulers_online/0
.:timeout
(pos_integer/0
) - Maximum amount of time to wait (in milliseconds).
:decode_data
(non-emptykeyword/0
) - Options to customize how data is decoded from a statement's execution. The default value is[downcase_column_names: false]
.:downcase_column_names
(boolean/0
) - Downcase the result's column names.
:receive_timeout
(pos_integer/0
) - Finch socket receive timeout in milliseconds. The default accounts for Snowflake's 45 second synchronous statement execution timeout. Use thepoll
options if you want to wait longer for a result. Otherwise a statement handle will be returned that you can use withAvalanche.status/3
to get the result. The default value is50000
.
The request_options
are merged with default options set with default_options/1
.
status(statement_handle, status_options \\ [], request_options \\ [])
View Source@spec status(String.t(), Keyword.t(), Keyword.t()) :: {:ok, Avalanche.Result.t()} | {:error, Avalanche.Error.t()}
Checks the status of a statement execution.
:statement_handle
- the unique identifier for an executed statement
Status Options
:async
(boolean/0
) - Set to true to disable polling and waiting for a statement to finish executing. The default value isfalse
.:partition
(non_neg_integer/0
) - 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 is0
.
Request Options
:server
(String.t/0
) - Required. Snowflake server to send requests to.:warehouse
(String.t/0
) - Required. Snowflake warehouse for the statement execution.:database
(String.t/0
) - Required. Snowflake database for the statement execution.:schema
(String.t/0
) - Required. Snowflake schema for the statement execution.:role
(String.t/0
) - Required. Snowflake role for the statement execution.:timeout
(non_neg_integer/0
) - 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 is3600
.:token
- Required. Snowflake authentication via OAuth token (string) or Key Pair (Keyword List)::account
(String.t/0
) - Snowflake Account ID:user
(String.t/0
) - User:priv_key
(String.t/0
) - RSA Private Key
:poll
(non-emptykeyword/0
) - Options to customize polling for the completion of a statement's execution. Synchronous statement execution will wait a maximum of 45 secondes plus thepoll
configuration (75 seconds) for a total of 2 minutes. The default value is[delay: 2500, max_attempts: 30]
.:delay
(pos_integer/0
) - Sleep this number of milliseconds between attempts.:max_attempts
(pos_integer/0
) - Maximum number of poll attempts.
:get_partitions
(non-emptykeyword/0
) - Options to customize retrieving all the partitions of data from a statement's execution. The default value is[timeout: 120000]
.:max_concurrency
(pos_integer/0
) - Sets the maximum number of tasks to run at the same time. The default value isSystem.schedulers_online/0
.:timeout
(pos_integer/0
) - Maximum amount of time to wait (in milliseconds).
:decode_data
(non-emptykeyword/0
) - Options to customize how data is decoded from a statement's execution. The default value is[downcase_column_names: false]
.:downcase_column_names
(boolean/0
) - Downcase the result's column names.
:receive_timeout
(pos_integer/0
) - Finch socket receive timeout in milliseconds. The default accounts for Snowflake's 45 second synchronous statement execution timeout. Use thepoll
options if you want to wait longer for a result. Otherwise a statement handle will be returned that you can use withAvalanche.status/3
to get the result. The default value is50000
.
The request_options
are merged with default options set with default_options/1
.