blazer 2.3.0 → 2.3.1
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of blazer might be problematic. Click here for more details.
- checksums.yaml +4 -4
- data/CHANGELOG.md +4 -0
- data/README.md +5 -5
- data/app/controllers/blazer/uploads_controller.rb +18 -7
- data/lib/blazer/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 71bd121d2bace5612677090372e36ebdd89eb09398bd7510ba38c666351c1eb4
|
4
|
+
data.tar.gz: 4b109076d6af5aee545f4c19311b431feb68bc7e31f45e28704a99fe7692595b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 035bcb0b2252cd10514b5ab3f28c78b4ae6b6b6b534d99948f20815076661cf7fe85200debcf64ab11c6e5307fc24c326daea76f361f6c474e8216b69ebbbe35
|
7
|
+
data.tar.gz: 4838d7ee13b888d005602916d309825f716cd868287b0f1843aa92bf1a96d5f43168f22de3430c7b2ba6b4ab25fc71e1ee6bd6b45588729c0a1b44897d508052
|
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -456,12 +456,10 @@ Commit and deploy away. The first deploy may take a few minutes.
|
|
456
456
|
|
457
457
|
## Forecasting
|
458
458
|
|
459
|
-
Blazer has experimental support for two different forecasting methods.
|
459
|
+
Blazer has experimental support for two different forecasting methods. [Example](https://blazer.dokkuapp.com/queries/18-forecast?forecast=t)
|
460
460
|
|
461
461
|
A forecast link will appear for queries that return 2 columns with types timestamp and numeric.
|
462
462
|
|
463
|
-
[Example](https://blazer.dokkuapp.com/queries/18-forecast?forecast=t)
|
464
|
-
|
465
463
|
### Prophet
|
466
464
|
|
467
465
|
Add [prophet](https://github.com/ankane/prophet) to your Gemfile:
|
@@ -494,7 +492,9 @@ forecasting: trend
|
|
494
492
|
|
495
493
|
## Uploads
|
496
494
|
|
497
|
-
Blazer has experimental support for creating database tables from CSV files.
|
495
|
+
Blazer has experimental support for creating database tables from CSV files. [Example](https://blazer.dokkuapp.com/uploads)
|
496
|
+
|
497
|
+
Run:
|
498
498
|
|
499
499
|
```sh
|
500
500
|
rails generate blazer:uploads
|
@@ -510,7 +510,7 @@ uploads:
|
|
510
510
|
data_source: main
|
511
511
|
```
|
512
512
|
|
513
|
-
This feature requires PostgreSQL. Create a new schema just for uploads
|
513
|
+
This feature requires PostgreSQL. Create a new schema just for uploads.
|
514
514
|
|
515
515
|
```sql
|
516
516
|
CREATE SCHEMA uploads;
|
@@ -93,7 +93,12 @@ module Blazer
|
|
93
93
|
|
94
94
|
contents = file.read
|
95
95
|
rows = CSV.parse(contents, converters: %i[numeric date date_time])
|
96
|
-
|
96
|
+
|
97
|
+
# friendly column names
|
98
|
+
columns = rows.shift.map { |v| v.to_s.encode("UTF-8").gsub("%", " pct ").parameterize.gsub("-", "_") }
|
99
|
+
duplicate_column = columns.find { |c| columns.count(c) > 1 }
|
100
|
+
raise Blazer::UploadError, "Duplicate column name: #{duplicate_column}" if duplicate_column
|
101
|
+
|
97
102
|
column_types =
|
98
103
|
columns.size.times.map do |i|
|
99
104
|
values = rows.map { |r| r[i] }.uniq.compact
|
@@ -110,13 +115,19 @@ module Blazer
|
|
110
115
|
end
|
111
116
|
end
|
112
117
|
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
Blazer.uploads_connection.
|
117
|
-
|
118
|
-
Blazer.uploads_connection.
|
118
|
+
begin
|
119
|
+
# maybe SET LOCAL statement_timeout = '30s'
|
120
|
+
# maybe regenerate CSV in Ruby to ensure consistent parsing
|
121
|
+
Blazer.uploads_connection.transaction do
|
122
|
+
Blazer.uploads_connection.execute("DROP TABLE IF EXISTS #{Blazer.uploads_table_name(drop)}") if drop
|
123
|
+
Blazer.uploads_connection.execute("CREATE TABLE #{upload.table_name} (#{columns.map.with_index { |c, i| "#{Blazer.uploads_connection.quote_column_name(c)} #{column_types[i]}" }.join(", ")})")
|
124
|
+
Blazer.uploads_connection.raw_connection.copy_data("COPY #{upload.table_name} FROM STDIN CSV HEADER") do
|
125
|
+
Blazer.uploads_connection.raw_connection.put_copy_data(contents)
|
126
|
+
end
|
119
127
|
end
|
128
|
+
rescue ActiveRecord::StatementInvalid => e
|
129
|
+
raise Blazer::UploadError, "Table already exists" if e.message.include?("PG::DuplicateTable")
|
130
|
+
raise e
|
120
131
|
end
|
121
132
|
end
|
122
133
|
|
data/lib/blazer/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: blazer
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.3.
|
4
|
+
version: 2.3.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Andrew Kane
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-11-
|
11
|
+
date: 2020-11-24 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: railties
|