Skip to content
Snippets Groups Projects
Commit 9cc03d5b authored by Allen Gilliland's avatar Allen Gilliland
Browse files

Merge pull request #1773 from metabase/smart-aggregation-options

Smart aggregation options
parents 96692002 60445fa7
Branches
Tags
No related merge requests found
......@@ -364,7 +364,8 @@ var Aggregators = [{
"name": "Standard deviation of ...",
"short": "stddev",
"description": "Number which expresses how much the values of a column vary among all rows in the answer.",
"validFieldsFilters": [summableFields]
"validFieldsFilters": [summableFields],
"requiredDriverFeature": "standard-deviation-aggregations"
}];
var BreakoutAggregator = {
......@@ -386,9 +387,16 @@ function populateFields(aggregator, fields) {
};
}
function getAggregators(fields) {
return _.map(Aggregators, function(aggregator) {
return populateFields(aggregator, fields);
function getAggregators(table) {
const supportedAggregations = Aggregators.filter(function (agg) {
if (agg.requiredDriverFeature && !_.contains(table.db.features, agg.requiredDriverFeature)) {
return false;
} else {
return true;
}
});
return _.map(supportedAggregations, function(aggregator) {
return populateFields(aggregator, table.fields);
});
}
......@@ -403,7 +411,7 @@ export function addValidOperatorsToFields(table) {
for (let field of table.fields) {
field.valid_operators = getOperators(field, table);
}
table.aggregation_options = getAggregators(table.fields);
table.aggregation_options = getAggregators(table);
table.breakout_options = getBreakouts(table.fields);
return table;
}
......
......@@ -299,7 +299,7 @@
(or ((keyword engine) @registered-drivers)
(let [namespce (symbol (format "metabase.driver.%s" (name engine)))]
(log/debug (format "Loading driver '%s'..." engine))
(require namespce)
(u/try-ignore-exceptions (require namespce))
((keyword engine) @registered-drivers))))
......
......@@ -12,7 +12,13 @@
(i/defentity Database :metabase_database)
(defn- pre-cascade-delete [{:keys [id] :as database}]
(defn- post-select [{:keys [engine] :as database}]
(if-not engine database
(assoc database :features (if-let [driver ((resolve 'metabase.driver/engine->driver) engine)]
((resolve 'metabase.driver/features) driver)
[]))))
(defn- pre-cascade-delete [{:keys [id]}]
(cascade-delete 'Card :database_id id)
(cascade-delete 'Table :db_id id))
......@@ -29,6 +35,7 @@
:timestamped? (constantly true)
:can-read? (constantly true)
:can-write? i/superuser?
:post-select post-select
:pre-cascade-delete pre-cascade-delete}))
......
......@@ -506,6 +506,12 @@
(last args)
[(last args)]))))
(defmacro try-ignore-exceptions
"Simple macro which wraps the given expression in a try/catch block and ignores the exception if caught."
[& body]
`(try ~@body (catch Throwable e#)))
(defn wrap-try-catch!
"Re-intern FN-SYMB as a new fn that wraps the original with a `try-catch`. Intended for debugging.
......
......@@ -25,36 +25,35 @@
:ssl false}
:is_full_sync full-sync?})))
(defn- db-details
([]
(db-details (db)))
([db]
(match-$ db
{:created_at $
:engine "h2"
:id $
:details $
:updated_at $
:name "test-data"
:is_sample false
:is_full_sync true
:organization_id nil
:description nil
:features (mapv name (metabase.driver/features (metabase.driver/engine->driver (:engine db))))})))
;; # DB LIFECYCLE ENDPOINTS
;; ## GET /api/database/:id
;; regular users *should not* see DB details
(expect
(match-$ (db)
{:created_at $
:engine "h2"
:id $
:updated_at $
:name "test-data"
:is_sample false
:is_full_sync true
:organization_id nil
:description nil})
(dissoc (db-details) :details)
((user->client :rasta) :get 200 (format "database/%d" (id))))
;; superusers *should* see DB details
(expect
(match-$ (db)
{:created_at $
:engine "h2"
:id $
:details $
:updated_at $
:name "test-data"
:is_sample false
:is_full_sync true
:organization_id nil
:description nil})
(db-details)
((user->client :crowberto) :get 200 (format "database/%d" (id))))
;; ## POST /api/database
......@@ -71,7 +70,8 @@
:is_sample false
:is_full_sync false
:organization_id nil
:description nil})
:description nil
:features (mapv name (metabase.driver/features (metabase.driver/engine->driver :postgres)))})
(create-db db-name false)))
;; ## DELETE /api/database/:id
......@@ -125,7 +125,8 @@
:is_sample false
:is_full_sync true
:organization_id nil
:description nil})))
:description nil
:features (mapv name (metabase.driver/features (metabase.driver/engine->driver engine)))})))
(match-$ (sel :one Database :name db-name)
{:created_at $
:engine "postgres"
......@@ -135,7 +136,8 @@
:is_sample false
:is_full_sync true
:organization_id nil
:description nil}))))
:description nil
:features (mapv name (metabase.driver/features (metabase.driver/engine->driver :postgres)))}))))
(do
;; Delete all the randomly created Databases we've made so far
(cascade-delete Database :id [not-in (set (filter identity
......@@ -161,6 +163,7 @@
:is_full_sync true
:organization_id nil
:description nil
:features (mapv name (metabase.driver/features (metabase.driver/engine->driver :h2)))
:tables [(match-$ (Table (id :categories))
{:description nil
:entity_type nil
......
......@@ -8,6 +8,20 @@
[metabase.test.data.users :refer :all]
[metabase.test.util :refer [match-$ expect-eval-actual-first]]))
;; Helper Fns
(defn- db-details []
(match-$ (db)
{:created_at $
:engine "h2"
:id $
:updated_at $
:name "test-data"
:is_sample false
:is_full_sync true
:organization_id nil
:description nil
:features (mapv name (metabase.driver/features (metabase.driver/engine->driver :h2)))}))
;; ## GET /api/field/:id
......@@ -19,16 +33,7 @@
{:description nil
:entity_type nil
:visibility_type nil
:db (match-$ (db)
{:created_at $
:engine "h2"
:id $
:updated_at $
:name "test-data"
:is_sample false
:is_full_sync true
:organization_id nil
:description nil})
:db (db-details)
:schema "PUBLIC"
:name "USERS"
:display_name "Users"
......
......@@ -24,6 +24,22 @@
(expect (get middleware/response-unauthentic :body) (http/client :get 401 (format "table/%d" (id :users))))
;; Helper Fns
(defn- db-details []
(match-$ (db)
{:created_at $
:engine "h2"
:id $
:updated_at $
:name "test-data"
:is_sample false
:is_full_sync true
:organization_id nil
:description nil
:features (mapv name (metabase.driver/features (metabase.driver/engine->driver :h2)))}))
;; ## GET /api/table?org
;; These should come back in alphabetical order and include relevant metadata
(expect
......@@ -62,16 +78,7 @@
{:description nil
:entity_type nil
:visibility_type nil
:db (match-$ (db)
{:created_at $
:engine "h2"
:id $
:updated_at $
:name "test-data"
:is_sample false
:is_full_sync true
:organization_id nil
:description nil})
:db (db-details)
:schema "PUBLIC"
:name "VENUES"
:display_name "Venues"
......@@ -124,16 +131,7 @@
{:description nil
:entity_type nil
:visibility_type nil
:db (match-$ (db)
{:created_at $
:engine "h2"
:id $
:updated_at $
:name "test-data"
:is_sample false
:is_full_sync true
:organization_id nil
:description nil})
:db (db-details)
:schema "PUBLIC"
:name "CATEGORIES"
:display_name "Categories"
......@@ -207,16 +205,7 @@
{:description nil
:entity_type nil
:visibility_type nil
:db (match-$ (db)
{:created_at $
:engine "h2"
:id $
:updated_at $
:name "test-data"
:is_sample false
:is_full_sync true
:organization_id nil
:description nil})
:db (db-details)
:schema "PUBLIC"
:name "USERS"
:display_name "Users"
......@@ -318,16 +307,7 @@
{:description nil
:entity_type nil
:visibility_type nil
:db (match-$ (db)
{:created_at $
:engine "h2"
:id $
:updated_at $
:name "test-data"
:is_sample false
:is_full_sync true
:organization_id nil
:description nil})
:db (db-details)
:schema "PUBLIC"
:name "USERS"
:display_name "Users"
......@@ -426,7 +406,8 @@
:details $
:id $
:engine "h2"
:created_at $})
:created_at $
:features (mapv name (metabase.driver/features (metabase.driver/engine->driver :h2)))})
:schema "PUBLIC"
:name "USERS"
:rows 15
......@@ -485,16 +466,7 @@
:id $
:db_id $
:created_at $
:db (match-$ (db)
{:description nil,
:organization_id nil,
:name "test-data",
:is_sample false,
:is_full_sync true,
:updated_at $,
:id $,
:engine "h2",
:created_at $})})})
:db (db-details)})})
:destination (match-$ users-id-field
{:id $
:table_id $
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment