-
Notifications
You must be signed in to change notification settings - Fork 4.9k
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
MLv2 Move metadata calculation functions into respective namespaces #29245
Conversation
:single-key-in {:level :warning} | ||
:keyword-binding {:level :warning} | ||
:shadowed-var {:level :warning} | ||
:metabase/deftest-not-marked-parallel-or-synchronized {:level :warning}}}}} |
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 added a custom Kondo linter to require that metabase.lib.*
tests are marked either ^:parallel
or ^:synchronous
if for some reason you don't want them to be parallel. Hopefully this will help us remember to make them all ^:parallel
and thus fast
:stage-number stage-number}))) | ||
(nth aggregations index))) | ||
|
||
(defmethod lib.metadata.calculation/describe-top-level-key :aggregation |
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.
Clojure(Script) impl of query description logic
[metabase.util.malli :as mu]) | ||
#?(:cljs (:require-macros [metabase.lib.aggregation]))) | ||
|
||
(mu/defn resolve-aggregation :- ::lib.schema.aggregation/aggregation |
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.
Moved some of the existing code that was in metabase.lib.metadata.calculate.resolve
to places that actually need/use it
(for [aggregation aggregations] | ||
(lib.metadata.calculation/display-name query stage-number aggregation))))) | ||
|
||
(defmethod lib.metadata.calculation/metadata :aggregation |
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.
All this stuff is already in, I just moved it over from the old namespaces
@@ -0,0 +1,150 @@ | |||
(ns metabase.lib.js.metadata |
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.
JavaScript implementation of a MetadataProvider
that works with the metadata available to Question.ts
(#?(:clj p/defprotocol+ :cljs defprotocol) DatabaseMetadataProvider | ||
(#?(:clj p/defprotocol+ :cljs defprotocol) MetadataProvider |
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 reworked the DatabaseMetadataProvider
protocol to include a lot more stuff that was on the TODO-list, for example methods to fetch specific tables by ID and other things that we're going to need eventually when we implement a QP store version of the provider or try to hook it in to the Redux store if we end up doing that
I added methods for Metrics and Segments too which we will need sooner rather than later. Metadata.ts
already has them. Since this isn't just DB stuff anymore I renamed it to MetadataProvider
|
||
(declare stage-metadata) | ||
|
||
(mu/defn ^:private breakout-columns :- [:maybe [:sequential lib.metadata/ColumnMetadata]] |
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.
All this stuff is just moved over from metabase.lib.metadata.calculate
[metabase.util.malli :as mu] | ||
#?@(:clj | ||
([potemkin :as p])) | ||
#?@(:cljs | ||
([goog.string :as gstring] | ||
[goog.string.format :as gstring.format])))) |
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 finally added metabase.lib.util/format
so we can use it in both Clojure and ClojureScript
([table field options] | ||
[:field (merge {:lib/uuid (str (random-uuid))} options) (meta/id table field)])) | ||
|
||
(deftest ^:parallel aggregation-names-test |
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.
Most of these tests already existed, I just moved them so they live in the same namespace as the clauses they're testing
@@ -0,0 +1,64 @@ | |||
(ns metabase.lib.test-util |
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.
Added new test util namespace for stuff I found myself using in a bunch of different tests.
options) | ||
(meta/id table field)])) | ||
|
||
(defn mock-metadata-provider |
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.
Mock metadata provider for those rare cases when we need to test stuff not covered by test-metadata/provider
, e.g. nested columns
|
||
;;; TODO -- merge this stuff into `defop` somehow. | ||
|
||
(defmethod lib.metadata.calculation/display-name-method :aggregation |
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.
display-name-method
here rhymes with clojure.core/print-method
. This was previously called display-name*
but I decided this was more meaningful and makes it clearer when you should use display-name
(the wrapper function with error handling and type checking) vs display-name-method
... display-name-method
makes it clearer that you should implement display-name-method
but call display-name
than before.
Codecov ReportPatch coverage:
Additional details and impacted files@@ Coverage Diff @@
## master #29245 +/- ##
==========================================
- Coverage 68.48% 68.45% -0.03%
==========================================
Files 2785 2788 +3
Lines 96184 96434 +250
Branches 12290 12298 +8
==========================================
+ Hits 65867 66018 +151
- Misses 25140 25231 +91
- Partials 5177 5185 +8
Flags with carried forward coverage won't be shown. Click here to find out more.
... and 4 files with indirect coverage changes Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here. ☔ View full report in Codecov by Sentry. |
src/metabase/lib/expressions.cljc
Outdated
@@ -0,0 +1,143 @@ | |||
(ns metabase.lib.expressions |
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 think this should be singular for consistency with lib.schema.expression
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.
good call. I've changed it
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 hope we can move column-name
and display-name
into defop
soon, lots of boilerplate right now and it would be very easy to miss implementing one of the 3-4 multimethods that are really required for each clause.
@@ -81,3 +100,49 @@ | |||
(-> q1 | |||
(lib/join q2 (lib/= venues-category-id-metadata categories-id-metadata)) | |||
(dissoc :lib/metadata))))))) | |||
|
|||
;;; FIXME |
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.
Is this for later?
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.
yes
(describe-legacy-query-order-by query))))) | ||
|
||
(deftest ^:parallel describe-order-by-expression-reference-test | ||
;; it("should work with expressions", () => { |
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.
looks like an unimplemented test
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.
Oops. I'll fix this in the follow on PR I'm working on that actually flips the switch to use this in JavaScript, I need to add a few more tests there anyway
No failed tests 🎉 |
Split off from #29200
This is the Clojure-only side of #29200, I think it makes sense to try to get this stuff in now while I iron out the bugs in some of the e2e tests to avoid more merge conflicts in the future.
display-name
,column-name
, etc. and moved their implementations to live with the other functions related to them. E.g. thedisplay-name
method for aggregations lives inmetabase.lib.aggregations
now, instead of inmetabase.lib.metadata.calculate.names
. About 90% of this PR is just moving stuff around so it's easier to deal with going forward.