mobilize-hive 1.351 → 1.352

Sign up to get free protection for your applications and to get access to all the features.
@@ -155,8 +155,8 @@ module Mobilize
155
155
  Gdrive.unslot_worker_by_path(stage_path)
156
156
 
157
157
  #check for select at end
158
- hql_array = hql.split(";").map{|hc| hc.strip}.reject{|hc| hc.length==0}
159
- last_statement = hql_array.last.downcase.split("\n").reject{|l| l.starts_with?("-- ")}.first
158
+ hql_array = hql.downcase.split("\n").reject{|l| l.starts_with?("--") or l.strip.length==0}.join("\n").split(";")
159
+ last_statement = hql_array.last
160
160
  if last_statement.to_s.starts_with?("select")
161
161
  #nil if no prior commands
162
162
  prior_hql = hql_array[0..-2].join(";") if hql_array.length > 1
@@ -209,13 +209,15 @@ module Mobilize
209
209
  schema_hash
210
210
  end
211
211
 
212
- def Hive.hql_to_table(cluster, db, table, part_array, source_hql, user_name, job_name, drop=false, schema_hash=nil, params=nil)
212
+ def Hive.hql_to_table(cluster, db, table, part_array, source_hql, user_name, job_name, drop=false, schema_hash=nil, run_params=nil)
213
213
  table_path = [db,table].join(".")
214
214
  table_stats = Hive.table_stats(cluster, db, table, user_name)
215
215
  url = "hive://" + [cluster,db,table,part_array.compact.join("/")].join("/")
216
216
 
217
- source_hql_array = source_hql.split(";")
218
- last_select_i = source_hql_array.rindex{|hql| hql.downcase.strip.starts_with?("select")}
217
+ #decomment hql
218
+
219
+ source_hql_array = source_hql.downcase.split("\n").reject{|l| l.starts_with?("--") or l.strip.length==0}.join("\n").split(";")
220
+ last_select_i = source_hql_array.rindex{|s| s.starts_with?("select")}
219
221
  #find the last select query -- it should be used for the temp table creation
220
222
  last_select_hql = (source_hql_array[last_select_i..-1].join(";")+";")
221
223
  #if there is anything prior to the last select, add it in prior to table creation
@@ -228,7 +230,7 @@ module Mobilize
228
230
  temp_set_hql = "set mapred.job.name=#{job_name} (temp table);"
229
231
  temp_drop_hql = "drop table if exists #{temp_table_path};"
230
232
  temp_create_hql = "#{temp_set_hql}#{prior_hql}#{temp_drop_hql}create table #{temp_table_path} as #{last_select_hql}"
231
- response = Hive.run(cluster,temp_create_hql,user_name,params)
233
+ response = Hive.run(cluster,temp_create_hql,user_name,run_params)
232
234
  raise response['stderr'] if response['stderr'].to_s.ie{|s| s.index("FAILED") or s.index("KILLED")}
233
235
 
234
236
  source_table_stats = Hive.table_stats(cluster,temp_db,temp_table_name,user_name)
@@ -267,7 +269,7 @@ module Mobilize
267
269
  target_insert_hql,
268
270
  temp_drop_hql].join
269
271
 
270
- response = Hive.run(cluster, target_full_hql, user_name, params)
272
+ response = Hive.run(cluster, target_full_hql, user_name, run_params)
271
273
 
272
274
  raise response['stderr'] if response['stderr'].to_s.ie{|s| s.index("FAILED") or s.index("KILLED")}
273
275
 
@@ -319,7 +321,7 @@ module Mobilize
319
321
  part_set_hql = "set hive.cli.print.header=true;set mapred.job.name=#{job_name} (permutations);"
320
322
  part_select_hql = "select distinct #{target_part_stmt} from #{temp_table_path};"
321
323
  part_perm_hql = part_set_hql + part_select_hql
322
- response = Hive.run(cluster, part_perm_hql, user_name, params)
324
+ response = Hive.run(cluster, part_perm_hql, user_name, run_params)
323
325
  raise response['stderr'] if response['stderr'].to_s.ie{|s| s.index("FAILED") or s.index("KILLED")}
324
326
  part_perm_tsv = response['stdout']
325
327
  #having gotten the permutations, ensure they are dropped
@@ -332,7 +334,7 @@ module Mobilize
332
334
 
333
335
  part_drop_hql = part_hash_array.map do |h|
334
336
  part_drop_stmt = h.map do |name,value|
335
- part_defs[name[1..-2]]=="string" ? "#{name}='#{value}'" : "#{name}=#{value}"
337
+ part_defs[name[1..-2]].downcase=="string" ? "#{name}='#{value}'" : "#{name}=#{value}"
336
338
  end.join(",")
337
339
  "use #{db};alter table #{table} drop if exists partition (#{part_drop_stmt});"
338
340
  end.join
@@ -345,7 +347,7 @@ module Mobilize
345
347
 
346
348
  target_full_hql = [target_set_hql, target_create_hql, target_insert_hql, temp_drop_hql].join
347
349
 
348
- response = Hive.run(cluster, target_full_hql, user_name, params)
350
+ response = Hive.run(cluster, target_full_hql, user_name, run_params)
349
351
  raise response['stderr'] if response['stderr'].to_s.ie{|s| s.index("FAILED") or s.index("KILLED")}
350
352
  else
351
353
  error_msg = "Incompatible partition specs"
@@ -543,7 +545,8 @@ module Mobilize
543
545
  result = begin
544
546
  url = if source_hql
545
547
  #include any params (or nil) at the end
546
- Hive.hql_to_table(cluster, db, table, part_array, source_hql, user_name, job_name, drop, schema_hash,params['params'])
548
+ run_params = params['params']
549
+ Hive.hql_to_table(cluster, db, table, part_array, source_hql, user_name, job_name, drop, schema_hash,run_params)
547
550
  elsif source_tsv
548
551
  Hive.tsv_to_table(cluster, db, table, part_array, source_tsv, user_name, drop, schema_hash)
549
552
  elsif source
@@ -1,5 +1,5 @@
1
1
  module Mobilize
2
2
  module Hive
3
- VERSION = "1.351"
3
+ VERSION = "1.352"
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mobilize-hive
3
3
  version: !ruby/object:Gem::Version
4
- version: '1.351'
4
+ version: '1.352'
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-04-25 00:00:00.000000000 Z
12
+ date: 2013-04-29 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: mobilize-hdfs
@@ -67,7 +67,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
67
67
  version: '0'
68
68
  segments:
69
69
  - 0
70
- hash: -249273093332881580
70
+ hash: 1135176985926667885
71
71
  required_rubygems_version: !ruby/object:Gem::Requirement
72
72
  none: false
73
73
  requirements:
@@ -76,7 +76,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
76
76
  version: '0'
77
77
  segments:
78
78
  - 0
79
- hash: -249273093332881580
79
+ hash: 1135176985926667885
80
80
  requirements: []
81
81
  rubyforge_project:
82
82
  rubygems_version: 1.8.25