ath 0.1.5 → 0.1.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/ath/driver.rb +21 -17
- data/lib/ath/query.rb +1 -21
- data/lib/ath/shell.rb +1 -1
- data/lib/ath/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c91de42f95791d3fe9be38882ac14ecf0c81618f
|
4
|
+
data.tar.gz: 8ecad5ef8c2818b371117ec83889ba709bd71282
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: fde85f64b72240c7c5d0b0557d711fd623513071775aa0c5d18819545b52fee25081aeecc46b657f6eb9bb110ea54db81bfeb6e8f6b7ca329f3307ef954d820d
|
7
|
+
data.tar.gz: e4d68468a9e5f7ee113cc55dadce6ac431e32fa7c531bd2d7d513f09f6c340200a4e0e9f8554b078a5ac360e4640c0e8414d1aac2c12743b7b205d6328a890bc
|
data/lib/ath/driver.rb
CHANGED
@@ -1,11 +1,12 @@
|
|
1
1
|
class Ath::Driver
|
2
2
|
attr_accessor :database
|
3
3
|
|
4
|
-
def initialize(athena:, s3:, output_location:, database:)
|
4
|
+
def initialize(athena:, s3:, output_location:, database:, options: {})
|
5
5
|
@athena = athena
|
6
6
|
@s3 = s3
|
7
7
|
@output_location = output_location
|
8
8
|
@database = database
|
9
|
+
@options = options
|
9
10
|
end
|
10
11
|
|
11
12
|
def get_query_execution(query_execution_id:)
|
@@ -18,13 +19,27 @@ class Ath::Driver
|
|
18
19
|
end
|
19
20
|
|
20
21
|
def get_query_execution_result(query_execution_id:)
|
21
|
-
|
22
|
+
query_execution = @athena.get_query_execution(query_execution_id: query_execution_id).query_execution
|
23
|
+
output_location = query_execution.result_configuration.output_location
|
24
|
+
bucket, key = output_location.sub(%r{\As3://}, '').split('/', 2)
|
22
25
|
tmp = Tempfile.create('ath')
|
23
26
|
|
24
|
-
if
|
25
|
-
@s3.
|
26
|
-
|
27
|
-
|
27
|
+
if @options[:progress]
|
28
|
+
head = @s3.head_object(bucket: bucket, key: key)
|
29
|
+
download_progressbar = ProgressBar.create(title: 'Download', total: head.content_length, output: $stderr)
|
30
|
+
|
31
|
+
begin
|
32
|
+
@s3.get_object(bucket: bucket, key: key) do |chunk|
|
33
|
+
tmp.write(chunk)
|
34
|
+
|
35
|
+
begin
|
36
|
+
download_progressbar.progress += chunk.length
|
37
|
+
rescue ProgressBar::InvalidProgressError
|
38
|
+
# nothing to do
|
39
|
+
end
|
40
|
+
end
|
41
|
+
ensure
|
42
|
+
download_progressbar.clear
|
28
43
|
end
|
29
44
|
else
|
30
45
|
@s3.get_object(bucket: bucket, key: key) do |chunk|
|
@@ -36,17 +51,6 @@ class Ath::Driver
|
|
36
51
|
tmp
|
37
52
|
end
|
38
53
|
|
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
|
-
|
50
54
|
def start_query_execution(query_string:)
|
51
55
|
@athena.start_query_execution(
|
52
56
|
query_string: query_string,
|
data/lib/ath/query.rb
CHANGED
@@ -42,27 +42,7 @@ class Ath::Query
|
|
42
42
|
end
|
43
43
|
|
44
44
|
if query_execution.status.state == 'SUCCEEDED'
|
45
|
-
|
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
|
45
|
+
@shell.driver.get_query_execution_result(query_execution_id: query_execution_id)
|
66
46
|
else
|
67
47
|
"QueryExecution #{query_execution_id}: #{query_execution.status.state_change_reason}"
|
68
48
|
end
|
data/lib/ath/shell.rb
CHANGED
@@ -7,7 +7,7 @@ class Ath::Shell
|
|
7
7
|
attr_accessor :pager
|
8
8
|
|
9
9
|
def initialize(athena: Aws::Athena::Client.new, s3: Aws::S3::Client.new, output_location:, database: nil, options: {})
|
10
|
-
@driver = Ath::Driver.new(athena: athena, s3: s3, output_location: output_location, database: database)
|
10
|
+
@driver = Ath::Driver.new(athena: athena, s3: s3, output_location: output_location, database: database, options: options)
|
11
11
|
@options = options
|
12
12
|
@scanner = Ath::Scanner.new(shell: self)
|
13
13
|
end
|
data/lib/ath/version.rb
CHANGED