athens 0.3.3 → 0.4.0
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.
- checksums.yaml +4 -4
- data/.gitignore +2 -1
- data/CHANGELOG.md +54 -0
- data/Gemfile.lock +12 -10
- data/README.md +18 -6
- data/Vagrantfile +4 -6
- data/athens.gemspec +1 -0
- data/lib/athens/configuration.rb +9 -3
- data/lib/athens/connection.rb +3 -4
- data/lib/athens/query.rb +6 -4
- data/lib/athens/version.rb +1 -1
- data/lib/athens.rb +1 -0
- metadata +17 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: cb4922b50ef935d722a54d54d4f3d9a9e47b587b67592454b806bf11e00f7be1
|
4
|
+
data.tar.gz: 2fc14349880958e3212444e8285a0005c76f9e1bcb219ac8423cb1f1cdacfb57
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6c8dc6d78814f5b947d08434b8f2ccf13998439fca59465495401cc9e73f7e7e30efe3899679d545fe17184704b81fab33ddf5ffc5d2eb833e6ea2ef67dc6f2e
|
7
|
+
data.tar.gz: 4e7d3d6f0cd1bdd5da7644c16b8802bc810d8f15f12e05fcd746acb743d48fe5c0ff740928ae117047aa2d6c2417daf33b86cab630cfbe0f42e87650c58e7909
|
data/.gitignore
CHANGED
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,57 @@
|
|
1
|
+
## 0.4.0 / 2021-12-03
|
2
|
+
|
3
|
+
* Added automatic parsing of JSON columns (thanks [darkside](https://github.com/darkside))
|
4
|
+
|
5
|
+
#### Potentially breaking change
|
6
|
+
|
7
|
+
If you were previously querying JSON type data and parsing it from a string in your own code, you'll want to remove that before upgrading.
|
8
|
+
|
9
|
+
For example, with previous versions you could do this (even though it would generate a warning):
|
10
|
+
|
11
|
+
```ruby
|
12
|
+
> query = conn.execute("SELECT JSON_PARSE('{\"a\": 1, \"b\": 2}');")
|
13
|
+
> query.wait
|
14
|
+
> JSON.parse(query.to_a(header_row: false).first[0])
|
15
|
+
WARNING: Unsupported type: json, defaulting to string
|
16
|
+
=> {"a"=>1, "b"=>2}
|
17
|
+
```
|
18
|
+
|
19
|
+
After upgrading, that same code will give you an error:
|
20
|
+
```ruby
|
21
|
+
> JSON.parse(query.to_a(header_row: false).first[0])
|
22
|
+
Traceback (most recent call last):
|
23
|
+
5: from bin/console:14:in `<main>'
|
24
|
+
4: from (irb):12:in `<main>'
|
25
|
+
3: from /home/vagrant/.rvm/rubies/ruby-3.0.0/lib/ruby/3.0.0/json/common.rb:216:in `parse'
|
26
|
+
2: from /home/vagrant/.rvm/rubies/ruby-3.0.0/lib/ruby/3.0.0/json/common.rb:216:in `new'
|
27
|
+
1: from /home/vagrant/.rvm/rubies/ruby-3.0.0/lib/ruby/3.0.0/json/common.rb:216:in `initialize'
|
28
|
+
TypeError (no implicit conversion of Hash into String)
|
29
|
+
```
|
30
|
+
|
31
|
+
Instead just remove your json parsing since Athens handles it now:
|
32
|
+
```ruby
|
33
|
+
> query = conn.execute("SELECT JSON_PARSE('{\"a\": 1, \"b\": 2}');")
|
34
|
+
> query.wait
|
35
|
+
> query.to_a(header_row: false).first[0]
|
36
|
+
=> {:a=>1, :b=>2}
|
37
|
+
```
|
38
|
+
|
39
|
+
|
40
|
+
## 0.3.6 / 2021-11-16
|
41
|
+
|
42
|
+
* Addition of :result_encryption as a configuration option to change encryption options for query results (https://github.com/getletterpress/athens/issues/12)
|
43
|
+
* Bumped development gem versions to latest releases
|
44
|
+
|
45
|
+
## 0.3.5 / 2021-05-19
|
46
|
+
|
47
|
+
* Addition of :aws_profile as a configuration option for credentials (thanks [oisin](https://github.com/oisin))
|
48
|
+
* Fix for BigDecimal in Ruby 3.x (thanks [mediafinger](https://github.com/mediafinger))
|
49
|
+
* Bumped development gem versions to latest releases
|
50
|
+
|
51
|
+
## 0.3.4 / 2021-03-02
|
52
|
+
|
53
|
+
* Added configurable polling period (thanks [jesseproudman](https://github.com/jesseproudman))
|
54
|
+
|
1
55
|
## 0.3.3 / 2021-01-12
|
2
56
|
|
3
57
|
* Added support for Ruby 3.0 (thanks [blackjiro](https://github.com/blackjiro))
|
data/Gemfile.lock
CHANGED
@@ -1,27 +1,29 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
athens (0.
|
4
|
+
athens (0.4.0)
|
5
5
|
aws-sdk-athena (~> 1)
|
6
|
+
multi_json (~> 1.0)
|
6
7
|
|
7
8
|
GEM
|
8
9
|
remote: https://rubygems.org/
|
9
10
|
specs:
|
10
|
-
aws-eventstream (1.
|
11
|
-
aws-partitions (1.
|
12
|
-
aws-sdk-athena (1.
|
13
|
-
aws-sdk-core (~> 3, >= 3.
|
11
|
+
aws-eventstream (1.2.0)
|
12
|
+
aws-partitions (1.539.0)
|
13
|
+
aws-sdk-athena (1.44.0)
|
14
|
+
aws-sdk-core (~> 3, >= 3.122.0)
|
14
15
|
aws-sigv4 (~> 1.1)
|
15
|
-
aws-sdk-core (3.
|
16
|
+
aws-sdk-core (3.124.0)
|
16
17
|
aws-eventstream (~> 1, >= 1.0.2)
|
17
|
-
aws-partitions (~> 1, >= 1.
|
18
|
+
aws-partitions (~> 1, >= 1.525.0)
|
18
19
|
aws-sigv4 (~> 1.1)
|
19
20
|
jmespath (~> 1.0)
|
20
|
-
aws-sigv4 (1.
|
21
|
+
aws-sigv4 (1.4.0)
|
21
22
|
aws-eventstream (~> 1, >= 1.0.2)
|
22
23
|
jmespath (1.4.0)
|
23
|
-
|
24
|
-
|
24
|
+
multi_json (1.15.0)
|
25
|
+
rake (13.0.6)
|
26
|
+
rexml (3.2.5)
|
25
27
|
|
26
28
|
PLATFORMS
|
27
29
|
ruby
|
data/README.md
CHANGED
@@ -44,8 +44,8 @@ When your query is done, grab the results as an array:
|
|
44
44
|
```ruby
|
45
45
|
results = query.to_a
|
46
46
|
# [
|
47
|
-
# ['column_1', 'column_2', 'column_3'],
|
48
|
-
# [15, 'data', true],
|
47
|
+
# ['column_1', 'column_2', 'column_3'],
|
48
|
+
# [15, 'data', true],
|
49
49
|
# [20, 'foo', false],
|
50
50
|
# ...
|
51
51
|
# ]
|
@@ -55,7 +55,7 @@ Or as a hash (which is really an array where each row is a hash):
|
|
55
55
|
```ruby
|
56
56
|
results = query.to_h
|
57
57
|
# [
|
58
|
-
# {'column_1': 15, 'column_2': 'data', 'column_3': true},
|
58
|
+
# {'column_1': 15, 'column_2': 'data', 'column_3': true},
|
59
59
|
# {'column_1': 20, 'column_2': 'foo', 'column_3': false},
|
60
60
|
# ...
|
61
61
|
# ]
|
@@ -87,9 +87,12 @@ Configure your AWS settings in an `Athens.configure` block (in rails put this in
|
|
87
87
|
```ruby
|
88
88
|
Athens.configure do |config|
|
89
89
|
config.output_location = "s3://my-bucket/my-folder/athena/results/" # Required
|
90
|
-
config.aws_access_key
|
91
|
-
config.aws_secret_key
|
92
|
-
config.
|
90
|
+
config.aws_access_key = 'access' # Optional
|
91
|
+
config.aws_secret_key = 'secret' # Optional
|
92
|
+
config.aws_profile = 'myprofile' # Optional
|
93
|
+
config.aws_region = 'us-east-1' # Optional
|
94
|
+
config.wait_polling_period = 0.25 # Optional - What period should we poll for the complete query?
|
95
|
+
config.result_encryption = nil # Optional, see below
|
93
96
|
end
|
94
97
|
```
|
95
98
|
|
@@ -103,6 +106,14 @@ conn = Athens::Connection.new(aws_client_override: {})
|
|
103
106
|
|
104
107
|
Take a look at the [AWS Athena SDK](https://docs.aws.amazon.com/sdk-for-ruby/v3/api/Aws/Athena/Client.html#initialize-instance_method) for a list of all the available options.
|
105
108
|
|
109
|
+
The `result_encryption` option controls how the Athens results will be encrypted at the `output_location`. By default it's set to use the Amazon SSE encryption if you don't set it at all:
|
110
|
+
|
111
|
+
```ruby
|
112
|
+
{ encryption_option: "SSE_S3" }
|
113
|
+
```
|
114
|
+
|
115
|
+
If you set it to `nil`, it'll default to the bucket encryption settings. You can also use a customer kms key, see https://docs.aws.amazon.com/sdk-for-ruby/v3/api/Aws/Athena/Types/EncryptionConfiguration.html for the correct format.
|
116
|
+
|
106
117
|
### Advanced Usage
|
107
118
|
|
108
119
|
Providing a database name to the connection is optional, if you omit the name you'll have to specify it in your query:
|
@@ -172,3 +183,4 @@ The gem is available as open source under the terms of the [WTFPL License](http:
|
|
172
183
|
## Code of Conduct
|
173
184
|
|
174
185
|
Everyone interacting in the Athens project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/getletterpress/athens/blob/master/CODE_OF_CONDUCT.md).
|
186
|
+
|
data/Vagrantfile
CHANGED
@@ -4,13 +4,11 @@
|
|
4
4
|
# Provisioning script
|
5
5
|
$script = <<SCRIPT
|
6
6
|
echo "*** Updating packages"
|
7
|
-
|
8
|
-
sudo DEBIAN_FRONTEND=noninteractive apt-get
|
9
|
-
sudo DEBIAN_FRONTEND=noninteractive aptitude update
|
10
|
-
sudo DEBIAN_FRONTEND=noninteractive aptitude -y safe-upgrade
|
7
|
+
sudo DEBIAN_FRONTEND=noninteractive apt-get update
|
8
|
+
sudo DEBIAN_FRONTEND=noninteractive apt-get upgrade
|
11
9
|
|
12
10
|
echo "*** Installing new packages"
|
13
|
-
sudo DEBIAN_FRONTEND=noninteractive
|
11
|
+
sudo DEBIAN_FRONTEND=noninteractive apt-get install -y curl git-core vim
|
14
12
|
|
15
13
|
if rvm -v 2>/dev/null; then
|
16
14
|
echo "*** rvm already installed, skipping"
|
@@ -30,7 +28,7 @@ SCRIPT
|
|
30
28
|
|
31
29
|
|
32
30
|
Vagrant.configure('2') do |config|
|
33
|
-
config.vm.box = "ubuntu/
|
31
|
+
config.vm.box = "ubuntu/focal64"
|
34
32
|
config.vm.hostname = 'athens-dev'
|
35
33
|
|
36
34
|
# Provision the machine with the shell script above
|
data/athens.gemspec
CHANGED
@@ -35,6 +35,7 @@ Gem::Specification.new do |spec|
|
|
35
35
|
spec.required_ruby_version = '>= 2.4'
|
36
36
|
|
37
37
|
spec.add_dependency "aws-sdk-athena", "~> 1"
|
38
|
+
spec.add_dependency 'multi_json', '~> 1.0'
|
38
39
|
|
39
40
|
spec.add_development_dependency "bundler", ">= 1.17"
|
40
41
|
spec.add_development_dependency "rake", "~> 13.0"
|
data/lib/athens/configuration.rb
CHANGED
@@ -1,15 +1,21 @@
|
|
1
1
|
module Athens
|
2
2
|
class Configuration
|
3
|
-
attr_accessor :aws_access_key,
|
3
|
+
attr_accessor :aws_access_key,
|
4
4
|
:aws_secret_key,
|
5
5
|
:aws_region,
|
6
|
-
:output_location
|
6
|
+
:output_location,
|
7
|
+
:wait_polling_period,
|
8
|
+
:aws_profile,
|
9
|
+
:result_encryption
|
7
10
|
|
8
11
|
def initialize
|
9
12
|
@aws_access_key = nil
|
10
13
|
@aws_secret_key = nil
|
11
14
|
@aws_region = nil
|
12
15
|
@output_location = nil
|
16
|
+
@wait_polling_period = 0.25
|
17
|
+
@aws_profile = nil
|
18
|
+
@result_encryption = { encryption_option: "SSE_S3" }
|
13
19
|
end
|
14
20
|
end
|
15
|
-
end
|
21
|
+
end
|
data/lib/athens/connection.rb
CHANGED
@@ -11,7 +11,8 @@ module Athens
|
|
11
11
|
client_config = {
|
12
12
|
access_key_id: Athens.configuration.aws_access_key,
|
13
13
|
secret_access_key: Athens.configuration.aws_secret_key,
|
14
|
-
region: Athens.configuration.aws_region
|
14
|
+
region: Athens.configuration.aws_region,
|
15
|
+
profile: Athens.configuration.aws_profile
|
15
16
|
}.merge(aws_client_override).compact
|
16
17
|
|
17
18
|
@client = Aws::Athena::Client.new(client_config)
|
@@ -47,9 +48,7 @@ module Athens
|
|
47
48
|
def result_config
|
48
49
|
Aws::Athena::Types::ResultConfiguration.new(
|
49
50
|
output_location: Athens.configuration.output_location,
|
50
|
-
encryption_configuration:
|
51
|
-
encryption_option: "SSE_S3"
|
52
|
-
}
|
51
|
+
encryption_configuration: Athens.configuration.result_encryption
|
53
52
|
)
|
54
53
|
end
|
55
54
|
|
data/lib/athens/query.rb
CHANGED
@@ -14,6 +14,7 @@ module Athens
|
|
14
14
|
|
15
15
|
version = RUBY_VERSION.split('.').map {|v| v.to_i}
|
16
16
|
@decimal_without_new = (version[0] >= 2 && version[1] >= 5)
|
17
|
+
@decimal_without_new = (version[0] == 2 && version[1] >= 5) || (version[0] >= 3)
|
17
18
|
end
|
18
19
|
|
19
20
|
def state
|
@@ -49,7 +50,7 @@ module Athens
|
|
49
50
|
end
|
50
51
|
|
51
52
|
# Wait a bit and check again
|
52
|
-
sleep(
|
53
|
+
sleep(Athens.configuration.wait_polling_period.to_f)
|
53
54
|
end
|
54
55
|
end
|
55
56
|
|
@@ -140,7 +141,7 @@ module Athens
|
|
140
141
|
metadata.column_info.each_with_index do |col, index|
|
141
142
|
data = row.data[index].var_char_value
|
142
143
|
nullable = ["UNKNOWN", "NULLABLE"].include?(col.nullable)
|
143
|
-
|
144
|
+
|
144
145
|
if nullable && data.nil?
|
145
146
|
mapped << data
|
146
147
|
elsif !nullable && data.nil?
|
@@ -165,6 +166,8 @@ module Athens
|
|
165
166
|
mapped << Date.parse(data)
|
166
167
|
when 'boolean'
|
167
168
|
mapped << (data == "true")
|
169
|
+
when 'json'
|
170
|
+
mapped << MultiJson.load(data, symbolize_keys: true)
|
168
171
|
else
|
169
172
|
puts "WARNING: Unsupported type: #{col.type}, defaulting to string"
|
170
173
|
mapped << data
|
@@ -173,9 +176,8 @@ module Athens
|
|
173
176
|
end
|
174
177
|
|
175
178
|
return mapped
|
176
|
-
end
|
179
|
+
end
|
177
180
|
|
178
181
|
|
179
182
|
end
|
180
183
|
end
|
181
|
-
|
data/lib/athens/version.rb
CHANGED
data/lib/athens.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: athens
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Chris Schulte
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-
|
11
|
+
date: 2021-12-03 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: aws-sdk-athena
|
@@ -24,6 +24,20 @@ dependencies:
|
|
24
24
|
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '1'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: multi_json
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '1.0'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '1.0'
|
27
41
|
- !ruby/object:Gem::Dependency
|
28
42
|
name: bundler
|
29
43
|
requirement: !ruby/object:Gem::Requirement
|
@@ -113,7 +127,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
113
127
|
- !ruby/object:Gem::Version
|
114
128
|
version: '0'
|
115
129
|
requirements: []
|
116
|
-
rubygems_version: 3.
|
130
|
+
rubygems_version: 3.0.9
|
117
131
|
signing_key:
|
118
132
|
specification_version: 4
|
119
133
|
summary: Run simple SQL queries in AWS Athena
|