egis 1.3.0 → 1.4.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: 11391a5ed53240c217c0bdd8db15ddfee6de259341a11f7109475149d7486e52
4
- data.tar.gz: 117fb43d54ec8363a44c70924cb4e94c194b234a710ec806fd1d9ae0e534d550
3
+ metadata.gz: 4fa3323e3c02d8537df83f33799f580fb196c255315c9923eb70c0e87bd1f50e
4
+ data.tar.gz: 9b4054a2201d98f501603cc137c1c7df93fccf105c448b6d4261515c3f53d959
5
5
  SHA512:
6
- metadata.gz: db5df8ea30e0a55dcd4988859ea13ed5e674491bf545a468630e9fe0821c8c36cd360b2839d13e609e2007bc32b5aa89e3a58870bdcdbbaca6b5cf448ac6d59f
7
- data.tar.gz: 9aa20b80ff73d128b1f057727fe9ce28367b77500e2c1724d1437b8228d900906f3ec3138d98e8d5c00d11a0e4d1f1674319ddf9fac0c3079ebff7b9b8ca9979
6
+ metadata.gz: 3da9b098de6948b584244db63eda8ef4ba3d26ff29806be0e1a3b3469a321bb72d0761bc4bcb415759646a2397c71d32221477cc2dabeb9233dd8cad22300cef
7
+ data.tar.gz: 5c50463ef9585563b3aa6fefbb89b4df101f93693b7e5d5f423e98fa803e614d7541639db9afe06fc1a4544205d6e3b0cbf3c166112f556f58b8c798b528571d
data/lib/egis/table.rb CHANGED
@@ -97,7 +97,19 @@ module Egis
97
97
  ##
98
98
  # Insert data into the table. Mostly useful for testing purposes.
99
99
  #
100
- # @param [Array] rows Array of arrays with row values
100
+ # @example Insert with array of arrays
101
+ # table.upload_data([
102
+ # ['hello world', 'mx', 1],
103
+ # ['hello again', 'us', 2]
104
+ # ])
105
+ #
106
+ # @example Insert with array of hashes
107
+ # table.upload_data([
108
+ # {message: 'hello world', country: 'mx', type: 1},
109
+ # {message: 'hello again', country: 'us', type: 2}
110
+ # ])
111
+ #
112
+ # @param [Array] rows Array of arrays or hashes with row values
101
113
  # @return [void]
102
114
 
103
115
  def upload_data(rows)
@@ -149,23 +161,33 @@ module Egis
149
161
  Egis.logger.info { "Creating table #{database.name}.#{name} located in #{location}" }
150
162
  end
151
163
 
152
- def column_serializers
153
- @column_serializers ||= column_types.map { |type| Egis::Types.serializer(type) }
164
+ def column_types
165
+ all_columns.map(&:type)
154
166
  end
155
167
 
156
- def column_types
157
- (schema.columns + schema.partitions).map(&:type)
168
+ def all_columns
169
+ schema.columns + schema.partitions
158
170
  end
159
171
 
160
172
  def data_insert_query(rows)
173
+ insert_values = rows.map { |row| row_literal_values(row) }
174
+ row_clause = insert_values.map { |row| row_values_statement(row) }.join(",\n")
175
+
161
176
  <<~SQL
162
177
  INSERT INTO #{name} VALUES
163
- #{rows.map { |row| row_values_statement(row) }.join(",\n")};
178
+ #{row_clause}
164
179
  SQL
165
180
  end
166
181
 
182
+ def row_literal_values(row)
183
+ all_columns.map.with_index do |column, index|
184
+ value = row.is_a?(Hash) ? row[column.name] : row[index]
185
+ Egis::Types.serializer(column.type).literal(value)
186
+ end
187
+ end
188
+
167
189
  def row_values_statement(row)
168
- "(#{row.zip(column_serializers).map { |value, serializer| serializer.literal(value) }.join(', ')})"
190
+ "(#{row.join(', ')})"
169
191
  end
170
192
  end
171
193
  end
data/lib/egis/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Egis
4
- VERSION = '1.3.0'
4
+ VERSION = '1.4.0'
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: egis
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.3.0
4
+ version: 1.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Agnieszka Czereba
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2020-07-23 00:00:00.000000000 Z
12
+ date: 2021-03-12 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: aws-sdk-athena
@@ -99,7 +99,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
99
99
  - !ruby/object:Gem::Version
100
100
  version: '0'
101
101
  requirements: []
102
- rubygems_version: 3.1.2
102
+ rubygems_version: 3.1.4
103
103
  signing_key:
104
104
  specification_version: 4
105
105
  summary: A handy wrapper for AWS Athena Ruby SDK.