Class: RedshiftConnector::UnloadQuery

Inherits:
Object
  • Object
show all
Defined in:
lib/redshift-connector/query.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(query:, bundle:) ⇒ UnloadQuery

Returns a new instance of UnloadQuery.



51
52
53
54
# File 'lib/redshift-connector/query.rb', line 51

def initialize(query:, bundle:)
  @query = query
  @bundle = bundle
end

Class Method Details

.wrap(query:, bundle:) ⇒ Object



47
48
49
# File 'lib/redshift-connector/query.rb', line 47

def UnloadQuery.wrap(query:, bundle:)
  new(query: ArbitraryQuery.new(query), bundle: bundle)
end

Instance Method Details

#descriptionObject



60
61
62
# File 'lib/redshift-connector/query.rb', line 60

def description
  @query.description
end

#escape_query(query) ⇒ Object



75
76
77
# File 'lib/redshift-connector/query.rb', line 75

def escape_query(query)
  query.gsub("'", "\\\\'")
end

#table_specObject



56
57
58
# File 'lib/redshift-connector/query.rb', line 56

def table_spec
  @query.table_spec
end

#to_sqlObject



64
65
66
67
68
69
70
71
72
73
# File 'lib/redshift-connector/query.rb', line 64

def to_sql
  <<-EndSQL.gsub(/^\s+/, '')
    unload ('#{escape_query(@query.to_sql)}')
    to '#{@bundle.url}'
    credentials '#{@bundle.credential_string}'
    gzip
    allowoverwrite
    delimiter ',' escape addquotes
  EndSQL
end