blazer 1.6.0 → 1.6.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
  SHA1:
3
- metadata.gz: 04d14bae947237ea5450d0c8104572d41030e2ba
4
- data.tar.gz: 1cf2e2ecad47ab458a653382728911dfaa82b1d9
3
+ metadata.gz: 2c31bc7010e3093044d6a2983172c97ed52f3009
4
+ data.tar.gz: a40086b84c9964fec00038bd4c4a2b2128ee7bf7
5
5
  SHA512:
6
- metadata.gz: 6331237e96ba16d02561cfeb1f2de6e95abdbc2b6f2069cdfa2a72309e92720137ae899498b4ac177abc9b3fb663293950006ff84e186560101b0786c9a6c75a
7
- data.tar.gz: b71679dded9d87c6637c082da7a41bda1ff448122fbfd3de62b1a8d8b5604b14196a26a96d8b2a14b0db38e65b77a8f2e0299761b3c25f411955541ce276e865
6
+ metadata.gz: 51b03a70d9acc454fe316edaacd87b102e3d832e420190037d674fe67d675e1a569c6a8055d7ee4c5be6237c53c2143f153bee6b5a31711567e2554f7c0cbfaa
7
+ data.tar.gz: 814bd7bd06a5d42ba29504a4d1511890df47d9ae89076b2580532211f5aa9b54f59b0cc2d9b98a4d72fac17ce538e66d3e2d09d78858f48c45ae43e4ab45a446
@@ -1,3 +1,9 @@
1
+ ## 1.6.1
2
+
3
+ - Added support for Presto [beta]
4
+ - Added support for Elasticsearch timeouts
5
+ - Fixed error in Rails 5
6
+
1
7
  ## 1.6.0
2
8
 
3
9
  - Added support for MongoDB [beta]
data/README.md CHANGED
@@ -111,6 +111,16 @@ GRANT SELECT, SHOW VIEW ON database_name.* TO blazer@’127.0.0.1′ IDENTIFIED
111
111
  FLUSH PRIVILEGES;
112
112
  ```
113
113
 
114
+ ### MongoDB
115
+
116
+ Create a user with read only permissions:
117
+
118
+ ```
119
+ db.createUser({user: "blazer", pwd: "password", roles: ["read"]})
120
+ ```
121
+
122
+ Also, make sure authorization is enabled when you start the server.
123
+
114
124
  ### Sensitive Data
115
125
 
116
126
  To protect sensitive info like password hashes and access tokens, use views. Documentation coming soon.
@@ -357,6 +367,7 @@ data_sources:
357
367
  - [Redshift](#redshift)
358
368
  - [MongoDB](#mongodb) [beta]
359
369
  - [Elasticsearch](#elasticsearch) [beta]
370
+ - [Presto](#presto) [beta]
360
371
 
361
372
  You can also create an adapter for any other data store.
362
373
 
@@ -399,6 +410,16 @@ data_sources:
399
410
  url: http://user:password@hostname:9200/
400
411
  ```
401
412
 
