Skip to content

Gem wrapper to enable ruby to use libsnowflakeclient for faster queries

Notifications You must be signed in to change notification settings

Riskified/ruby_snowflake_client

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

33 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

ruby_snowflake_client

A small gem wrapping libsnowflakeclient whose goal is to stream query results so as to not allocate memory for more than a row at a time.

Building the gem file as Ruby native: gem build ruby_snowflake_client.gemspec

Install this library (there are other means): gem install pkg/ruby_snowflake_client-0.1.0.gem

Usage:

# may raise an IoError if it fails to instantiate or connect
connection = SnowflakeCConnection.new(host, account, 'WH', database, schema, user, password, 'SERVICE_ROLE', timezone_or_nil, port_or_nil)
query = <<~QUERY
  select account_id, order_time, amount 
    from orders where order_time < #{4.hours.ago}
      and shipping_time is null
    order by order_time
QUERY

# read query
status = connection.snowflake_query(query) do |row|
  process_overdue_order(row[0], # account
                        Time.at(row[1]), # order time--all dates and times come back as seconds since epoch
                        row[1])
end
raise status if status  # status either `nil` or sprintf(msg, "%d: %s", error->error_code, error->msg);

# update query (can use for any query where you only care about the number of affected rows)
rows, status = connection.snowflake_update("delete from orders where status = 'cancelled' and order_time < #{1.year.ago}")
if rows
  puts "Deleted #{rows} cancelled orders from over a year ago"
elsif status
  raise status  # error_code: error_msg
end

About

Gem wrapper to enable ruby to use libsnowflakeclient for faster queries

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Makefile 70.2%
  • C 13.6%
  • C++ 6.5%
  • Roff 2.4%
  • Python 1.7%
  • Shell 1.5%
  • Other 4.1%