ath 0.2.4 → 0.2.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: 399f1d61c2594b897dfaa078b3a37efcf845e4d4
4
- data.tar.gz: 991941010b0cdc593d03b8cdb90c7661e0626c60
3
+ metadata.gz: d5a50c633facd053d721acff0fb97f8f5d0adb82
4
+ data.tar.gz: dc576e3a4548ac632b145281aa0e0786252bf6e7
5
5
  SHA512:
6
- metadata.gz: 5ab2de1eeee5ecbf2e56995c0bac3681e2438fd984404a141c8f0cc0dfc7f3f094db60e07b4db565a6a7c3218a1db9402e893c97137056d6f7adb25ee96adcaa
7
- data.tar.gz: 27e37541d13f6fa18626be07a33a846d5bda8b43bbda8f3083362eacfbebf0c2044aa5c922287bb1a501003cb1c8cb07ee3dee00edbbed4ddaaf498d5c15ac61
6
+ metadata.gz: bc8524c18109b05bc5610749434381dea009e13dd18e3d23a73e6b0f0f2eec0897302ae9df8e09a42da737ee7cfaf3b193d1a6dbb73953856ab684732a8f3a45
7
+ data.tar.gz: 737154660475921c40bd7fcea791dab6ac87c95ad26d59cde4c857381582a13b5e195d1b44c145b4ff16f44f0afc4a81cf23f87ca36d013423a2503c50c2d015
data/README.md CHANGED
@@ -2,6 +2,8 @@
2
2
 
