athens 0.2.0 → 0.3.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: d1fb8ee7934d4e7019f1f54dbd3b3eb4368536e3974a00b35442898e4e8b267f
4
- data.tar.gz: 1685787b3a1c68f850cc7ca01523a0f3a4feaeaae26ed5d9f77e41ffdafe4b15
3
+ metadata.gz: 901ae482186b3f1eeb424ee6bc4c09f5122aa7ba20028e7bc88015f0f8eff840
4
+ data.tar.gz: a42a0b004300dd61da4d1bf3fc96aace76c94fa0ba7760a8ca81a4a736cb77e2
5
5
  SHA512:
6
- metadata.gz: 7ba436dc94c82c4b6642e8084e76455d3f32a786bc718364c89f2e3769b3786ddcfb65f0e1526d62b56c5d11a6e6e67cab501f3063b8e5e0c59fa2e46a219292
7
- data.tar.gz: b6ef5c5bd6e318348fb4bb9fb794c37ff57be2e13bdcaaeef707246a524b3ea6b5d65ba62e0a2d3d7dbfab696ac6fbbfbfad33f943c473d1c2abc8747849658d
6
+ metadata.gz: e89fc662abb5ee87ab4612ddc90cadfb2259f0e33e6e3d59a73f0b759dbf675239630ef9f8835d88746ad72726404eb9db5d451eb5d84ad0bdcb4c1ceffd23c5
7
+ data.tar.gz: c15ce346a50f27fd2f684928bf1761145b848b1d80b9503faad4b5ffcd3cf35b49aa8d3fe719bd6da0210e2a5094cc0ff3e7a38026e1361521f8404738d09fca
@@ -1,3 +1,8 @@
1
+ ## 0.3.0 / 2019-07-02
2
+
3
+ * Added enumerator-based result access methods: `#rows` and `#records`
4
+ * Fixed bug dropping headers from memoized rows across `#to_h` and `#to_a(header_row: true)`
5
+
1
6
  ## 0.2.0 / 2019-03-20
2
7
 
3
8
  * Added support for NULL values. Columns with a nullable status of "NULLABLE" or "UNKNOWN" will return nil for NULL values
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- athens (0.2.0)
4
+ athens (0.3.0)
5
5
  aws-sdk-athena (~> 1)
6
6
 
7
7
  GEM
data/README.md CHANGED
@@ -61,6 +61,23 @@ results = query.to_h
61
61
  # ]
62
62
  ```
63
63
 
64
+ Results are also available as unbuffered enumerators of row arrays:
65
+ ```ruby
66
+ query.rows.each {|row| ...}
67
+ # ['column_1', 'column_2', 'column_3']
68
+ # [15, 'data', true]
69
+ # [20, 'foo', false],
70
+ # ...
71
+ ```
72
+
73
+ Or hashes:
74
+ ```ruby
75
+ query.records.each {|record| ...}
76
+ # {'column_1': 15, 'column_2': 'data', 'column_3': true}
77
+ # {'column_1': 20, 'column_2': 'foo', 'column_3': false}
78
+ # ...
79
+ ```
80
+
64
81
  Athens attempts to parse the sql data types into their ruby equivalents, although there's currently no support for the more complex Array/Map types.
65
82
 
66
83
  ### Configuration
@@ -69,12 +69,10 @@ module Athens
69
69
  end
70
70
  end
71
71
 
72
- def to_a(header_row: true)
72
+ def rows
73
73
  raise InvalidRequestError.new("Query must be in SUCCEEDED state to return results") unless @state == 'SUCCEEDED'
74
74
 
75
- if @results.nil?
76
- # Need to load and map all of the rows from the original result
77
- @results = []
75
+ Enumerator.new do |y|
78
76
  result = @connection.client.get_query_results({query_execution_id: @query_execution_id})
79
77
 
80
78
  metadata = result.result_set.result_set_metadata
@@ -85,53 +83,43 @@ module Athens
85
83
  break if rows.empty?
86
84
 
87
85
  if first
88
- @results << rows.shift.data.map {|col| col.var_char_value}
86
+ y << rows.shift.data.map {|col| col.var_char_value}
89
87
  first = false
90
88
  end
91
89
 
92
- rows.each do |row|
93
- @results << map_types(metadata, row)
94
- end
90
+ rows.each {|row| y << map_types(metadata, row)}
95
91
 
96
- if result.next_token
97
- result = @connection.client.get_query_results({
98
- query_execution_id: @query_execution_id,
99
- next_token: result.next_token
100
- })
101
- else
102
- # No more rows, break out and return our mapped data
103
- break
104
- end
105
- end
106
- end
92
+ break unless result.next_token
107
93
 
108
- if header_row
109
- return @results
110
- else
111
- return @results[1, @results.size]
94
+ result = @connection.client.get_query_results({
95
+ query_execution_id: @query_execution_id,
96
+ next_token: result.next_token
97
+ })
98
+ end
112
99
  end
113
100
  end
114
101
 
115
- def to_h
116
- if @hash_results.nil?
117
- all_rows = self.to_a(header_row: true)
118
-
119
- headers = all_rows.shift
120
-
121
- @hash_results = []
102
+ def records
103
+ Enumerator.new do |y|
104
+ headers = nil
122
105
 
123
- unless headers.nil?
124
- all_rows.each do |row|
125
- map = {}
126
- headers.each_with_index do |header, index|
127
- map[header] = row[index]
128
- end
129
- @hash_results << map
106
+ rows.each_with_index do |row|
107
+ if headers.nil?
108
+ headers = row
109
+ next
130
110
  end
111
+
112
+ y << Hash[headers.zip(row)]
131
113
  end
132
114
  end
115
+ end
133
116
 
134
- return @hash_results
117
+ def to_a(header_row: true)
118
+ (@results ||= rows.to_a).drop(header_row ? 0 : 1)
119
+ end
120
+
121
+ def to_h
122
+ @hash_results ||= records.to_a
135
123
  end
136
124
 
137
125
  private
@@ -1,3 +1,3 @@
1
1
  module Athens
2
- VERSION = "0.2.0"
2
+ VERSION = "0.3.0"
3
3
  end
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.2.0
4
+ version: 0.3.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: 2019-03-20 00:00:00.000000000 Z
11
+ date: 2019-07-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: aws-sdk-athena