ath 0.1.2 → 0.1.3

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: ac2048d603b91207098eaf1e020d539a909ff227
4
- data.tar.gz: 0bbb1519eae02dfc64d5fb2b9e46d0ce5f3ea4a9
3
+ metadata.gz: 80ffe06cac04232d653df61585e7b55bb9dbad32
4
+ data.tar.gz: 7324f607b6f3a5938851bcb4ec1abd959a9354d4
5
5
  SHA512:
6
- metadata.gz: f215fbf6efb8de0fb895b77babf09501bb8bbb953135b9fb7673a8d9ddc1906d41e0d303c4f706391340a7f7525164f416a4cd03933ead8b5bdd98373bb9d59a
7
- data.tar.gz: ce9ef15b32050292976e959e4339e4ba66a456c1d4e4aedd6f72e8c2b569a36d99a6c50a52b4b24f770f85bdde3ff742e15a2657dd8d0ea599f689044e109e8a
6
+ metadata.gz: 18fc95d03296eb96fedacec2fd7f0003a1beb805c8432e2da5687ec7ea3b9dc4689fc52ea509b2d9fdcbbd1b04fd9bba5c81aad8327a86d5943672a021a3daaa
7
+ data.tar.gz: 9cdb21d2198f16043b14008a4f6769a3060d6871cebd03cf93f09afb8e133f01d8fa259513c50c35dbe01274a2507b4e647740b22d39fc1edeb66eb26db49ef8
data/README.md CHANGED
@@ -93,7 +93,9 @@ default> /help
93
93
  /desc QUERY_EXECUTION_ID
94
94
  /help
95
95
  /list [NUM]
96
+ /output_location [S3URL]
96
97
  /pager PAGER
98
+ /region [REGION]
97
99
  /result QUERY_EXECUTION_ID
98
100
  /stop QUERY_EXECUTION_ID
99
101
  /use DATABASE
data/exe/ath CHANGED
@@ -61,7 +61,10 @@ if options[:debug]
61
61
  end
62
62
 
63
63
  begin
64
- shell = Ath::Shell.new(database: options.delete(:database), options: options)
64
+ shell = Ath::Shell.new(
65
+ output_location: options.delete(:output_location),
66
+ database: options.delete(:database),
67
+ options: options)
65
68
 
66
69
  if query_file
67
70
  if query_file == '-'
data/lib/ath/command.rb CHANGED
@@ -51,6 +51,12 @@ class Ath::Command
51
51
  end
52
52
 
53
53
  out = lines.join("\n")
54
+ when 'output_location'
55
+ if @arg
56
+ @shell.driver.output_location = @arg
57
+ else
58
+ out = @shell.driver.output_location
59
+ end
54
60
  when 'pager'
55
61
  if @arg
56
62
  @shell.pager = @arg
@@ -58,6 +64,12 @@ class Ath::Command
58
64
  @shell.pager = nil
59
65
  out = "Using stdout"
60
66
  end
67
+ when 'region'
68
+ if @arg
69
+ @shell.driver.region = @arg
70
+ else
71
+ out = @shell.driver.region
72
+ end
61
73
  when 'result'
62
74
  if @arg
63
75
  out = @shell.driver.get_query_execution_result(query_execution_id: @arg)
@@ -72,7 +84,7 @@ class Ath::Command
72
84
  end
73
85
  when 'use'
74
86
  if @arg
75
- @shell.database = @arg
87
+ @shell.driver.database = @arg
76
88
  else
77
89
  out = "Usage: /use DATABASE"
78
90
  end
@@ -91,7 +103,9 @@ class Ath::Command
91
103
  /desc QUERY_EXECUTION_ID
92
104
  /help
93
105
  /list [NUM]
106
+ /output_location [S3URL]
94
107
  /pager PAGER
108
+ /region [REGION]
95
109
  /result QUERY_EXECUTION_ID
96
110
  /stop QUERY_EXECUTION_ID
97
111
  /use DATABASE
data/lib/ath/driver.rb CHANGED
@@ -1,11 +1,14 @@
1
1
  class Ath::Driver
