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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: c22ffd3b33bca8c53e32df849e161eaf654cc480b75ee09d4c1eba5a2728b2d1
4
- data.tar.gz: 604d3ec2f9bc97ad85aef289392306132a6e8fd165f11f0b099a6219d40bd0c9
3
+ metadata.gz: 71bd121d2bace5612677090372e36ebdd89eb09398bd7510ba38c666351c1eb4
4
+ data.tar.gz: 4b109076d6af5aee545f4c19311b431feb68bc7e31f45e28704a99fe7692595b
5
5
  SHA512:
6
- metadata.gz: 001d81b65da57fc18c62579df60864715ce6073bc1328696dd2d9c2b3dd14c3087ea9151c8676e853eaf5c7b705896ceab93db2a77e6703cdaffd7742e9b05dd
7
- data.tar.gz: f7ad912b5bb3114f8d74eba474f394b4962d46a51c4f01a6d360c44da2e19943ebf17fd82a61dc3d2c0e8dbbee311ba6153a4d7fae3d3e2541a44b90f580db7b
6
+ metadata.gz: 035bcb0b2252cd10514b5ab3f28c78b4ae6b6b6b534d99948f20815076661cf7fe85200debcf64ab11c6e5307fc24c326daea76f361f6c474e8216b69ebbbe35
7
+ data.tar.gz: 4838d7ee13b888d005602916d309825f716cd868287b0f1843aa92bf1a96d5f43168f22de3430c7b2ba6b4ab25fc71e1ee6bd6b45588729c0a1b44897d508052
@@ -1,3 +1,7 @@
1
+ ## 2.3.1 (2020-11-23)
2
+
3
+ - Improved column names for uploads
4
+
1
5
  ## 2.3.0 (2020-11-16)
2
6
 
3
7
  - Added support for archiving queries
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. Run:
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 to ensure existing tables aren’t overwritten.
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
- columns = rows.shift.map(&:to_s)
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
- # maybe SET LOCAL statement_timeout = '30s'
114
- Blazer.uploads_connection.transaction do
115
- Blazer.uploads_connection.execute("DROP TABLE IF EXISTS #{Blazer.uploads_table_name(drop)}") if drop
116
- 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(", ")})")
117
- Blazer.uploads_connection.raw_connection.copy_data("COPY #{upload.table_name} FROM STDIN CSV HEADER") do
118
- Blazer.uploads_connection.raw_connection.put_copy_data(contents)
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
 
@@ -1,3 +1,3 @@
1
1
  module Blazer
2
- VERSION = "2.3.0"
2
+ VERSION = "2.3.1"
3
3
  end
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.0
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-16 00:00:00.000000000 Z
11
+ date: 2020-11-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: railties