### Example Ruby Snowflake Client Configuration Source: https://github.com/rinsed-org/rb-snowflake-client/blob/master/README.md Provides a practical example of how to initialize the Ruby Snowflake client using `from_env` and override default configuration options. It demonstrates setting a custom logger, increasing maximum connections, and reducing HTTP retries. ```ruby client = RubySnowflake::Client.from_env( logger: Rails.logger max_connections: 24 http_retries 1 ) ``` -------------------------------- ### Example Snowflake Formatted Public Key Source: https://github.com/rinsed-org/rb-snowflake-client/blob/master/README.md Shows the final, single-line, base64-encoded public key string ready to be set in Snowflake's user configuration. ```text MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEArOL5WQYaXSnVhQXQZQHVIzrNt08A+bnGjBb6DWFVRao3dlPG+HOf9Nv0nGlk8m5AMvvETUnN3tihuRHOJ9MOUzDp58IYIr5xvOENSunbRVyJL7DuCGwZz8z1pEnlBjZPONzEX8dCKxCU0neJrksFgwdhfhIUs7GnbTuIjYP9EqXPlbsYNYTVVnFNZ9DHFur9PggPJpPHTfFDz8MEB3Xb3AWV3pE752ed/PtRcTODvgoQSpP80cTgsKjsG009NY2ulEtV3r7yNJgawxmcMTNLhFlSS7Wm2NSEIS0aNo+DgSZI72MnAOw2klUzvdBl0i43gI+aX0Y6y/y18VL1o9KMQwIDAQAB ``` -------------------------------- ### Verify Snowflake Authentication with SnowSQL Source: https://github.com/rinsed-org/rb-snowflake-client/blob/master/README.md Command-line example using `snowsql` to verify key-pair authentication. It connects to Snowflake using the account identifier, username, and the path to the private key. ```bash # example: snowsql -a AAAAAAA.BBBBBBBB.us-east-1 -u john --private-key-path private_key.pem snowsql -a . -u --private-key-path private_key.pem ``` -------------------------------- ### Example Snowflake Public Key PEM Format Source: https://github.com/rinsed-org/rb-snowflake-client/blob/master/README.md Illustrates the typical structure of a public key in PEM format, as generated by OpenSSL, before it's transformed for Snowflake's specific requirements. ```text -----BEGIN PUBLIC KEY----- MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAx8FaPusz9X9MCvv0h3N3 v1QaruyU1ivHs8jLjo6idzLSHJPGk7n3LSXerIw5/LkhfA27ibJj225/fKFnPy+X gidbhE4BlvSdoVgdMH7WB1ZC3PpAwwqHeMisIzarwOwUu6mLyG9VY55ciKJY8CwA 5xt19pgVsXg/lcOa72jDjK+ExdSAN6K2TqSKqq77yzeI5creslny5VuAGTbZy3Bt Wk0zg1xz8+C4regIOlSoFrzn1e4wHqbFv2zFFvORC2LV3HXFRaHYClB7jWRN1bFj om6gRpiTO8bsCSPKi0anxMN8qt1Lw2d/+cwezxCwI6xPLC7JhZYdx6u+hC0g3PVK PQIDAQAB -----END PUBLIC KEY----- ``` -------------------------------- ### Switching Snowflake Database per Query in Ruby Source: https://github.com/rinsed-org/rb-snowflake-client/blob/master/README.md Demonstrates how to override the default database specified during client initialization to execute a query against a different Snowflake database. The example shows querying a 'SECRET_TABLE' in 'OTHER_DB' and iterating through the results. ```ruby result = client.query("SELECT * FROM SECRET_TABLE", database: "OTHER_DB") result.each do |row| puts row end ``` -------------------------------- ### Binding Parameters for Snowflake Queries in Ruby Source: https://github.com/rinsed-org/rb-snowflake-client/blob/master/README.md Provides an example of how to use bind variables in a Snowflake query to securely insert data, preventing SQL injection. It demonstrates inserting a JSON string into a `VARIANT` column by parsing a placeholder and binding a text value. ```ruby json_string = '{"valid": "json"}' query = "insert into BIGTABLE(data) select parse_json(?)" bindings = { "1" => { "type" => "TEXT", "value" => "Other Event" } } client.query(query, bindings: bindings) ``` -------------------------------- ### Specifying Snowflake Role per Query in Ruby Source: https://github.com/rinsed-org/rb-snowflake-client/blob/master/README.md Explains how to execute a Snowflake query using a specific role, overriding the account's primary role. This enables fine-grained access control and privilege management on a per-query basis, for example, using 'MY_ROLE' for 'BIGTABLE'. ```ruby client.query("SELECT * FROM BIGTABLE", role: "MY_ROLE") ``` -------------------------------- ### Initialize Ruby Snowflake Client Instance Source: https://github.com/rinsed-org/rb-snowflake-client/blob/master/README.md Demonstrates how to create a new `RubySnowflake::Client` instance. It covers explicit configuration with connection details (URL, private key, account info, warehouse, database, role) and initialization from environment variables. Available environment variables for configuration include `SNOWFLAKE_URI`, `SNOWFLAKE_PRIVATE_KEY_PATH` or `SNOWFLAKE_PRIVATE_KEY`, `SNOWFLAKE_ORGANIZATION`, `SNOWFLAKE_ACCOUNT`, `SNOWFLAKE_USER`, `SNOWFLAKE_DEFAULT_WAREHOUSE`, `SNOWFLAKE_DEFAULT_DATABASE`, `SNOWFLAKE_DEFAULT_ROLE`, `SNOWFLAKE_JWT_TOKEN_TTL`, `SNOWFLAKE_CONNECTION_TIMEOUT`, `SNOWFLAKE_MAX_CONNECTIONS`, `SNOWFLAKE_MAX_THREADS_PER_QUERY`, `SNOWFLAKE_THREAD_SCALE_FACTOR`, `SNOWFLAKE_HTTP_RETRIES`, and `SNOWFLAKE_QUERY_TIMEOUT`. ```ruby require "rb_snowflake_client" # uses env variables, you can also new one up # see: https://github.com/rinsed-org/pure-ruby-snowflake-client/blob/master/lib/ruby_snowflake/client.rb#L43 client = RubySnowflake::Client.new( "https://yourinstance.region.snowflakecomputing.com", # insert your URL here File.read("secrets/my_key.pem"), # your private key in PEM format (scroll down for instructions) "snowflake-organization", # your account name (doesn't match your URL), using nil may be required depending on your snowflake account "snowflake-account", # typically your subdomain "snowflake-user", # Your snowflake user "some_warehouse", # The name of your warehouse to use by default "some_database", # The name of the database in the context of which the queries will run default_role: "some_role", # The name of the role with which the queries will run. A `nil` value uses the primary role of the user. max_connections: 12, # Config options can be passed in connection_timeout: 45, # See below for the full set of options query_timeout: 1200 # how long to wait for queries, in seconds ) # alternatively you can use the `from_env` method, which will pull these values from the following environment variables. You can either provide the path to the PEM file, or it's contents in an ENV variable. RubySnowflake::Client.from_env ``` -------------------------------- ### Verify Snowflake Authentication with Ruby Client Source: https://github.com/rinsed-org/rb-snowflake-client/blob/master/README.md Ruby code snippet demonstrating how to initialize the `RubySnowflake::Client` for key-pair authentication. It requires the Snowflake URL, private key path, account details, and default warehouse/database. ```ruby client = RubySnowflake::Client.new( "https://yourinstance.region.snowflakecomputing.com", # insert your URL here File.read("secrets/my_key.pem"), # path to your private key "snowflake-organization", # your account name (doesn't match your URL), using nil may be required depending on your snowflake account "snowflake-account", # typically your subdomain "snowflake-user", # Your snowflake user "some_warehouse", # The name of your warehouse to use by default "some_database" # The name of the database in the context of which the queries will run ) ``` -------------------------------- ### Execute Snowflake Queries and Process In-Memory Results Source: https://github.com/rinsed-org/rb-snowflake-client/blob/master/README.md Shows how to execute a SQL query using the `client.query` method to fetch all data into memory. It then demonstrates iterating over the `Enumerable` result set and accessing row data using symbols, strings, or numeric indices. Also illustrates using `Enumerable` methods like `keys`, `values`, `to_h`, `each`, and `select` on individual rows. ```ruby # will get all data in memory result = client.query("SELECT ID, NAME FROM SOMETABLE") # result is Enumerable result.each do |row| # Row implements Enumerable and provides flexible column access: puts row[:id] # access with symbols (case-insensitive) puts row["name"] # access with strings (case-insensitive) puts row[0] # access with numeric indices # Row has Enumerable methods puts row.keys # get all column names puts row.values # get all values puts row.to_h # convert to Hash with column names as keys # Use all Enumerable methods row.each { |column_name, value| puts "#{column_name}: #{value}" } filtered = row.select { |column, value| column.start_with?("i") } end ``` -------------------------------- ### Ruby Snowflake Client Configuration Options Source: https://github.com/rinsed-org/rb-snowflake-client/blob/master/README.md Documents the various configuration options available for the Ruby Snowflake client, including `logger`, `log_level`, `jwt_token_ttl`, `connection_timeout`, `max_connections`, `max_threads_per_query`, `thread_scale_factor`, `http_retries`, and `query_timeout`. It specifies their purpose, default values, and how they can be set during client initialization or via environment variables. ```APIDOC Configuration Options: - logger: Takes any Ruby logger (default: std lib Logger.new(STDOUT) at DEBUG level). Not available as ENV variable. - log_level: Takes a log level (e.g., Logger::WARN for default Ruby Logger). Not available as ENV variable. - jwt_token_ttl: The time to live set on JWT token in seconds (default: 3540). Longest Snowflake supports is 60 minutes. - connection_timeout: The amount of time in seconds that the client's connection pool will wait before erroring (default: 60). - max_connections: The maximum number of http connections to hold open in the connection pool (default: 16). Increase for threaded contexts. - max_threads_per_query: The maximum number of threads the client should use to retrieve data, per query (default: 8). Set to 1 for single-threaded. - thread_scale_factor: When downloading a result set into memory, thread count is calculated by dividing a query's partition count by this number. - http_retries: Number of retries for common typically transient errors (http responses) (default: 2). - query_timeout: Time in seconds client will wait for a query to finish (default: 600s/10 minutes). Also sets this limit in the query for Snowflake to obey. ``` -------------------------------- ### Update Snowflake User with RSA Public Key Source: https://github.com/rinsed-org/rb-snowflake-client/blob/master/README.md SQL command to set the formatted public key for a specified Snowflake user (`EXAMPLE_USER`). This enables key-pair authentication for that user. ```sql ALTER USER EXAMPLE_USER SET RSA_PUBLIC_KEY = 'MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEArOL5WQYaXSnVhQXQZQHVIzrNt08A+bnGjBb6DWFVRao3dlPG+HOf9Nv0nGlk8m5AMvvETUnN3tihuRHOJ9MOUzDp58IYIr5xvOENSunbRVyJL7DuCGwZz8z1pEnlBjZPONzEX8dCKxCU0neJrksFgwdhfhIUs7GnbTuIjYP9EqXPlbsYNYTVVnFNZ9DHFur9PggPJpPHTfFDz8MEB3Xb3AWV3pE752ed/PtRcTODvgoQSpP80cTgsKjsG009NY2ulEtV3r7yNJgawxmcMTNLhFlSS7Wm2NSEIS0aNo+DgSZI72MnAOw2klUzvdBl0i43gI+aX0Y6y/y18VL1o9KMQwIDAQAB' ``` -------------------------------- ### Switching Snowflake Warehouse per Query in Ruby Source: https://github.com/rinsed-org/rb-snowflake-client/blob/master/README.md Illustrates how to specify a different Snowflake warehouse for a specific query, overriding the client's default warehouse. This allows for flexible resource allocation based on query requirements, such as using a 'FAST_WH' for 'BIGTABLE'. ```ruby client.query("SELECT * FROM BIGTABLE", warehouse: "FAST_WH") ``` -------------------------------- ### Stream Snowflake Query Results to Avoid Memory Load Source: https://github.com/rinsed-org/rb-snowflake-client/blob/master/README.md Illustrates how to execute a SQL query with `streaming: true` to process results without loading the entire dataset into memory. The client prefetches data partitions, making it suitable for large tables and efficient with IO-bound processing. ```ruby result = client.query("SELECT * FROM HUGETABLE", streaming: true) result.each do |row| puts row end ``` -------------------------------- ### Add Ruby Snowflake Client Gem to Gemfile Source: https://github.com/rinsed-org/rb-snowflake-client/blob/master/README.md Instructions to include the `rb_snowflake_client` gem in your Ruby project's Gemfile, making it available for use. ```ruby gem "rb_snowflake_client" ``` -------------------------------- ### Generate Public Key from Private Key for Snowflake Source: https://github.com/rinsed-org/rb-snowflake-client/blob/master/README.md Extracts the public key from the generated private key (`private_key.pem`) and saves it to `public_key.pem` in a standard PEM format. ```bash openssl rsa -pubout -in private_key.pem -out public_key.pem ``` -------------------------------- ### Specifying Snowflake Schema per Query in Ruby Source: https://github.com/rinsed-org/rb-snowflake-client/blob/master/README.md Shows how to direct a query to a specific schema within a Snowflake database. This is useful for organizing data and ensuring queries target the correct data structures, as demonstrated by querying 'BIGTABLE' within 'MY_SCHEMA'. ```ruby client.query("SELECT * FROM BIGTABLE", schema: "MY_SCHEMA") ``` -------------------------------- ### Generate RSA Private Key for Snowflake Authentication Source: https://github.com/rinsed-org/rb-snowflake-client/blob/master/README.md Generates a 2048-bit RSA private key and saves it to `private_key.pem`. This key is essential for JWT authentication with Snowflake and must be kept secure and not checked into source control. ```bash openssl genpkey -algorithm RSA -out private_key.pem -pkeyopt rsa_keygen_bits:2048 ``` -------------------------------- ### Format Public Key for Snowflake RSA_PUBLIC_KEY Property Source: https://github.com/rinsed-org/rb-snowflake-client/blob/master/README.md Transforms the public key into a single-line, base64-encoded DER format, which is required by Snowflake for the `RSA_PUBLIC_KEY` user property. This removes newlines and headers. ```bash openssl rsa -pubin -in public_key.pem -outform DER | openssl base64 -A ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.