-
Notifications
You must be signed in to change notification settings - Fork 5.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
metabase.analyze
API namespace
#42469
Changes from all commits
37b9c35
78d25b4
44c1939
8a8b312
f79db08
122bbd2
8f7ec72
a9e93b9
37024a2
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
(ns metabase.analyze | ||
"API namespace for the `metabase.analyze` module." | ||
(:require | ||
[metabase.analyze.classifiers.category] | ||
[metabase.analyze.classifiers.core] | ||
[metabase.analyze.classifiers.name] | ||
[metabase.analyze.fingerprint.fingerprinters] | ||
[metabase.analyze.fingerprint.schema] | ||
[metabase.analyze.query-results] | ||
[potemkin :as p])) | ||
|
||
(comment | ||
metabase.analyze.classifiers.category/keep-me | ||
metabase.analyze.classifiers.core/keep-me | ||
metabase.analyze.classifiers.name/keep-me | ||
metabase.analyze.fingerprint.fingerprinters/keep-me | ||
metabase.analyze.fingerprint.schema/keep-me | ||
metabase.analyze.query-results/keep-me) | ||
|
||
(p/import-vars | ||
[metabase.analyze.classifiers.category | ||
auto-list-cardinality-threshold | ||
category-cardinality-threshold] | ||
[metabase.analyze.classifiers.core | ||
run-classifiers] | ||
[metabase.analyze.classifiers.name | ||
infer-entity-type-by-name] | ||
[metabase.analyze.fingerprint.fingerprinters | ||
col-wise | ||
constant-fingerprinter | ||
fingerprint-fields] | ||
[metabase.analyze.fingerprint.schema | ||
Fingerprint] | ||
[metabase.analyze.query-results | ||
ResultsMetadata | ||
insights-rf]) |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -27,6 +27,7 @@ | |
[java-time.api :as t] | ||
[malli.core :as mc] | ||
[medley.core :as m] | ||
[metabase.analyze :as analyze] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This dependency bothers me a bit, in my mind models shouldn't depend on higher level modules, if possible. We could "fix" this by moving the constants out to a general config namespace at some point. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. agreed, but that's a step 2 thing and step 1 is just getting things in modules. It's going to take a while and several iterations to clean everything up |
||
[metabase.db.metadata-queries :as metadata-queries] | ||
[metabase.db.query :as mdb.query] | ||
[metabase.models.interface :as mi] | ||
|
@@ -40,24 +41,13 @@ | |
[methodical.core :as methodical] | ||
[toucan2.core :as t2])) | ||
|
||
(def ^Long category-cardinality-threshold | ||
"Fields with less than this many distinct values should automatically be given a semantic type of `:type/Category`. | ||
This no longer has any meaning whatsoever as far as the backend code is concerned; it is used purely to inform | ||
frontend behavior such as widget choices." | ||
30) | ||
|
||
(def ^Long auto-list-cardinality-threshold | ||
"Fields with less than this many distincy values should be given a `has_field_values` value of `list`, which means | ||
the Field should have FieldValues." | ||
1000) | ||
|
||
(def ^:private ^Long entry-max-length | ||
"The maximum character length for a stored FieldValues entry." | ||
100) | ||
|
||
(def ^:dynamic ^Long *total-max-length* | ||
"Maximum total length for a FieldValues entry (combined length of all values for the field)." | ||
(long (* auto-list-cardinality-threshold entry-max-length))) | ||
(long (* analyze/auto-list-cardinality-threshold entry-max-length))) | ||
|
||
(def ^java.time.Period advanced-field-values-max-age | ||
"Age of an advanced FieldValues in days. | ||
|
@@ -403,7 +393,7 @@ | |
field-name (or (:name field) (:id field))] | ||
(cond | ||
;; If this Field is marked `auto-list`, and the number of values in now over | ||
;; the [[auto-list-cardinality-threshold]] or the accumulated length of all values exceeded | ||
;; the [[analyze/auto-list-cardinality-threshold]] or the accumulated length of all values exceeded | ||
;; the [[*total-max-length*]] threshold we need to unmark it as `auto-list`. Switch it to `has_field_values` = | ||
;; `nil` and delete the FieldValues; this will result in it getting a Search Widget in the UI when | ||
;; `has_field_values` is automatically inferred by the [[metabase.models.field/infer-has-field-values]] hydration | ||
|
@@ -414,7 +404,7 @@ | |
;; way that could make this work. Thus, we are stuck doing it here :( | ||
(and (= :auto-list (keyword (:has_field_values field))) | ||
(or has_more_values | ||
(> (count values) auto-list-cardinality-threshold))) | ||
(> (count values) analyze/auto-list-cardinality-threshold))) | ||
(do | ||
(log/infof | ||
(str "Field %s was previously automatically set to show a list widget, but now has %s values." | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I renamed this because
classifiers.name/infer-entity-type
clearly implied this was based on column name, howeveranalyze/infer-entity-type
lost that clarity