Skip to content

Business intelligence made simple

Merge branch 'query_editable'

Andrew Kane7a2ae7845f9c
diff --cc app/models/blazer/query.rb
index 60acf64f,621924b2..364b7e54
--- a/app/models/blazer/query.rb
+++ b/app/models/blazer/query.rb
@@@ -19,7 -19,9 +19,9 @@@ module Blaze
end
def editable?(user)
- !persisted? || (name.present? && name.first != "*" && name.first != "#") || user == creator
- editable = !persisted? || (name.present? && name.first != "*") || user == creator
++ editable = !persisted? || (name.present? && name.first != "*" && name.first != "#") || user == creator
+ editable &&= Blazer.query_editable.call(self, user) if Blazer.query_editable
+ editable
end
end
end
diff --cc app/views/blazer/queries/_form.html.erb
index c5ae7599,888e1314..e702ce35
--- a/app/views/blazer/queries/_form.html.erb
+++ b/app/views/blazer/queries/_form.html.erb
@@@ -12,12 -12,11 +12,12 @@@
</div>
</div>
<div class="form-group text-right">
- <div class="pull-left" style="margin-top: 6px;">
+ <div class="pull-left" style="margin-top: 9px;">
<%= link_to "Back", :back %>
</div>
+ <%= link_to "Schema", "#", target: "_blank", id: "view-schema", style: "margin-right: 10px;" %>
- <%= f.select :data_source, Blazer.data_sources.values.map { |ds| [ds.name, ds.id] }, {}, class: ("hide" if Blazer.data_sources.size == 1), style: "width: 140px;" %>
+ <%= f.select :data_source, Blazer.data_sources.values.select { |ds| q = @query.dup; q.data_source = ds.id; q.editable?(blazer_user) }.map { |ds| [ds.name, ds.id] }, {}, class: ("hide" if Blazer.data_sources.size == 1), style: "width: 140px;" %>
- <div id="tables" style="display: inline-block; width: 260px; margin-right: 10px;" class="hide">
+ <div id="tables" style="display: inline-block; width: 250px; margin-right: 10px;" class="hide">
<%= render partial: "tables" %>
</div>
<script>
diff --cc lib/blazer/adapters/base_adapter.rb
index 84c76bf9,7d6553d0..e9b78416
--- a/lib/blazer/adapters/base_adapter.rb
+++ b/lib/blazer/adapters/base_adapter.rb
@@@ -35,10 -31,10 +35,14 @@@ module Blaze
# optional
end
+ def cancel(run_id)
+ # optional
+ end
+
+ def cachable?(statement)
+ true # optional
+ end
+
protected
def settings
diff --cc lib/blazer/adapters/sql_adapter.rb
index 58380680,c12e6e26..57d9fc1a
--- a/lib/blazer/adapters/sql_adapter.rb
+++ b/lib/blazer/adapters/sql_adapter.rb
@@@ -72,23 -66,12 +72,27 @@@ module Blaze
nil
end
+ def cancel(run_id)
+ if postgresql?
+ select_all("SELECT pg_cancel_backend(pid) FROM pg_stat_activity WHERE pid <> pg_backend_pid() AND query LIKE '%,run_id:#{run_id}%'")
+ elsif redshift?
+ first_row = select_all("SELECT pid FROM stv_recents WHERE status = 'Running' AND query LIKE '%,run_id:#{run_id}%'").first
+ if first_row
+ select_all("CANCEL #{first_row["pid"].to_i}")
+ end
+ end
+ end
+
+ def cachable?(statement)
+ !%w[CREATE ALTER UPDATE INSERT DELETE].include?(statement.split.first.to_s.upcase)
+ end
+
protected
+ def select_all(statement)
+ connection_model.connection.select_all(statement)
+ end
+
def postgresql?
["PostgreSQL", "PostGIS"].include?(adapter_name)
end