Module: ActiveRecord::QueryMethods

Defined in:
lib/monkeypatch_activerecord.rb,
lib/monkeypatch_activerecord.rb

Defined Under Namespace

Modules: CopyUnloadParser

Constant Summary collapse

VALID_UNLOAD_SWITCHES =

UNLOAD (‘select_statement’) TO ‘s3_path’

WITH

CREDENTIALS [AS] ‘aws_access_credentials’

option [ …

]

where option is

{ DELIMITER [ AS ] ‘delimiter_char’ | FIXEDWIDTH [ AS ] ‘fixedwidth_spec’ }

| ENCRYPTED | GZIP

| ADDQUOTES | NULL [ AS ] ‘null_string’ | ESCAPE | ALLOWOVERWRITE

[
 :gzip,
 :addquotes,
 :escape,
 :allowoverwrite
]
VALID_UNLOAD_OPTIONS =
[
 :delimiter,
 :fixedwidth,
 :null
]
VALID_UNQUOTED_UNLOAD_OPTIONS =
[ ]
VALID_SPECIAL_UNLOAD_OPTIONS =
[
 :credentials,
 :aws_access_key_id,
 :aws_secret_access_key,
 :master_symmetric_key,
 :token
]
VALID_COPY_SWITCHES =
[
 :encrypted,
 :gzip,
 :removequotes,
 :explicit_ids,
 :escape,
 :acceptanydate,
 :ignoreblanklines,
 :truncatecolumns,
 :fillrecord,
 :trimblanks,
 :noload,
 :emptyasnull,
 :blanksasnull,
 :escape,
 :roundec
]
VALID_COPY_OPTIONS =
[
 :delimiter,
 :fixedwidth,
 :csv,
 :acceptinvchars,
 :dateformat,
 :timeformat,
 :null
]
VALID_UNQUOTED_COPY_OPTIONS =
[
 :maxerror,
 :ignoreheader,
 :comprows,
 :compupdate,
 :statupdate
]
VALID_SPECIAL_COPY_OPTIONS =
[
 :credentials,
 :aws_access_key_id,
 :aws_secret_access_key,
 :master_symmetric_key,
 :token
]

Instance Method Summary collapse

Instance Method Details

#copy(to_s3_filename, *options) ⇒ Object

| ACCEPTINVCHARS [ AS ] [‘replacement_char’] | MAXERROR [ AS ] error_count | DATEFORMAT [ AS ] { ‘dateformat_string’ | ‘auto’ } | TIMEFORMAT [ AS ] { ‘timeformat_string’ | ‘auto’ | ‘epochsecs’ | ‘epochmillisecs’ } | IGNOREHEADER [ AS ] number_rows | ACCEPTANYDATE | IGNOREBLANKLINES | TRUNCATECOLUMNS | FILLRECORD | TRIMBLANKS | NOLOAD | NULL [ AS ] ‘null_string’ | EMPTYASNULL | BLANKSASNULL | COMPROWS numrows | COMPUPDATE [ { ON | TRUE } | { OFF | FALSE } ] | STATUPDATE [ { ON | TRUE } | { OFF | FALSE } ] | ESCAPE | ROUNDEC



180
181
182
183
184
185
186
187
188
189
190
191
192
193
# File 'lib/monkeypatch_activerecord.rb', line 180

def copy(to_s3_filename, *options)
  if options.last.is_a? Hash
    options_hash = options.last
  else
    options_hash = {}
  end

  credentials, copy_options =
    ::ActiveRecord::QueryMethods::CopyUnloadParser.parse_options(options, options_hash,
                                                                 VALID_COPY_SWITCHES, VALID_COPY_OPTIONS, VALID_UNQUOTED_COPY_OPTIONS, VALID_SPECIAL_COPY_OPTIONS)


  conncection.execute(Arel::Nodes::CopyStatement.new(Arel::Nodes::Copy.new(table_name, to_s3_filename), copy_options.join(" ")).to_sql)
end

#unload(to_s3_filename, *options) ⇒ Object



86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
# File 'lib/monkeypatch_activerecord.rb', line 86

def unload(to_s3_filename, *options)
  if options.last.is_a? Hash
    options_hash = options.last
  else
    options_hash = {}
  end

  credentials, unload_options =
    ActiveRecord::QueryMethods::CopyUnloadParser.parse_options(options, options_hash,
                                                               VALID_UNLOAD_SWITCHES, VALID_UNLOAD_OPTIONS, VALID_UNQUOTED_UNLOAD_OPTIONS, VALID_SPECIAL_UNLOAD_OPTIONS)


  relation = Arel::Nodes::UnloadStatement.new(Arel::Nodes::Unload.new(Arel::Nodes::Relation.new(clone), to_s3_filename), unload_options.join(" "))
  relation
end