ath 0.1.4 → 0.1.5

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 2e26f04434c7a6c3b7004606b78c59f7607347d7
4
- data.tar.gz: 8df1c34e7d78d1b9d11b329f96234e36e4c6b35d
3
+ metadata.gz: f2e657482ca868e38e2823974acf2d99a7291bc0
4
+ data.tar.gz: fe8561a1ce77cbcee7decdb892ccbde7a0938b95
5
5
  SHA512:
6
- metadata.gz: dfb56ede9208a2cf4ed8602cc46535e70766cf0638f833e30df7390f0f7ab8205276dd26e23f79b2b5aacdecbcf79ca402e6ecea6424669d69dc8814b360a7b0
7
- data.tar.gz: e8b2b7e9fb5420d2f25c70ba01d275eb6493d3a6497b5b8c0e62d44b611e9db659454f40d8228d6483971d4504856bde8c3e5a7f0ca7dfb3c6d39b132568288f
6
+ metadata.gz: 9b80a39f2864d34af1c7c301e64419419b36215a9f04ec48e6bcf7721ab57dd0c68247df901e64d83af5ba1300ca2ecd71116f282102620b241a65bc01b255d6
7
+ data.tar.gz: 718f99c07022cf0305cda6434715f768a13ca11e3e6283f23986d43b200901e9b12b9c87a11dfa408c9cdce319eb1bd0851521fdc56a29843e6a9c6135e43b45
data/README.md CHANGED
@@ -84,6 +84,7 @@ Usage: ath [options]
84
84
  -d, --database DATABASE
85
85
  -e, --execute QUERY
86
86
  -f, --file QUERY_FILR
87
+ --[no-]progress
87
88
  --debug
