Skip to content

Instantly share code, notes, and snippets.

@kikeda1104
Last active July 13, 2018 08:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kikeda1104/da6695ea9d9295cff6c714ec549bc7ca to your computer and use it in GitHub Desktop.
Save kikeda1104/da6695ea9d9295cff6c714ec549bc7ca to your computer and use it in GitHub Desktop.
def call
@conn.exec(ERB.new(erb_template).result(binding))
end
private
def post_initialize(args)
@iam_role = ENV['iam_role']
@conn = Database::Adapter.conn
@directory = Model.to_s.underscore
@bucket_name = ENV['bucket_name']
end
def erb_template
<<-SQL
<% TABLES.each do |table| %>
copy <%= table %>_copy
from 's3://<%= "#{bucket_name}/#{@directory}/#{id}" %>/<%= table %>.txt.'
iam_role '<%= @iam_role %>'
region 'ap-northeast-1'
blanksasnull
emptyasnull
GZIP
delimiter '\t'
NULL AS 'NULL'
;
<% end %>
SQL
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment