class Turboquery::OLAP
Public Class Methods
after_fork()
click to toggle source
# File lib/turboquery/olap.rb, line 29 def self.after_fork AROLAP.connect end
Public Instance Methods
copy_result_to_s3(query)
click to toggle source
# File lib/turboquery/olap.rb, line 6 def copy_result_to_s3(query) key = random_key execute("UNLOAD ('#{query}') TO 's3://#{Turboquery.aws_bucket}/#{key}' #{copy_options};") key end
copy_s3_to_table(key, table)
click to toggle source
# File lib/turboquery/olap.rb, line 12 def copy_s3_to_table(key, table) execute("COPY #{table} FROM 's3://#{Turboquery.aws_bucket}/#{key}manifest' #{copy_options} DATEFORMAT 'auto' TIMEFORMAT 'auto';") end
copy_table_to_s3(table)
click to toggle source
# File lib/turboquery/olap.rb, line 2 def copy_table_to_s3(table) copy_result_to_s3("SELECT * FROM #{table}") end
drop_table(key)
click to toggle source
# File lib/turboquery/olap.rb, line 24 def drop_table(key) sql = "DROP TABLE IF EXISTS #{key}" execute(sql) end
execute_to_temporary_table(query)
click to toggle source
# File lib/turboquery/olap.rb, line 17 def execute_to_temporary_table(query) key = random_key sql = "CREATE TEMPORARY TABLE #{key} AS #{query}" execute(sql) key end
Protected Instance Methods
connection()
click to toggle source
# File lib/turboquery/olap.rb, line 35 def connection AROLAP.connection end
copy_options()
click to toggle source
# File lib/turboquery/olap.rb, line 43 def copy_options "CREDENTIALS 'aws_access_key_id=#{Turboquery.aws_key};aws_secret_access_key=#{Turboquery.aws_secret}' MANIFEST DELIMITER '\\t' NULL AS '\\\\N'" end
excape_single_quotes(str)
click to toggle source
# File lib/turboquery/olap.rb, line 39 def excape_single_quotes(str) str.gsub(/'/, %q(\\\')) end