Class: FlareUp::CopyCommand
- Inherits:
-
Object
- Object
- FlareUp::CopyCommand
- Defined in:
- lib/flare_up/copy_command.rb
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.
-
#table_name ⇒ Object
readonly
Returns the value of attribute table_name.
Instance Method Summary collapse
- #execute(connection) ⇒ Object
- #get_command ⇒ Object
-
#initialize(table_name, data_source, aws_access_key_id, aws_secret_access_key) ⇒ CopyCommand
constructor
A new instance of CopyCommand.
Constructor Details
#initialize(table_name, data_source, aws_access_key_id, aws_secret_access_key) ⇒ CopyCommand
Returns a new instance of CopyCommand.
21 22 23 24 25 26 27 28 |
# File 'lib/flare_up/copy_command.rb', line 21 def initialize(table_name, data_source, aws_access_key_id, aws_secret_access_key) @table_name = table_name @data_source = data_source @aws_access_key_id = aws_access_key_id @aws_secret_access_key = aws_secret_access_key @columns = [] @options = '' end |
Instance Attribute Details
#aws_access_key_id ⇒ Object (readonly)
Returns the value of attribute aws_access_key_id.
16 17 18 |
# File 'lib/flare_up/copy_command.rb', line 16 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.
17 18 19 |
# File 'lib/flare_up/copy_command.rb', line 17 def aws_secret_access_key @aws_secret_access_key end |
#columns ⇒ Object
Returns the value of attribute columns.
18 19 20 |
# File 'lib/flare_up/copy_command.rb', line 18 def columns @columns end |
#data_source ⇒ Object (readonly)
Returns the value of attribute data_source.
15 16 17 |
# File 'lib/flare_up/copy_command.rb', line 15 def data_source @data_source end |
#options ⇒ Object
Returns the value of attribute options.
19 20 21 |
# File 'lib/flare_up/copy_command.rb', line 19 def @options end |
#table_name ⇒ Object (readonly)
Returns the value of attribute table_name.
14 15 16 |
# File 'lib/flare_up/copy_command.rb', line 14 def table_name @table_name end |
Instance Method Details
#execute(connection) ⇒ Object
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/flare_up/copy_command.rb', line 39 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
30 31 32 |
# File 'lib/flare_up/copy_command.rb', line 30 def get_command "COPY #{@table_name} #{get_columns} FROM '#{@data_source}' CREDENTIALS '#{get_credentials}' #{@options}" end |