ath 0.1.9 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/22b39199-4070-4100-abed-c7bb63c13d3b.txt +2 -0
- data/README.md +1 -0
- data/lib/ath/command.rb +10 -0
- data/lib/ath/driver.rb +29 -7
- data/lib/ath/scanner.rb +1 -1
- data/lib/ath/version.rb +1 -1
- metadata +2 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 21a47438e2f1e99a854aa23c1bd7301e217e3266
|
4
|
+
data.tar.gz: 014b49b565e36d3ca64e4e5f3c7c5ab1de54e0b1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e59acba379c679e781eef4a4324e38a8ff5b69962d91c6fa4bd5abda578405dbbe8dfa1848a590251e25ec813ce3335f72df4a83e144171474f68e20a549c743
|
7
|
+
data.tar.gz: faa08d22bb15c6bcad6fbe1477ade5b1247e1bc57c52823358bf286dc62e9db2f766882d607c8437ba1985d8cc4b3babcded8c2f2c36bd44d7d3cdf10ed9874a
|
data/README.md
CHANGED
data/lib/ath/command.rb
CHANGED
@@ -76,6 +76,15 @@ class Ath::Command
|
|
76
76
|
else
|
77
77
|
out = "Usage: /result QUERY_EXECUTION_ID"
|
78
78
|
end
|
79
|
+
when 'save'
|
80
|
+
if @arg
|
81
|
+
query_execution_id, path = @arg.split(/\s+/, 2)
|
82
|
+
path ||= Dir.pwd
|
83
|
+
path = @shell.driver.save_query_execution_result(query_execution_id: query_execution_id, path: path)
|
84
|
+
out = "Save to #{path}"
|
85
|
+
else
|
86
|
+
out = "Usage: /result QUERY_EXECUTION_ID [PATH]"
|
87
|
+
end
|
79
88
|
when 'stop'
|
80
89
|
if @arg
|
81
90
|
@shell.driver.stop_query_execution(query_execution_id: @arg)
|
@@ -107,6 +116,7 @@ class Ath::Command
|
|
107
116
|
/pager PAGER
|
108
117
|
/region [REGION]
|
109
118
|
/result QUERY_EXECUTION_ID
|
119
|
+
/save QUERY_EXECUTION_ID [PATH]
|
110
120
|
/stop QUERY_EXECUTION_ID
|
111
121
|
/use DATABASE
|
112
122
|
EOS
|
data/lib/ath/driver.rb
CHANGED
@@ -19,10 +19,26 @@ class Ath::Driver
|
|
19
19
|
end
|
20
20
|
|
21
21
|
def get_query_execution_result(query_execution_id:)
|
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)
|
25
22
|
tmp = Tempfile.create('ath')
|
23
|
+
bucket, key = get_query_execution_result_output_location(query_execution_id: query_execution_id)
|
24
|
+
download_query_execution_result(bucket: bucket, key: key, file: tmp)
|
25
|
+
end
|
26
|
+
|
27
|
+
def save_query_execution_result(query_execution_id:, path:)
|
28
|
+
bucket, key = get_query_execution_result_output_location(query_execution_id: query_execution_id)
|
29
|
+
|
30
|
+
if File.directory?(path)
|
31
|
+
path = File.join(path, File.basename(key))
|
32
|
+
end
|
33
|
+
|
34
|
+
open(path, 'wb') do |file|
|
35
|
+
download_query_execution_result(bucket: bucket, key: key, file: file)
|
36
|
+
end
|
37
|
+
|
38
|
+
path
|
39
|
+
end
|
40
|
+
|
41
|
+
def download_query_execution_result(bucket:, key:, file:)
|
26
42
|
head = @s3.head_object(bucket: bucket, key: key)
|
27
43
|
|
28
44
|
if @options[:progress] and head.content_length >= 1024 ** 2
|
@@ -30,7 +46,7 @@ class Ath::Driver
|
|
30
46
|
|
31
47
|
begin
|
32
48
|
@s3.get_object(bucket: bucket, key: key) do |chunk|
|
33
|
-
|
49
|
+
file.write(chunk)
|
34
50
|
|
35
51
|
begin
|
36
52
|
download_progressbar.progress += chunk.length
|
@@ -43,12 +59,18 @@ class Ath::Driver
|
|
43
59
|
end
|
44
60
|
else
|
45
61
|
@s3.get_object(bucket: bucket, key: key) do |chunk|
|
46
|
-
|
62
|
+
file.write(chunk)
|
47
63
|
end
|
48
64
|
end
|
49
65
|
|
50
|
-
|
51
|
-
|
66
|
+
file.flush
|
67
|
+
file
|
68
|
+
end
|
69
|
+
|
70
|
+
def get_query_execution_result_output_location(query_execution_id:)
|
71
|
+
query_execution = @athena.get_query_execution(query_execution_id: query_execution_id).query_execution
|
72
|
+
output_location = query_execution.result_configuration.output_location
|
73
|
+
output_location.sub(%r{\As3://}, '').split('/', 2)
|
52
74
|
end
|
53
75
|
|
54
76
|
def start_query_execution(query_string:)
|
data/lib/ath/scanner.rb
CHANGED
@@ -8,7 +8,7 @@ class Ath::Scanner
|
|
8
8
|
ss = StringScanner.new(line)
|
9
9
|
|
10
10
|
if self.empty? and (tok = ss.scan %r{/\w+(?:\s+.*)?\z})
|
11
|
-
cmd, arg = tok.split(/\s+/, 2)
|
11
|
+
cmd, arg = tok.strip.split(/\s+/, 2)
|
12
12
|
cmd.slice!(0)
|
13
13
|
arg.strip! if arg
|
14
14
|
yield(Ath::Command.new(shell: @shell, command: cmd, arg: arg))
|
data/lib/ath/version.rb
CHANGED
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.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- winebarrel
|
@@ -97,6 +97,7 @@ files:
|
|
97
97
|
- ".gitignore"
|
98
98
|
- ".rspec"
|
99
99
|
- ".travis.yml"
|
100
|
+
- 22b39199-4070-4100-abed-c7bb63c13d3b.txt
|
100
101
|
- Gemfile
|
101
102
|
- LICENSE.txt
|
102
103
|
- README.md
|