data_pitcher 0.1.1 → 0.1.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/lib/data_pitcher/batch.rb +6 -2
- data/lib/data_pitcher/command.rb +1 -0
- data/lib/data_pitcher/spreadsheet.rb +7 -13
- data/lib/data_pitcher/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8025404be932416fdf0b9bbd08d08f22cdf31469
|
4
|
+
data.tar.gz: 29b8bc521481415d5412bd4114f316ad3fb7d718
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8c75433570a7a09727e2e51c9f8ee0ba535166dc108b2ba4a8a23aa098144fea6c4eceed56b74801cb8f80720a23c42bcee1e47b5f95a9ea9de6dbee2653a2ea
|
7
|
+
data.tar.gz: 9ee9e905e4915689e1181d6f6867758edae4693ad9160246de1f804898b2f9160727acdddc0f308800aed12f97c70c74085b24b5df462de2fcfb7c9d037d821b
|
data/Gemfile.lock
CHANGED
data/lib/data_pitcher/batch.rb
CHANGED
@@ -14,8 +14,12 @@ module DataPitcher
|
|
14
14
|
def execute(dry_run: true)
|
15
15
|
commands.each.with_index(1) do |command, index|
|
16
16
|
begin
|
17
|
-
|
18
|
-
|
17
|
+
result = false
|
18
|
+
elapsed_time = Benchmark.realtime do
|
19
|
+
result = DataPitcher::Command.new(command['spreadsheet_key'], command['sql_path'], dry_run: dry_run, index: index).execute
|
20
|
+
end
|
21
|
+
if result
|
22
|
+
puts "##{index} command: sending completed. #{elapsed_time}s"
|
19
23
|
end
|
20
24
|
rescue => e
|
21
25
|
puts "[ERROR] ##{index} command skipped: #{e.class} #{e.message}"
|
data/lib/data_pitcher/command.rb
CHANGED
@@ -2,6 +2,8 @@ require 'google_drive'
|
|
2
2
|
|
3
3
|
module DataPitcher
|
4
4
|
class Spreadsheet
|
5
|
+
BATCH_SIZE = 1000
|
6
|
+
|
5
7
|
def initialize(spreadsheet_key)
|
6
8
|
@spreadsheet_key = spreadsheet_key
|
7
9
|
end
|
@@ -17,11 +19,7 @@ module DataPitcher
|
|
17
19
|
|
18
20
|
def clear_sheet
|
19
21
|
worksheet.reload
|
20
|
-
(1
|
21
|
-
(1..worksheet.num_cols).each do |col|
|
22
|
-
worksheet[row, col] = ''
|
23
|
-
end
|
24
|
-
end
|
22
|
+
worksheet.delete_rows(1, worksheet.num_rows)
|
25
23
|
worksheet.save
|
26
24
|
end
|
27
25
|
|
@@ -29,16 +27,12 @@ module DataPitcher
|
|
29
27
|
result = DataPitcher::Executor.new(sql_query).execute
|
30
28
|
worksheet.reload
|
31
29
|
# fill header
|
32
|
-
|
33
|
-
worksheet[1, col_index] = val
|
34
|
-
end
|
30
|
+
worksheet.insert_rows(1, [result.header])
|
35
31
|
# fill rows
|
36
|
-
result.rows.
|
37
|
-
|
38
|
-
|
39
|
-
end
|
32
|
+
result.rows.each_slice(BATCH_SIZE).with_index do |array, batch_index|
|
33
|
+
worksheet.insert_rows(2 + batch_index * BATCH_SIZE, array)
|
34
|
+
worksheet.save
|
40
35
|
end
|
41
|
-
worksheet.save
|
42
36
|
end
|
43
37
|
|
44
38
|
def replace_worksheet_with_query(sql_query)
|
data/lib/data_pitcher/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: data_pitcher
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Masahiro Nishimi
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-06-
|
11
|
+
date: 2017-06-28 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activerecord
|