88
89
  ```
89
90
 
@@ -22,6 +22,7 @@ Gem::Specification.new do |spec|
22
22
  spec.require_paths = ['lib']
23
23
 
24
24
  spec.add_dependency 'aws-sdk', '>= 2.9.21', '< 3'
25
+ spec.add_dependency 'ruby-progressbar'
25
26
  spec.add_development_dependency 'bundler'
26
27
  spec.add_development_dependency 'rake'
27
28
  spec.add_development_dependency 'rspec', '~> 3.0'
data/exe/ath CHANGED
@@ -10,6 +10,7 @@ Version = Ath::VERSION
10
10
  options = {
11
11
  database: 'default',
12
12
  output_location: ENV['ATH_OUTPUT_LOCATION'],
13
+ progress: true,
13
14
  debug: false,
14
15
  }
15
16
 
@@ -30,6 +31,7 @@ ARGV.options do |opt|
30
31
  opt.on('-d', '--database DATABASE') {|v| options[:database] = v }
31
32
  opt.on('-e', '--execute QUERY') {|v| query = v }
32
33
  opt.on('-f', '--file QUERY_FILR') {|v| query_file = v }
34
+ opt.on('', '--[no-]progress') {|v| options[:progress] = v }
33
35
  opt.on('' , '--debug') { options[:debug] = true }
34
36
  opt.parse!
35
37
 
data/lib/ath.rb CHANGED
@@ -3,6 +3,7 @@ require 'strscan'
3
3
  require 'tempfile'
4
4
 
5
5
  require 'aws-sdk'
6
+ require 'ruby-progressbar'
6
7
 
7
8
  require 'ath/version'
8
9
  require 'ath/command'
@@ -18,24 +18,40 @@ class Ath::Driver
18
18
  end
19
19
 
20
20
  def get_query_execution_result(query_execution_id:)
21
- query_execution = @athena.get_query_execution(query_execution_id: query_execution_id).query_execution
22
- output_location = query_execution.result_configuration.output_location
23
- bucket, key = output_location.sub(%r{\As3://}, '').split('/', 2)
21
+ bucket, key = get_query_execution_result_output_location(query_execution_id: query_execution_id)
24
22
  tmp = Tempfile.create('ath')
25
23
 
26
- @s3.get_object(bucket: bucket, key: key) do |chunk|
27
- tmp.write(chunk)
24
+ if block_given?
25
+ @s3.get_object(bucket: bucket, key: key) do |chunk|
26
+ yield(chunk)
27
+ tmp.write(chunk)
28
+ end
29
+ else
30
+ @s3.get_object(bucket: bucket, key: key) do |chunk|
31
+ tmp.write(chunk)
32
+ end
28
33
  end
29
34
 
30
35
  tmp.flush
31
36
  tmp
32
37
  end
33
38
 
39
+ def head_query_execution_result(query_execution_id:)
40
+ bucket, key = get_query_execution_result_output_location(query_execution_id: query_execution_id)
41
+ @s3.head_object(bucket: bucket, key: key)
42
+ end
43
+
44
+ def get_query_execution_result_output_location(query_execution_id:)
45
+ query_execution = @athena.get_query_execution(query_execution_id: query_execution_id).query_execution
46
+ output_location = query_execution.result_configuration.output_location
47
+ output_location.sub(%r{\As3://}, '').split('/', 2)
48
+ end
49
+
34
50
  def start_query_execution(query_string:)
35
51
  @athena.start_query_execution(
36
52
  query_string: query_string,
37
53
  query_execution_context: {database: @database},
38
- result_configuration: { output_location: @output_location})
54
+ result_configuration: {output_location: @output_location})
39
55
  end
40
56
 
41
57
  def stop_query_execution(query_execution_id:)
@@ -15,8 +15,13 @@ class Ath::Query
15
15
  abort_waiting = false
16
16
  orig_handler = trap(:INT, proc { abort_waiting = true })
17
17
  query_execution = nil
18
+ running_progressbar = nil
18
19
 
19
20
  begin
21
+ if @shell.options[:progress]
22
+ running_progressbar = ProgressBar.create(title: 'Running', total: nil, output: $stderr)
23
+ end
24
+
20
25
  until abort_waiting
21
26
  query_execution = @shell.driver.get_query_execution(query_execution_id: query_execution_id)
22
27
 
@@ -24,9 +29,11 @@ class Ath::Query
24
29
  break
25
30
  end
26
31
 
32
+ running_progressbar.increment if running_progressbar
27
33
  sleep 1
28
34
  end
29
35
  ensure
36
+ running_progressbar.clear if running_progressbar
30
37
  trap(:INT, orig_handler)
31
38
  end
32
39
 
@@ -35,7 +42,27 @@ class Ath::Query
35
42
  end
36
43
 
37
44
  if query_execution.status.state == 'SUCCEEDED'
38
- @shell.driver.get_query_execution_result(query_execution_id: query_execution_id)
45
+ head = @shell.driver.head_query_execution_result(query_execution_id: query_execution_id)
46
+ download_progressbar = nil
47
+
48
+ begin
49
+ if @shell.options[:progress]
50
+ download_progressbar = ProgressBar.create(
51
+ title: 'Download',
52
+ total: head.content_length,
53
+ output: $stderr)
54
+ end
55
+
56
+ @shell.driver.get_query_execution_result(query_execution_id: query_execution_id) do |chunk|
57
+ begin
58
+ download_progressbar.progress += chunk.length if download_progressbar
59
+ rescue ProgressBar::InvalidProgressError
60
+ # nothing to do
61
+ end
62
+ end
63
+ ensure
64
+ download_progressbar.clear if download_progressbar
65
+ end
39
66
  else
40
67
  "QueryExecution #{query_execution_id}: #{query_execution.status.state_change_reason}"
41
68
  end
@@ -1,3 +1,3 @@
1
1
  module Ath
2
- VERSION = '0.1.4'
2
+ VERSION = '0.1.5'
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ath
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.4
4
+ version: 0.1.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - winebarrel
@@ -30,6 +30,20 @@ dependencies:
30
30
  - - "<"
31
31
  - !ruby/object:Gem::Version
32
32
  version: '3'
33
+ - !ruby/object:Gem::Dependency
34
+ name: ruby-progressbar
35
+ requirement: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - ">="
38
+ - !ruby/object:Gem::Version
39
+ version: '0'
40
+ type: :runtime
41
+ prerelease: false
42
+ version_requirements: !ruby/object:Gem::Requirement
43
+ requirements:
44
+ - - ">="
45
+ - !ruby/object:Gem::Version
46
+ version: '0'
33
47
  - !ruby/object:Gem::Dependency
34
48
  name: bundler
35
49
  requirement: !ruby/object:Gem::Requirement