2
- def initialize(athena:, s3:)
2
+ attr_accessor :database
3
+
4
+ def initialize(athena:, s3:, output_location:, database:)
3
5
  @athena = athena
4
6
  @s3 = s3
7
+ @output_location = output_location
8
+ @database = database
5
9
  end
6
10
 
7
11
  def get_query_execution(query_execution_id:)
8
-
9
12
  @athena.get_query_execution(query_execution_id: query_execution_id).query_execution
10
13
  end
11
14
 
@@ -28,15 +31,32 @@ class Ath::Driver
28
31
  tmp
29
32
  end
30
33
 
31
- def start_query_execution(query_string:, database:, output_location:)
34
+ def start_query_execution(query_string:)
32
35
  @athena.start_query_execution(
33
36
  query_string: query_string,
34
- query_execution_context: {database: database},
35
- result_configuration: { output_location: output_location}
36
- )
37
+ query_execution_context: {database: @database},
38
+ result_configuration: { output_location: @output_location})
37
39
  end
38
40
 
39
41
  def stop_query_execution(query_execution_id:)
40
42
  @athena.stop_query_execution(query_execution_id: query_execution_id)
41
43
  end
44
+
45
+ def output_location
46
+ @output_location
47
+ end
48
+
49
+ def output_location=(v)
50
+ @output_location = v
51
+ end
52
+
53
+ def region
54
+ @athena.config.region
55
+ end
56
+
57
+ def region=(v)
58
+ @athena.config.region = v
59
+ @athena.config.sigv4_region = v
60
+ @athena.config.endpoint = Aws::EndpointProvider.resolve(v, 'athena')
61
+ end
42
62
  end
data/lib/ath/query.rb CHANGED
@@ -6,11 +6,7 @@ class Ath::Query
6
6
  end
7
7
 
8
8
  def run
9
- query_execution_id = @shell.driver.start_query_execution(
10
- query_string: @query,
11
- database: @shell.database,
12
- output_location: @shell.options.fetch(:output_location)
13
- ).query_execution_id
9
+ query_execution_id = @shell.driver.start_query_execution(query_string: @query).query_execution_id
14
10
 
15
11
  if @detach
16
12
  return "QueryExecution #{query_execution_id}"
data/lib/ath/shell.rb CHANGED
@@ -4,13 +4,11 @@ class Ath::Shell
4
4
 
5
5
  attr_reader :driver
6
6
  attr_reader :options
7
- attr_accessor :database
8
7
  attr_accessor :pager
9
8
 
10
- def initialize(athena: Aws::Athena::Client.new, s3: Aws::S3::Client.new, database: nil, options: {})
11
- @driver = Ath::Driver.new(athena: athena, s3: s3)
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)
12
11
  @options = options
13
- @database = database
14
12
  @scanner = Ath::Scanner.new(shell: self)
15
13
  end
16
14
 
@@ -60,7 +58,7 @@ class Ath::Shell
60
58
  end
61
59
 
62
60
  def prompt
63
- database = @database || '(none)'
61
+ database = @driver.database || '(none)'
64
62
 
65
63
  if @scanner.empty?
66
64
  "#{database}> "
@@ -112,15 +110,15 @@ class Ath::Shell
112
110
  end
113
111
 
114
112
  def save_history
115
- if Readline::HISTORY.length < HISTSIZE
116
- offset = Readline::HISTORY.length
113
+ history = Readline::HISTORY.map(&:strip).reject(&:empty?).reverse.uniq.reverse
114
+
115
+ if history.length < HISTSIZE
116
+ offset = history.length
117
117
  else
118
- offset = HISTORY
118
+ offset = HISTSIZE
119
119
  end
120
120
 
121
- history = Readline::HISTORY.map(&:strip).reject(&:empty?).uniq
122
121
  history = history.slice(-offset..-1) || []
123
-
124
122
  return if history.empty?
125
123
 
126
124
  open(HISTORY_FILE, 'wb') do |f|
data/lib/ath/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Ath
2
- VERSION = '0.1.2'
2
+ VERSION = '0.1.3'
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.1.2
4
+ version: 0.1.3
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-02 00:00:00.000000000 Z
11
+ date: 2017-07-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: aws-sdk