athena-utils 0.2.0 → 0.2.1

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.
Files changed (5) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +74 -1
  3. data/athena-utils.gemspec +1 -1
  4. data/bin/athena +4 -4
  5. metadata +2 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 90313673159e89c11d9e5a349cf25ba6f36c8a1b2e0842aede4077b4bd4591e2
4
- data.tar.gz: cc06774cad38266f57b842dbd75c05f82b2a39502c4c4918653f1a8becd8e8f0
3
+ metadata.gz: a6cfc30203a5a7011e98d08203bb667a82635fef01f429aea57816ed26e2f162
4
+ data.tar.gz: 8f54fbfdaa0decb20edadf57a01ff93507d42ec97c7ca033811be22d03339e22
5
5
  SHA512:
6
- metadata.gz: a9d081001c9d3df09e9c168eaf1b9ae3b9efef68304de3f7bee46f58faac5ba661cdcab389a1c41930c92673f6bce55f1b123e39fbc258789c62ffbfd7607ab9
7
- data.tar.gz: c95477b1c4a8f13c6e3ad9433c0ebe123b56b4446799c70bf7c345c1e4a447742ca246dba2a6a015711e576a7018d679dc5b19145df5b2b178860ce2ab1054fa
6
+ metadata.gz: eb94223f2bc84ae9363c64ba9fadfa24b4afa6003c41b498979b1b0673dbf0f97d330b7ce4d8c55abefe29718ce9191aba35229d4c9feb6515f2cd391605a55a
7
+ data.tar.gz: eecb9e9020be2969c47ed309d41c1a001e1910fd6bba0bc7956855507b1d4aa73497fdcd9964f7e7ea3d9ba9fdf85391519c7b6be5884842178d3d68a8a8f630
data/README.md CHANGED
@@ -1,3 +1,76 @@
1
1
  # AWS Athena Utils
2
2
 
3
- A simple query wrapper around Aws::Athena::Client.
3
+ Purpose of this utility is to execute Athena queries and wait for results.
4
+
5
+ ## Usage
6
+
7
+ Install the gem:
8
+
9
+ ```
10
+ gem install 'athena-utils'
11
+ ```
12
+
13
+ Create an Athena client and wait for results.
14
+
15
+ ```
16
+ require 'athena-utils'
17
+
18
+ athena_database = 'test_db'
19
+ athena_workspace = 'primary'
20
+ athena_client = AthenaUtils::AthenaClient.new(athena_database, athena_workspace)
21
+
22
+ results = athena_client.query("SELECT * FROM users WHERE created_at >= Date('2022-01-01')")
23
+ results.first
24
+ # => {"id"=>"8", "name"=>"Foo", "email"=>"foo@example.com", "created_at"=>"2022-02-01"}
25
+ ```
26
+
27
+ Execute multiple queries and wait for results.
28
+
29
+ ```
30
+ require 'athena-utils'
31
+
32
+ athena_database = 'test_db'
33
+ athena_workspace = 'primary'
34
+ athena_client = AthenaUtils::AthenaClient.new(athena_database, athena_workspace)
35
+
36
+ # contains table_name => query_execution_id
37
+ query_executions = {}
38
+ query_executions['users'] = athena_client.query_async("SELECT * FROM users WHERE created_at >= Date('2022-01-01')")
39
+ query_executions['groups'] = athena_client.query_async("SELECT * FROM groups WHERE created_at >= Date('2022-01-01')")
40
+ query_executions['activities'] = athena_client.query_async("SELECT * FROM activities WHERE created_at >= Date('2022-01-01')")
41
+
42
+ # given an array of query_execution_id(s)
43
+ # waits for each query to successfully complete
44
+ # and returns the results of each in a hash
45
+ # key is the query_execution_id and the value is the results
46
+ results = athena_client.wait(query_executions.values)
47
+
48
+ users_results = results[query_executions['users']]
49
+ groups_results = results[query_executions['groups']]
50
+ activities_results = results[query_executions['activities']]
51
+
52
+ users_results.first
53
+ # => {"id"=>"8", "name"=>"Foo", "email"=>"foo@example.com", "created_at"=>"2022-02-01"}
54
+ ```
55
+
56
+ ## AthenaUtils::AthenaQueryResults
57
+
58
+ Streams the results of the query. Avoids loading the results into memory.
59
+
60
+ The class implements the Enumerable module. For easy of use the _each_ method returns each row in a hash where the header names are the keys.
61
+
62
+ How to access the rows as an array
63
+
64
+ ```
65
+ # given the above query logic
66
+ headers = users_results.csv.shift
67
+
68
+ while(row = users_results.csv.shift)
69
+ id = row[0]
70
+ name = row[1]
71
+ emai = row[2]
72
+ created_at = row[3]
73
+
74
+ # do something
75
+ end
76
+ ```
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.2.0'
5
+ s.version = '0.2.1'
6
6
  s.licenses = ['MIT']
7
7
  s.summary = 'Athena Utils'
8
8
  s.description = 'Tools for querying AWS Athena'
data/bin/athena CHANGED
@@ -11,17 +11,17 @@ options = {
11
11
  console: false
12
12
  }
13
13
  OptionParser.new do |opts|
14
- opts.banner = "Usage: athena [options]"
14
+ opts.banner = 'Usage: athena [options]'
15
15
 
16
- opts.on("-d", "--database DATABASE", "Athena DB") do |v|
16
+ opts.on('-d', '--database DATABASE', 'Athena DB') do |v|
17
17
  options[:database] = v
18
18
  end
19
19
 
20
- opts.on("-w WORK_GROUP", "Athena Work Group, default: primary") do |v|
20
+ opts.on('-w', '--work-group WORK_GROUP', 'Athena Work Group, default: primary') do |v|
21
21
  options[:work_group] = v
22
22
  end
23
23
 
24
- opts.on("-e", "--execute QUERY", "Execute SQL Query") do |v|
24
+ opts.on('-e', '--execute QUERY', 'Execute SQL Query') do |v|
25
25
  options[:query] = v
26
26
  end
27
27
 
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.2.0
4
+ version: 0.2.1
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-23 00:00:00.000000000 Z
11
+ date: 2022-02-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: aws-sdk-athena