413
+ ### Presto
414
+
415
+ Add [presto-client](https://github.com/treasure-data/presto-client-ruby) to your Gemfile and set:
416
+
417
+ ```yml
418
+ data_sources:
419
+ my_source:
420
+ url: presto://user@hostname:8080/catalog
421
+ ```
422
+
402
423
  ## Learn SQL
403
424
 
404
425
  Have team members who want to learn SQL? Here are a few great, free resources.
@@ -415,7 +436,7 @@ For an easy way to group by day, week, month, and more with correct time zones,
415
436
  Add the [R buildpack](https://github.com/virtualstaticvoid/heroku-buildpack-r) to your app.
416
437
 
417
438
  ```sh
418
- heroku buildpacks:add --index 1 https://github.com/ankane/heroku-buildpack-r.git\#cedar-14
439
+ heroku buildpacks:add --index 1 https://github.com/virtualstaticvoid/heroku-buildpack-r.git\#cedar-14
419
440
  ```
420
441
 
421
442
  And create an `init.r` with:
@@ -6,7 +6,6 @@ module Blazer
6
6
  skip_before_action(*filters, raise: false)
7
7
  skip_after_action(*filters, raise: false)
8
8
  skip_around_action(*filters, raise: false)
9
- before_action :verify_request_size
10
9
  else
11
10
  skip_action_callback *filters
12
11
  end
@@ -12,7 +12,7 @@ module Blazer
12
12
  BLAZER_IMAGE_EXT = %w[png jpg jpeg gif]
13
13
 
14
14
  def blazer_format_value(key, value)
15
- if value.is_a?(Integer) && !key.to_s.end_with?("id")
15
+ if value.is_a?(Integer) && !key.to_s.end_with?("id") && !key.to_s.start_with?("id")
16
16
  number_with_delimiter(value)
17
17
  elsif value =~ BLAZER_URL_REGEX
18
18
  # see if image or link
@@ -172,7 +172,7 @@
172
172
  </script>
173
173
  <% end %>
174
174
 
175
- <% if Blazer.data_sources[@query.data_source].adapter == "activerecord" %>
175
+ <% if %w[sql presto].include?(Blazer.data_sources[@query.data_source].adapter) %>
176
176
  <script>
177
177
  // do not highlight really long queries
178
178
  // this can lead to performance issues
@@ -9,6 +9,7 @@ require "blazer/run_statement"
9
9
  require "blazer/adapters/base_adapter"
10
10
  require "blazer/adapters/elasticsearch_adapter"
11
11
  require "blazer/adapters/mongodb_adapter"
12
+ require "blazer/adapters/presto_adapter"
12
13
  require "blazer/adapters/sql_adapter"
13
14
  require "blazer/engine"
14
15
 
@@ -8,16 +8,22 @@ module Blazer
8
8
 
9
9
  begin
10
10
  header, body = statement.gsub(/\/\/.+/, "").strip.split("\n", 2)
11
- response = client.msearch(body: [JSON.parse(header), JSON.parse(body)])["responses"].first
12
- hits = response["hits"]["hits"]
13
- source_keys = hits.flat_map { |r| r["_source"].keys }.uniq
14
- hit_keys = (hits.first.try(:keys) || []) - ["_source"]
15
- columns = source_keys + hit_keys
16
- rows =
17
- hits.map do |r|
18
- source = r["_source"]
19
- source_keys.map { |k| source[k] } + hit_keys.map { |k| r[k] }
20
- end
11
+ body = JSON.parse(body)
12
+ body["timeout"] ||= data_source.timeout if data_source.timeout
13
+ response = client.msearch(body: [JSON.parse(header), body])["responses"].first
14
+ if response["error"]
15
+ error = response["error"]
16
+ else
17
+ hits = response["hits"]["hits"]
18
+ source_keys = hits.flat_map { |r| r["_source"].keys }.uniq
19
+ hit_keys = (hits.first.try(:keys) || []) - ["_source"]
20
+ columns = source_keys + hit_keys
21
+ rows =
22
+ hits.map do |r|
23
+ source = r["_source"]
24
+ source_keys.map { |k| source[k] } + hit_keys.map { |k| r[k] }
25
+ end
26
+ end
21
27
  rescue => e
22
28
  error = e.message
23
29
  end
@@ -26,7 +32,7 @@ module Blazer
26
32
  end
27
33
 
28
34
  def tables
29
- client.indices.get_aliases.map { |k, v| [k, v["aliases"].keys] }.flatten.uniq.sort
35
+ client.indices.get_aliases(name: "*").map { |k, v| [k, v["aliases"].keys] }.flatten.uniq.sort
30
36
  end
31
37
 
32
38
  def preview_statement
@@ -0,0 +1,45 @@
1
+ module Blazer
2
+ module Adapters
3
+ class PrestoAdapter < BaseAdapter
4
+ def run_statement(statement, comment)
5
+ columns = []
6
+ rows = []
7
+ error = nil
8
+
9
+ begin
10
+ columns, rows = client.run("#{statement} /*#{comment}*/")
11
+ columns = columns.map(&:name)
12
+ rescue => e
13
+ error = e.message
14
+ end
15
+
16
+ [columns, rows, error]
17
+ end
18
+
19
+ def tables
20
+ _, rows = client.run("SHOW TABLES")
21
+ rows.map(&:first)
22
+ end
23
+
24
+ def preview_statement
25
+ "SELECT * FROM {table} LIMIT 10"
26
+ end
27
+
28
+ protected
29
+
30
+ def client
31
+ @client ||= begin
32
+ uri = URI.parse(settings["url"])
33
+ query = uri.query ? CGI::parse(uri.query) : {}
34
+ Presto::Client.new(
35
+ server: "#{uri.host}:#{uri.port}",
36
+ catalog: uri.path.to_s.sub(/\A\//, ""),
37
+ schema: query["schema"] || "public",
38
+ user: uri.user,
39
+ http_debug: false
40
+ )
41
+ end
42
+ end
43
+ end
44
+ end
45
+ end
@@ -18,12 +18,14 @@ module Blazer
18
18
 
19
19
  @adapter_instance =
20
20
  case adapter
21
- when "sql"
22
- Blazer::Adapters::SqlAdapter.new(self)
23
21
  when "elasticsearch"
24
22
  Blazer::Adapters::ElasticsearchAdapter.new(self)
25
23
  when "mongodb"
26
24
  Blazer::Adapters::MongodbAdapter.new(self)
25
+ when "presto"
26
+ Blazer::Adapters::PrestoAdapter.new(self)
27
+ when "sql"
28
+ Blazer::Adapters::SqlAdapter.new(self)
27
29
  else
28
30
  raise Blazer::Error, "Unknown adapter"
29
31
  end
@@ -178,8 +180,10 @@ module Blazer
178
180
  end
179
181
 
180
182
  def detect_adapter
181
- if settings["url"].to_s.start_with?("mongodb://")
182
- "mongodb"
183
+ schema = settings["url"].to_s.split("://").first
184
+ case schema
185
+ when "mongodb", "presto"
186
+ schema
183
187
  else
184
188
  "sql"
185
189
  end
@@ -1,3 +1,3 @@
1
1
  module Blazer
2
- VERSION = "1.6.0"
2
+ VERSION = "1.6.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: 1.6.0
4
+ version: 1.6.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: 2016-07-29 00:00:00.000000000 Z
11
+ date: 2016-07-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -162,6 +162,7 @@ files:
162
162
  - lib/blazer/adapters/base_adapter.rb
163
163
  - lib/blazer/adapters/elasticsearch_adapter.rb
164
164
  - lib/blazer/adapters/mongodb_adapter.rb
165
+ - lib/blazer/adapters/presto_adapter.rb
165
166
  - lib/blazer/adapters/sql_adapter.rb
166
167
  - lib/blazer/data_source.rb
167
168
  - lib/blazer/detect_anomalies.R