Class: FlareUp::Command::Copy
Instance Attribute Summary collapse
-
#aws_access_key_id ⇒ Object
readonly
Returns the value of attribute aws_access_key_id.
-
#aws_secret_access_key ⇒ Object
readonly
Returns the value of attribute aws_secret_access_key.
-
#columns ⇒ Object
Returns the value of attribute columns.
-
#data_source ⇒ Object
readonly
Returns the value of attribute data_source.
-
#options ⇒ Object
Returns the value of attribute options.
Attributes inherited from Base
Instance Method Summary collapse
- #execute(connection) ⇒ Object
- #get_command ⇒ Object
-
#initialize(table_name, data_source, aws_access_key_id, aws_secret_access_key) ⇒ Copy
constructor
A new instance of Copy.
Constructor Details
#initialize(table_name, data_source, aws_access_key_id, aws_secret_access_key) ⇒ Copy
Returns a new instance of Copy.
11 12 13 14 15 16 17 18 |
# File 'lib/flare_up/command/copy.rb', line 11 def initialize(table_name, data_source, aws_access_key_id, aws_secret_access_key) @data_source = data_source @aws_access_key_id = aws_access_key_id @aws_secret_access_key = aws_secret_access_key = '' @columns = [] super end |
Instance Attribute Details
#aws_access_key_id ⇒ Object (readonly)
Returns the value of attribute aws_access_key_id.
6 7 8 |
# File 'lib/flare_up/command/copy.rb', line 6 def aws_access_key_id @aws_access_key_id end |
#aws_secret_access_key ⇒ Object (readonly)
Returns the value of attribute aws_secret_access_key.
7 8 9 |
# File 'lib/flare_up/command/copy.rb', line 7 def aws_secret_access_key @aws_secret_access_key end |
#columns ⇒ Object
Returns the value of attribute columns.
9 10 11 |
# File 'lib/flare_up/command/copy.rb', line 9 def columns @columns end |
#data_source ⇒ Object (readonly)
Returns the value of attribute data_source.
5 6 7 |
# File 'lib/flare_up/command/copy.rb', line 5 def data_source @data_source end |
#options ⇒ Object
Returns the value of attribute options.
8 9 10 |
# File 'lib/flare_up/command/copy.rb', line 8 def end |
Instance Method Details
#execute(connection) ⇒ Object
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/flare_up/command/copy.rb', line 30 def execute(connection) begin connection.execute(get_command) [] rescue PG::InternalError => e case e. when /Check 'stl_load_errors' system table for details/ return STLLoadErrorFetcher.fetch_errors(connection) when /The specified S3 prefix '.+' does not exist/ raise DataSourceError, "A data source with prefix '#{@data_source}' does not exist." when /The bucket you are attempting to access must be addressed using the specified endpoint/ raise OtherZoneBucketError, "Your Redshift instance appears to be in a different zone than your S3 bucket. Specify the \"REGION 'bucket-region'\" option." when /PG::SyntaxError/ matches = /syntax error (.+) \(PG::SyntaxError\)/.match(e.) raise SyntaxError, "Syntax error in the COPY command: [#{matches[1]}]." else raise e end end end |
#get_command ⇒ Object
21 22 23 |
# File 'lib/flare_up/command/copy.rb', line 21 def get_command "COPY #{@table_name} #{get_columns} FROM '#{@data_source}' CREDENTIALS '#{get_credentials}' #{@options}" end |