Class: RedshiftConnector::UnloadQuery
- Inherits:
-
Object
- Object
- RedshiftConnector::UnloadQuery
- Defined in:
- lib/redshift_connector/query.rb
Class Method Summary collapse
Instance Method Summary collapse
- #description ⇒ Object
- #escape_query(query) ⇒ Object
-
#initialize(query:, bundle:, enable_sort: false) ⇒ UnloadQuery
constructor
A new instance of UnloadQuery.
- #table_spec ⇒ Object
- #to_sql ⇒ Object
Constructor Details
#initialize(query:, bundle:, enable_sort: false) ⇒ UnloadQuery
Returns a new instance of UnloadQuery.
51 52 53 54 55 |
# File 'lib/redshift_connector/query.rb', line 51 def initialize(query:, bundle:, enable_sort: false) @query = query @bundle = bundle @enable_sort = enable_sort end |
Class Method Details
.wrap(query:, bundle:, enable_sort: false) ⇒ Object
47 48 49 |
# File 'lib/redshift_connector/query.rb', line 47 def UnloadQuery.wrap(query:, bundle:, enable_sort: false) new(query: ArbitraryQuery.new(query), bundle: bundle, enable_sort: enable_sort) end |
Instance Method Details
#description ⇒ Object
61 62 63 |
# File 'lib/redshift_connector/query.rb', line 61 def description @query.description end |
#escape_query(query) ⇒ Object
77 78 79 |
# File 'lib/redshift_connector/query.rb', line 77 def escape_query(query) query.gsub("'", "\\\\'") end |
#table_spec ⇒ Object
57 58 59 |
# File 'lib/redshift_connector/query.rb', line 57 def table_spec @query.table_spec end |
#to_sql ⇒ Object
65 66 67 68 69 70 71 72 73 74 75 |
# File 'lib/redshift_connector/query.rb', line 65 def to_sql <<-EndSQL.gsub(/^\s+/, '') unload ('#{escape_query(@query.to_sql)}') to '#{@bundle.url}' credentials '#{@bundle.credential_string}' gzip allowoverwrite parallel #{@enable_sort ? 'off' : 'on'} delimiter ',' escape addquotes EndSQL end |