3
3
  ath is a interactive [Amazon Athena](https://aws.amazon.com/athena/) shell.
4
4
 
5
+ [![Gem Version](https://badge.fury.io/rb/ath.svg)](https://badge.fury.io/rb/ath)
6
+
5
7
  [![asciicast](https://asciinema.org/a/127476.png)](https://asciinema.org/a/127476)
6
8
 
7
9
  ## Installation
@@ -44,7 +46,11 @@ sampledb> select * from elb_logs limit 3;
44
46
  "2015-01-01T08:00:00.516940Z","elb_demo_009","240.136.98.149","25858","172.51.67.62","8888","9.99E-4","8.11E-4","0.001561","200","200","0","428","GET","https://www.example.com/articles/746","HTTP/1.1","""Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_6) AppleWebKit/602.1.50 (KHTML, like Gecko) Version/10.0 Safari/602.1.50""","DHE-RSA-AES128-SHA","TLSv1.2"
45
47
  "2015-01-01T08:00:00.902953Z","elb_demo_008","244.46.184.108","27758","172.31.168.31","443","6.39E-4","0.001471","3.73E-4","200","200","0","4231","GET","https://www.example.com/jobs/688","HTTP/1.1","""Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:15.0) Gecko/20100101 Firefox/15.0.1""","DHE-RSA-AES128-SHA","TLSv1.2"
46
48
  "2015-01-01T08:00:01.206255Z","elb_demo_008","240.120.203.212","26378","172.37.170.107","8888","0.001174","4.97E-4","4.89E-4","200","200","0","2075","GET","http://www.example.com/articles/290","HTTP/1.1","""Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/42.0.2311.135 Safari/537.36 Edge/12.246""","-","-"
49
+ ```
47
50
 
51
+ ### Detach Query
52
+
53
+ ```sh
48
54
  sampledb> select * from elb_logs limit 3 &
49
55
  QueryExecution 2335c77b-d138-4c5d-89df-12f2781c311b
50
56
 
@@ -74,7 +80,11 @@ sampledb> /result 2335c77b-d138-4c5d-89df-12f2781c311b
74
80
  "2015-01-01T16:00:00.516940Z","elb_demo_009","242.76.140.141","18201","172.42.159.57","80","0.001448","8.46E-4","9.97E-4","302","302","0","2911","GET","https://www.example.com/articles/817","HTTP/1.1","""Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:15.0) Gecko/20100101 Firefox/15.0.1""","DHE-RSA-AES128-SHA","TLSv1.2"
75
81
  "2015-01-01T16:00:00.902953Z","elb_demo_005","246.233.91.115","1950","172.42.232.155","8888","9.59E-4","0.001703","8.93E-4","200","200","0","3027","GET","http://www.example.com/jobs/509","HTTP/1.1","""Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_6) AppleWebKit/602.1.50 (KHTML, like Gecko) Version/10.0 Safari/602.1.50""","-","-"
76
82
  "2015-01-01T16:00:01.206255Z","elb_demo_002","250.96.73.238","12800","172.34.87.144","80","0.001549","9.68E-4","0.001908","200","200","0","888","GET","http://www.example.com/articles/729","HTTP/1.1","""Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/42.0.2311.135 Safari/537.36 Edge/12.246""","-","-"
83
+ ```
84
+
85
+ ### Use Pager
77
86
 
87
+ ```sh
78
88
  sampledb> /pager column -t -s,
79
89
 
80
90
  sampledb> select elb_name, count(*) from elb_logs group by elb_name;
@@ -88,7 +98,11 @@ sampledb> select elb_name, count(*) from elb_logs group by elb_name;
88
98
  "elb_demo_004" "151062"
89
99
  "elb_demo_002" "151284"
90
100
  "elb_demo_003" "148761"
101
+ ```
102
+
103
+ ### Save Result
91
104
 
105
+ ```sh
92
106
  sampledb> /list 1
93
107
  2017-07-03 20:52:24 +0900 cf881630-a845-424a-8035-afe155505cac SUCCEEDED select elb_name cou..
94
108
 
@@ -96,10 +110,17 @@ default> /save cf881630-a845-424a-8035-afe155505cac
96
110
  Save to /Users/.../cf881630-a845-424a-8035-afe155505cac.csv
97
111
  ```
98
112
 
113
+ ### Input Query from File
114
+
99
115
  ```sh
100
116
  $ echo 'select count(*) from elb_logs' | ath -d sampledb -f -
101
117
  "_col0"
102
118
  "1356206"
119
+
120
+ $ echo 'select count(*) from elb_logs' > count.sql
121
+ $ ath -d sampledb -f count.sql
122
+ "_col0"
123
+ "1356206"
103
124
  ```
104
125
 
105
126
  ## Usage
data/exe/ath CHANGED
@@ -1,99 +1,6 @@
1
1
  #!/usr/bin/env ruby
2
2
  $LOAD_PATH << File.expand_path('../../lib', __FILE__)
3
3
 
4
- require 'logger'
5
- require 'optparse'
6
4
  require 'ath'
7
-
8
5
  Version = Ath::VERSION
9
-
10
- options = {
11
- database: 'default',
12
- output_location: ENV['ATH_OUTPUT_LOCATION'],
13
- pager: ENV['ATH_PAGER'],
14
- debug: false,
15
- }
16
-
17
- query = nil
18
- query_file = nil
19
-
20
- ARGV.options do |opt|
21
- aws_opts = {}
22
- creds_opts = {}
23
-
24
- begin
25
- opt.on('-p', '--profile PROFILE_NAME') {|v| creds_opts[:profile_name] = v }
26
- opt.on('' , '--credentials-path PATH') {|v| creds_opts[:path] = v }
27
- opt.on('-k', '--access-key ACCESS_KEY') {|v| aws_opts[:access_key] = v }
28
- opt.on('-s', '--secret-key SECRET_KEY') {|v| aws_opts[:secret_access_key] = v }
29
- opt.on('-r', '--region REGION') {|v| aws_opts[:region] = v }
30
- opt.on('' , '--output-location S3URI') {|v| options[:output_location] = v }
31
- opt.on('-d', '--database DATABASE') {|v| options[:database] = v }
32
- opt.on('-e', '--execute QUERY') {|v| query = v }
33
- opt.on('-f', '--file QUERY_FILE') {|v| query_file = v }
34
- opt.on('', '--pager PAGER') {|v| options[:pager] = v }
35
- opt.on('', '--[no-]progress') {|v| options[:progress] = v }
36
- opt.on('' , '--debug') { options[:debug] = true }
37
- opt.parse!
38
-
39
- unless options[:output_location]
40
- raise Ath::Error, '"--output-location" or ATH_OUTPUT_LOCATION is required'
41
- end
42
-
43
- if not creds_opts.empty?
44
- creds = Aws::SharedCredentials.new(credentials_opts)
45
- aws_opts[:credentials] = creds
46
- end
47
-
48
- Aws.config.update(aws_opts)
49
- rescue Ath::Error, OptionParser::ParseError => e
50
- $stderr.puts("[ERROR] #{e.message}")
51
- exit 1
52
- rescue => e
53
- $stderr.puts("[ERROR] #{e.message}")
54
- puts "\t" + e.backtrace.join("\n\t")
55
- exit 1
56
- end
57
- end
58
-
59
- if options[:debug]
60
- Aws.config.update(
61
- http_wire_trace: true,
62
- logger: Logger.new($stdout).tap {|l| l.level = Logger::DEBUG },
63
- )
64
- end
65
-
66
- begin
67
- shell = Ath::Shell.new(
68
- output_location: options.delete(:output_location),
69
- database: options.delete(:database),
70
- pager: options.delete(:pager),
71
- options: options)
72
-
73
- if query_file
74
- if query_file == '-'
75
- query = $stdin.read
76
- else
77
- query = File.read(query_file)
78
- end
79
- end
80
-
81
- if query
82
- options[:progress] = false unless options.has_key?(:progress)
83
- query.strip!
84
- query << ';' if query !~ /[;&]\z/
85
- shell.oneshot(query)
86
- else
87
- options[:progress] = true unless options.has_key?(:progress)
88
- shell.start
89
- end
90
- rescue Interrupt
91
- # nothing to do
92
- rescue => e
93
- if options[:debug]
94
- raise e
95
- else
96
- $stderr.puts("[ERROR] #{[e.message, e.backtrace.first].join("\n\t")}")
97
- exit 1
98
- end
99
- end
6
+ Ath::CLI.new(argv: ARGV).main
data/lib/ath.rb CHANGED
@@ -1,3 +1,6 @@
1
+ require 'erb'
2
+ require 'logger'
3
+ require 'optparse'
1
4
  require 'readline'
2
5
  require 'strscan'
3
6
  require 'tempfile'
@@ -6,6 +9,7 @@ require 'aws-sdk'
6
9
  require 'ruby-progressbar'
7
10
 
8
11
  require 'ath/version'
12
+ require 'ath/cli'
9
13
  require 'ath/command'
10
14
  require 'ath/driver'
11
15
  require 'ath/error'
@@ -0,0 +1,104 @@
1
+ class Ath::CLI
2
+ def initialize(argv:)
3
+ @argv = argv
4
+ end
5
+
6
+ def parse_options
7
+ options = {
8
+ database: 'default',
9
+ output_location: ENV['ATH_OUTPUT_LOCATION'],
10
+ pager: ENV['ATH_PAGER'],
11
+ debug: false,
12
+ }
13
+
14
+ query = nil
15
+ query_file = nil
16
+
17
+ @argv.options do |opt|
18
+ aws_opts = {}
19
+ creds_opts = {}
20
+
21
+ begin
22
+ opt.on('-p', '--profile PROFILE_NAME') {|v| creds_opts[:profile_name] = v }
23
+ opt.on('' , '--credentials-path PATH') {|v| creds_opts[:path] = v }
24
+ opt.on('-k', '--access-key ACCESS_KEY') {|v| aws_opts[:access_key] = v }
25
+ opt.on('-s', '--secret-key SECRET_KEY') {|v| aws_opts[:secret_access_key] = v }
26
+ opt.on('-r', '--region REGION') {|v| aws_opts[:region] = v }
27
+ opt.on('' , '--output-location S3URI') {|v| options[:output_location] = v }
28
+ opt.on('-d', '--database DATABASE') {|v| options[:database] = v }
29
+ opt.on('-e', '--execute QUERY') {|v| query = v }
30
+ opt.on('-f', '--file QUERY_FILE') {|v| query_file = v }
31
+ opt.on('', '--pager PAGER') {|v| options[:pager] = v }
32
+ opt.on('', '--[no-]progress') {|v| options[:progress] = v }
33
+ opt.on('' , '--debug') { options[:debug] = true }
34
+ opt.parse!
35
+
36
+ unless options[:output_location]
37
+ raise Ath::Error, '"--output-location" or ATH_OUTPUT_LOCATION is required'
38
+ end
39
+
40
+ if not creds_opts.empty?
41
+ creds = Aws::SharedCredentials.new(credentials_opts)
42
+ aws_opts[:credentials] = creds
43
+ end
44
+
45
+ Aws.config.update(aws_opts)
46
+ rescue Ath::Error, OptionParser::ParseError => e
47
+ $stderr.puts("[ERROR] #{e.message}")
48
+ exit 1
49
+ rescue => e
50
+ $stderr.puts("[ERROR] #{e.message}")
51
+ puts "\t" + e.backtrace.join("\n\t")
52
+ exit 1
53
+ end
54
+ end
55
+
56
+ if options[:debug]
57
+ Aws.config.update(
58
+ http_wire_trace: true,
59
+ logger: Logger.new($stdout).tap {|l| l.level = Logger::DEBUG },
60
+ )
61
+ end
62
+
63
+ options[:output_location] = ERB.new(options[:output_location]).result
64
+
65
+ return [options, query, query_file]
66
+ end
67
+
68
+ def main
69
+ options, query, query_file = parse_options
70
+
71
+ shell = Ath::Shell.new(
72
+ output_location: options.delete(:output_location),
73
+ database: options.delete(:database),
74
+ pager: options.delete(:pager),
75
+ options: options)
76
+
77
+ if query_file
78
+ if query_file == '-'
79
+ query = $stdin.read
80
+ else
81
+ query = File.read(query_file)
82
+ end
83
+ end
84
+
85
+ if query
86
+ options[:progress] = false unless options.has_key?(:progress)
87
+ query.strip!
88
+ query << ';' if query !~ /[;&]\z/
89
+ shell.oneshot(query)
90
+ else
91
+ options[:progress] = true unless options.has_key?(:progress)
92
+ shell.start
93
+ end
94
+ rescue Interrupt
95
+ # nothing to do
96
+ rescue => e
97
+ if options[:debug]
98
+ raise e
99
+ else
100
+ $stderr.puts("[ERROR] #{[e.message, e.backtrace.first].join("\n\t")}")
101
+ exit 1
102
+ end
103
+ end
104
+ end
@@ -1,3 +1,3 @@
1
1
  module Ath
2
- VERSION = '0.2.4'
2
+ VERSION = '0.2.5'
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ath
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.4
4
+ version: 0.2.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - winebarrel
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2017-07-03 00:00:00.000000000 Z
11
+ date: 2017-07-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: aws-sdk
@@ -107,6 +107,7 @@ files:
107
107
  - bin/setup
108
108
  - exe/ath
109
109
  - lib/ath.rb
110
+ - lib/ath/cli.rb
110
111
  - lib/ath/command.rb
111
112
  - lib/ath/driver.rb
112
113
  - lib/ath/error.rb