Skip to content
Snippets Groups Projects
Unverified Commit 2ba5c4d9 authored by Chris Truter's avatar Chris Truter Committed by GitHub
Browse files

Stop serializing LegacyMetric (#47268)

parent de7ff21d
Branches
Tags
No related merge requests found
......@@ -52,9 +52,9 @@
"GroupTableAccessPolicy"
"HTTPAction"
"ImplicitAction"
"LoginHistory"
"LegacyMetric"
"LegacyMetricImportantField"
"LoginHistory"
"ModelIndex"
"ModelIndexValue"
"ModerationReview"
......
......@@ -3,7 +3,6 @@
It is passed in as an `:aggregation` clause but is replaced by the `expand-macros` middleware with the appropriate
clauses."
(:require
[clojure.set :as set]
[medley.core :as m]
[metabase.api.common :as api]
[metabase.models.audit-log :as audit-log]
......@@ -11,7 +10,6 @@
[metabase.models.database :as database]
[metabase.models.interface :as mi]
[metabase.models.revision :as revision]
[metabase.models.serialization :as serdes]
[metabase.util :as u]
[metabase.util.i18n :refer [tru]]
[methodical.core :as methodical]
......@@ -86,38 +84,6 @@
(get-in base-diff [:before :definition])) (assoc :definition {:before (get metric1 :definition)
:after (get metric2 :definition)})))))
;;; ------------------------------------------------- SERIALIZATION --------------------------------------------------
(defmethod serdes/hash-fields LegacyMetric
[_metric]
[:name (serdes/hydrated-hash :table) :created_at])
(defmethod serdes/extract-one "LegacyMetric"
[_model-name _opts metric]
(-> (serdes/extract-one-basics "LegacyMetric" metric)
(update :table_id serdes/*export-table-fk*)
(update :creator_id serdes/*export-user*)
(update :definition serdes/export-mbql)))
(defmethod serdes/load-xform "LegacyMetric" [metric]
(-> metric
serdes/load-xform-basics
(update :table_id serdes/*import-table-fk*)
(update :creator_id serdes/*import-user*)
(update :definition serdes/import-mbql)))
(defmethod serdes/dependencies "LegacyMetric" [{:keys [definition table_id]}]
(into [] (set/union #{(serdes/table->path table_id)}
(serdes/mbql-deps definition))))
(defmethod serdes/storage-path "LegacyMetric" [metric _ctx]
(let [{:keys [id label]} (-> metric serdes/path last)]
(-> metric
:table_id
serdes/table->path
serdes/storage-table-path-prefix
(concat ["metrics" (serdes/storage-leaf-file-name id label)]))))
;;; ------------------------------------------------ Audit Log --------------------------------------------------------
(defmethod audit-log/model-details :model/LegacyMetric
......
......@@ -4,12 +4,9 @@
[metabase.models :refer [Database Table]]
[metabase.models.legacy-metric :as metric :refer [LegacyMetric]]
[metabase.models.revision :as revision]
[metabase.models.serialization :as serdes]
[metabase.test :as mt]
[toucan2.core :as t2]
[toucan2.tools.with-temp :as t2.with-temp])
(:import
(java.time LocalDateTime)))
[toucan2.tools.with-temp :as t2.with-temp]))
(set! *warn-on-reflection* true)
......@@ -114,13 +111,3 @@
{:name "A"
:description "Unchanged"
:definition {:filter [:and [:> 4 "2014-10-19"]]}}))))))
(deftest identity-hash-test
(testing "Metric hashes are composed of the metric name and table identity-hash"
(let [now (LocalDateTime/of 2022 9 1 12 34 56)]
(mt/with-temp [Database db {:name "field-db" :engine :h2}
Table table {:schema "PUBLIC" :name "widget" :db_id (:id db)}
LegacyMetric metric {:name "measurement" :table_id (:id table) :created_at now}]
(is (= "a2318866"
(serdes/raw-hash ["measurement" (serdes/identity-hash table) now])
(serdes/identity-hash metric)))))))
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment