Class: RedshiftExtractor::Unload

Inherits:
Object
  • Object
show all
Defined in:
lib/redshift_extractor/unload.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(args) ⇒ Unload

Returns a new instance of Unload.



5
6
7
8
9
10
# File 'lib/redshift_extractor/unload.rb', line 5

def initialize(args)
  @aws_access_key_id = args.fetch(:aws_access_key_id)
  @aws_secret_access_key = args.fetch(:aws_secret_access_key)
  @s3_destination = args.fetch(:s3_destination)
  @select_sql = args.fetch(:select_sql)
end

Instance Attribute Details

#aws_access_key_idObject (readonly)

Returns the value of attribute aws_access_key_id.



3
4
5
# File 'lib/redshift_extractor/unload.rb', line 3

def aws_access_key_id
  @aws_access_key_id
end

#aws_secret_access_keyObject (readonly)

Returns the value of attribute aws_secret_access_key.



3
4
5
# File 'lib/redshift_extractor/unload.rb', line 3

def aws_secret_access_key
  @aws_secret_access_key
end

#s3_destinationObject (readonly)

Returns the value of attribute s3_destination.



3
4
5
# File 'lib/redshift_extractor/unload.rb', line 3

def s3_destination
  @s3_destination
end

#select_sqlObject (readonly)

Returns the value of attribute select_sql.



3
4
5
# File 'lib/redshift_extractor/unload.rb', line 3

def select_sql
  @select_sql
end

Instance Method Details

#credentialsObject



21
22
23
# File 'lib/redshift_extractor/unload.rb', line 21

def credentials
  "aws_access_key_id=#{aws_access_key_id};aws_secret_access_key=#{aws_secret_access_key}"
end

#escaped_extract_sqlObject



17
18
19
# File 'lib/redshift_extractor/unload.rb', line 17

def escaped_extract_sql
  select_sql.gsub("'", "\\\\'")
end

#unload_sqlObject



12
13
14
15
# File 'lib/redshift_extractor/unload.rb', line 12

def unload_sql
  "UNLOAD('#{escaped_extract_sql}') to '#{s3_destination}'"\
  " CREDENTIALS '#{credentials}' MANIFEST GZIP ADDQUOTES ESCAPE;"
end