athena-utils 0.1.1 → 0.2.0

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
  SHA256:
3
- metadata.gz: f60738b7ecb0c8155fbdf4f85e0bc0371905840808af83eace67328b9a65177b
4
- data.tar.gz: 8055dfa958fe0e4a3d8d7364a75e7a6ee500ea32316677472c80c20525c47d82
3
+ metadata.gz: 90313673159e89c11d9e5a349cf25ba6f36c8a1b2e0842aede4077b4bd4591e2
4
+ data.tar.gz: cc06774cad38266f57b842dbd75c05f82b2a39502c4c4918653f1a8becd8e8f0
5
5
  SHA512:
6
- metadata.gz: aeccd09b1b52e06d5c4f7da44ae6b0538f2c779e959d22a2aa3b117709da72c463d409fa640af51208f1e5fc8fecb2cb8e891a45868f4ac9131f01202fbe5b24
7
- data.tar.gz: 9485169a4b35602f55b7cf60321cc4629a2798b7380f6ec3d8edf4045c03debe20c362f520136fbd858726d65af15c1bf6b4c04cba16473c8dda4d39c6d1d7ce
6
+ metadata.gz: a9d081001c9d3df09e9c168eaf1b9ae3b9efef68304de3f7bee46f58faac5ba661cdcab389a1c41930c92673f6bce55f1b123e39fbc258789c62ffbfd7607ab9
7
+ data.tar.gz: c95477b1c4a8f13c6e3ad9433c0ebe123b56b4446799c70bf7c345c1e4a447742ca246dba2a6a015711e576a7018d679dc5b19145df5b2b178860ce2ab1054fa
data/athena-utils.gemspec CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = 'athena-utils'
5
- s.version = '0.1.1'
5
+ s.version = '0.2.0'
6
6
  s.licenses = ['MIT']
7
7
  s.summary = 'Athena Utils'
8
8
  s.description = 'Tools for querying AWS Athena'
data/bin/athena CHANGED
@@ -5,9 +5,10 @@ require 'optparse'
5
5
 
6
6
  options = {
7
7
  database: nil,
8
- output_location: nil,
8
+ work_group: 'primary',
9
9
  query: nil,
10
- save: nil
10
+ save: nil,
11
+ console: false
11
12
  }
12
13
  OptionParser.new do |opts|
13
14
  opts.banner = "Usage: athena [options]"
@@ -16,8 +17,8 @@ OptionParser.new do |opts|
16
17
  options[:database] = v
17
18
  end
18
19
 
19
- opts.on("-o", "--output-location OUTPUT_LOCATION", "S3 output location for athena queries") do |v|
20
- options[:output_location] = v
20
+ opts.on("-w WORK_GROUP", "Athena Work Group, default: primary") do |v|
21
+ options[:work_group] = v
21
22
  end
22
23
 
23
24
  opts.on("-e", "--execute QUERY", "Execute SQL Query") do |v|
@@ -27,12 +28,16 @@ OptionParser.new do |opts|
27
28
  opts.on('-s', '--save FILE', 'Save query results to file') do |v|
28
29
  options[:save] = v
29
30
  end
31
+
32
+ opts.on('-c', '--console', 'Execute query and makes results available in irb') do
33
+ options[:console] = true
34
+ end
30
35
  end.parse!
31
36
 
32
37
  raise('must specify a database') unless options[:database]
33
- raise('must specify output location for athean queries') unless options[:output_location]
38
+ raise('must specify work group for athean queries') unless options[:work_group]
34
39
 
35
- @athena = AthenaUtils::AthenaClient.new(options[:database], options[:output_location])
40
+ @athena = AthenaUtils::AthenaClient.new(options[:database], options[:work_group])
36
41
  def athena
37
42
  @athena
38
43
  end
@@ -47,8 +52,17 @@ if options[:query]
47
52
  results.save(options[:save])
48
53
  exit
49
54
  end
50
- end
51
-
52
- require 'irb'
53
- IRB.start
54
55
 
56
+ if options[:console]
57
+ require 'irb'
58
+ IRB.start
59
+ else
60
+ io = results.s3_object.body
61
+ while chunk = io.read(8192)
62
+ print chunk
63
+ end
64
+ end
65
+ else
66
+ require 'irb'
67
+ IRB.start
68
+ end
@@ -5,9 +5,9 @@ module AthenaUtils
5
5
  DEFAULT_WAIT_TIME = 3 # seconds
6
6
 
7
7
  # database is the name of the Athena DB
8
- # output_location is the full S3 path to store the results of Athena queries
8
+ # work_group is Athena Work Group to use with queries
9
9
  attr_reader :database,
10
- :output_location
10
+ :work_group
11
11
 
12
12
  # wait_time is time to wait before checking query results again
13
13
  attr_accessor :wait_time
@@ -15,9 +15,9 @@ module AthenaUtils
15
15
  attr_writer :aws_athena_client,
16
16
  :aws_s3_client
17
17
 
18
- def initialize(database, output_location, wait_time = DEFAULT_WAIT_TIME)
18
+ def initialize(database, work_group, wait_time = DEFAULT_WAIT_TIME)
19
19
  @database = database
20
- @output_location = output_location
20
+ @work_group = work_group
21
21
  @wait_time = wait_time
22
22
  end
23
23
 
@@ -48,9 +48,7 @@ module AthenaUtils
48
48
  query_execution_context: {
49
49
  database: database
50
50
  },
51
- result_configuration: {
52
- output_location: output_location
53
- }
51
+ work_group: work_group
54
52
  )
55
53
 
56
54
  response.query_execution_id
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: athena-utils
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Doug Youch
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-02-22 00:00:00.000000000 Z
11
+ date: 2022-02-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: aws-sdk-athena