From 38ea154a2629817b0e96840fc31db814650615bc Mon Sep 17 00:00:00 2001
From: Cam Saul <1455846+camsaul@users.noreply.github.com>
Date: Wed, 23 Mar 2022 19:47:59 -0700
Subject: [PATCH] Replace remaining references to `qp/query->preprocessed` with
 `qp/preprocess` (#21047)

* Remove references to qp/query->preprocessed

* Fix Oracle
---
 .clj-kondo/config.edn                                |  2 --
 .../middleware/row_level_restrictions.clj            |  2 +-
 .../middleware/row_level_restrictions_test.clj       |  2 +-
 .../oracle/test/metabase/driver/oracle_test.clj      |  2 +-
 .../test/metabase/driver/sqlserver_test.clj          |  2 +-
 shared/src/metabase/mbql/schema.cljc                 |  4 ++--
 src/metabase/events/activity_feed.clj                |  2 +-
 src/metabase/models/query/permissions.clj            |  2 +-
 src/metabase/query_processor.clj                     |  5 -----
 src/metabase/query_processor/util/nest_query.clj     |  6 +++---
 test/metabase/driver/sql/query_processor_test.clj    |  2 +-
 .../query_processor/middleware/annotate_test.clj     |  6 +++---
 .../query_processor/util/add_alias_info_test.clj     |  2 +-
 .../query_processor/util/nest_query_test.clj         |  4 ++--
 test/metabase/query_processor_test.clj               | 12 ++++++------
 15 files changed, 24 insertions(+), 31 deletions(-)

diff --git a/.clj-kondo/config.edn b/.clj-kondo/config.edn
index 2c479cf1aee..9caee7acc44 100644
--- a/.clj-kondo/config.edn
+++ b/.clj-kondo/config.edn
@@ -73,8 +73,6 @@
                                       {:namespaces ["metabase\\.driver.*"]}
                                       metabase.driver.sql-jdbc.sync.interface/syncable-schemas
                                       {:namespaces ["metabase\\.driver.*"]}
-                                      metabase.query-processor/query->preprocessed
-                                      {:namespaces ["metabase.*"]}
                                       schema.core/either
                                       {:namespaces ["metabase.*"]}
                                       schema.core/both
diff --git a/enterprise/backend/src/metabase_enterprise/sandbox/query_processor/middleware/row_level_restrictions.clj b/enterprise/backend/src/metabase_enterprise/sandbox/query_processor/middleware/row_level_restrictions.clj
index 75e226d2c44..961837ea458 100644
--- a/enterprise/backend/src/metabase_enterprise/sandbox/query_processor/middleware/row_level_restrictions.clj
+++ b/enterprise/backend/src/metabase_enterprise/sandbox/query_processor/middleware/row_level_restrictions.clj
@@ -138,7 +138,7 @@
                         :query    source-query}
           preprocessed (binding [api/*current-user-id* nil]
                          (classloader/require 'metabase.query-processor)
-                         ((resolve 'metabase.query-processor/query->preprocessed) query))]
+                         ((resolve 'metabase.query-processor/preprocess) query))]
       (select-keys (:query preprocessed) [:source-query :source-metadata]))
     (catch Throwable e
       (throw (ex-info (tru "Error preprocessing source query when applying GTAP: {0}" (ex-message e))
diff --git a/enterprise/backend/test/metabase_enterprise/sandbox/query_processor/middleware/row_level_restrictions_test.clj b/enterprise/backend/test/metabase_enterprise/sandbox/query_processor/middleware/row_level_restrictions_test.clj
index 116ef76fd35..ecb5cf6f681 100644
--- a/enterprise/backend/test/metabase_enterprise/sandbox/query_processor/middleware/row_level_restrictions_test.clj
+++ b/enterprise/backend/test/metabase_enterprise/sandbox/query_processor/middleware/row_level_restrictions_test.clj
@@ -799,7 +799,7 @@
                                                                            :id (mt/id :products :category))
                                                           :database_type "VARCHAR"
                                                           :name          "CATEGORY"}]]
-                                       (get-in (qp/query->preprocessed drill-thru-query) [:query :filter])))))]
+                                       (get-in (qp/preprocess drill-thru-query) [:query :filter])))))]
                         (testing "As an admin"
                           (mt/with-test-user :crowberto
                             (test-preprocessing)
diff --git a/modules/drivers/oracle/test/metabase/driver/oracle_test.clj b/modules/drivers/oracle/test/metabase/driver/oracle_test.clj
index 15d2883e9be..1cd97ba8bba 100644
--- a/modules/drivers/oracle/test/metabase/driver/oracle_test.clj
+++ b/modules/drivers/oracle/test/metabase/driver/oracle_test.clj
@@ -294,7 +294,7 @@
                   :where  [:<= (hsql/raw "rownum") 100]})
                (#'sql.qp/mbql->honeysql
                 :oracle
-                (qp/query->preprocessed
+                (qp/preprocess
                  (mt/mbql-query venues
                    {:source-table $$venues
                     :order-by     [[:asc $id]]
diff --git a/modules/drivers/sqlserver/test/metabase/driver/sqlserver_test.clj b/modules/drivers/sqlserver/test/metabase/driver/sqlserver_test.clj
index c231d060737..320ab7eac65 100644
--- a/modules/drivers/sqlserver/test/metabase/driver/sqlserver_test.clj
+++ b/modules/drivers/sqlserver/test/metabase/driver/sqlserver_test.clj
@@ -150,7 +150,7 @@
                                              :fields       [$name]
                                              :order-by     [[:asc $id]]}
                               :order-by     [[:asc $id]]})
-                           qp/query->preprocessed
+                           qp/preprocess
                            (m/dissoc-in [:query :limit]))]
       (mt/with-everything-store
         (is (= {:query  (str "SELECT \"source\".\"name\" AS \"name\" "
diff --git a/shared/src/metabase/mbql/schema.cljc b/shared/src/metabase/mbql/schema.cljc
index ed9f7aadc04..b9db2574631 100644
--- a/shared/src/metabase/mbql/schema.cljc
+++ b/shared/src/metabase/mbql/schema.cljc
@@ -1444,8 +1444,8 @@
    s/Bool
 
    ;; disable the MBQL->native middleware. If you do this, the query will not work at all, so there are no cases where
-   ;; you should set this yourself. This is only used by the `qp/query->preprocessed` function to get the fully
-   ;; pre-processed query without attempting to convert it to native.
+   ;; you should set this yourself. This is only used by the [[metabase.query-processor/preprocess]] function to get
+   ;; the fully pre-processed query without attempting to convert it to native.
    (s/optional-key :disable-mbql->native?)
    s/Bool
 
diff --git a/src/metabase/events/activity_feed.clj b/src/metabase/events/activity_feed.clj
index a58d56ca66c..4c12e1e0e5e 100644
--- a/src/metabase/events/activity_feed.clj
+++ b/src/metabase/events/activity_feed.clj
@@ -56,7 +56,7 @@
                        ;; around
                        dataset? (assoc :original-model "card"))
         query       (when (seq query)
-                      (try (qp/query->preprocessed query)
+                      (try (qp/preprocess query)
                            (catch Throwable e
                              (log/error e (tru "Error preprocessing query:")))))
         database-id (some-> query :database u/the-id)
diff --git a/src/metabase/models/query/permissions.clj b/src/metabase/models/query/permissions.clj
index 46398de6a7c..e88be2deaaf 100644
--- a/src/metabase/models/query/permissions.clj
+++ b/src/metabase/models/query/permissions.clj
@@ -103,7 +103,7 @@
   ;; preprocessing to fail because current user doesn't have permissions to run it when we're not trying to run it at
   ;; all
   (binding [api/*current-user-id* nil]
-    ((resolve 'metabase.query-processor/query->preprocessed) query)))
+    ((resolve 'metabase.query-processor/preprocess) query)))
 
 (s/defn ^:private mbql-permissions-path-set :- #{perms/Path}
   "Return the set of required permissions needed to run an adhoc `query`.
diff --git a/src/metabase/query_processor.clj b/src/metabase/query_processor.clj
index b9ab6cb97f3..8b32b63e2d5 100644
--- a/src/metabase/query_processor.clj
+++ b/src/metabase/query_processor.clj
@@ -250,11 +250,6 @@
               (preprocess* query)))]
     (qp query nil nil)))
 
-(defn ^:deprecated query->preprocessed
-  "DEPRECATED: Use [[preprocess]] instead."
-  [query]
-  (preprocess query))
-
 (defn query->expected-cols
   "Return the `:cols` you would normally see in MBQL query results by preprocessing the query and calling `annotate` on
   it. This only works for pure MBQL queries, since it does not actually run the queries. Native queries or MBQL
diff --git a/src/metabase/query_processor/util/nest_query.clj b/src/metabase/query_processor/util/nest_query.clj
index d1e058eec98..3160b7b1481 100644
--- a/src/metabase/query_processor/util/nest_query.clj
+++ b/src/metabase/query_processor/util/nest_query.clj
@@ -33,9 +33,9 @@
                  ;; here in the first place we already had to do perms checks to make sure the query we're transforming
                  ;; is itself ok, so we don't need to run another check
                  (binding [api/*current-user-id* nil]
-                   ((resolve 'metabase.query-processor/query->preprocessed) {:database (u/the-id (qp.store/database))
-                                                                             :type     :query
-                                                                             :query    source}))
+                   ((resolve 'metabase.query-processor/preprocess) {:database (u/the-id (qp.store/database))
+                                                                    :type     :query
+                                                                    :query    source}))
                  (add/add-alias-info source)
                  (:query source)
                  (dissoc source :limit)
diff --git a/test/metabase/driver/sql/query_processor_test.clj b/test/metabase/driver/sql/query_processor_test.clj
index 3a1a3912ddd..3b35833b2e5 100644
--- a/test/metabase/driver/sql/query_processor_test.clj
+++ b/test/metabase/driver/sql/query_processor_test.clj
@@ -42,7 +42,7 @@
 (defn- mbql->native [query]
   (mt/with-everything-store
     (driver/with-driver :h2
-      (-> (sql.qp/mbql->native :h2 (qp/query->preprocessed query))
+      (-> (sql.qp/mbql->native :h2 (qp/preprocess query))
           :query
           sql.qp-test-util/pretty-sql))))
 
diff --git a/test/metabase/query_processor/middleware/annotate_test.clj b/test/metabase/query_processor/middleware/annotate_test.clj
index 68f1f24e86d..888a77cf72c 100644
--- a/test/metabase/query_processor/middleware/annotate_test.clj
+++ b/test/metabase/query_processor/middleware/annotate_test.clj
@@ -612,7 +612,7 @@
 
 (deftest mbql-cols-nested-queries-test
   (testing "Should be able to infer MBQL columns with nested queries"
-    (let [base-query (qp/query->preprocessed
+    (let [base-query (qp/preprocess
                       (mt/mbql-query venues
                         {:joins [{:fields       :all
                                   :source-table $$categories
@@ -644,7 +644,7 @@
                   (get result "EAN")
                   (select-keys result [:name :display_name :base_type :semantic_type :id :field_ref])))]
         (testing "Make sure metadata is correct for the 'EAN' column with"
-          (let [base-query (qp/query->preprocessed
+          (let [base-query (qp/preprocess
                             (mt/mbql-query orders
                               {:joins [{:fields       :all
                                         :source-table $$products
@@ -676,7 +676,7 @@
                       Card [{card-2-id :id} {:dataset_query (mt/mbql-query people)}]]
         (testing "when a nested query is from a saved question, there should be no `:join-alias` on the left side"
           (mt/$ids nil
-            (let [base-query (qp/query->preprocessed
+            (let [base-query (qp/preprocess
                               (mt/mbql-query nil
                                 {:source-table (str "card__" card-1-id)
                                  :joins        [{:fields       :all
diff --git a/test/metabase/query_processor/util/add_alias_info_test.clj b/test/metabase/query_processor/util/add_alias_info_test.clj
index f4cdb1318bd..f1ccc418786 100644
--- a/test/metabase/query_processor/util/add_alias_info_test.clj
+++ b/test/metabase/query_processor/util/add_alias_info_test.clj
@@ -35,7 +35,7 @@
 (defn- add-alias-info [query]
   (mt/with-everything-store
     (driver/with-driver (or driver/*driver* :h2)
-      (-> query qp/query->preprocessed add/add-alias-info remove-source-metadata (dissoc :middleware)))))
+      (-> query qp/preprocess add/add-alias-info remove-source-metadata (dissoc :middleware)))))
 
 (deftest join-in-source-query-test
   (is (query= (mt/mbql-query venues
diff --git a/test/metabase/query_processor/util/nest_query_test.clj b/test/metabase/query_processor/util/nest_query_test.clj
index 92abf605b1d..ca53a4f3557 100644
--- a/test/metabase/query_processor/util/nest_query_test.clj
+++ b/test/metabase/query_processor/util/nest_query_test.clj
@@ -21,7 +21,7 @@
   (mt/with-everything-store
     (driver/with-driver :h2
       (-> query
-          qp/query->preprocessed
+          qp/preprocess
           :query
           nest-query/nest-expressions
           remove-source-metadata))))
@@ -690,7 +690,7 @@
                              :aggregation [[:count]]
                              :order-by    [[:asc [:expression"CATEGORY"]]]
                              :limit       1})
-                          qp/query->preprocessed
+                          qp/preprocess
                           add/add-alias-info
                           :query
                           nest-query/nest-expressions)))))))
diff --git a/test/metabase/query_processor_test.clj b/test/metabase/query_processor_test.clj
index b25aec98cc2..d805648fca2 100644
--- a/test/metabase/query_processor_test.clj
+++ b/test/metabase/query_processor_test.clj
@@ -462,8 +462,8 @@
   [driver-or-drivers & body]
   `(do-with-bigquery-fks ~driver-or-drivers (fn [] ~@body)))
 
-(deftest query->preprocessed-caching-test
-  (testing "`query->preprocessed` should work the same even if query has cached results (#18579)"
+(deftest preprocess-caching-test
+  (testing "`preprocess` should work the same even if query has cached results (#18579)"
     ;; make a copy of the `test-data` DB so there will be no cache entries from previous test runs possibly affecting
     ;; this test.
     (data/with-temp-copy-of-db
@@ -475,8 +475,8 @@
                                  (let [results (qp/process-query query)]
                                    {:cached?  (boolean (:cached results))
                                     :num-rows (count (rows results))}))
-              expected-results (qp/query->preprocessed query)]
-          (testing "Check query->preprocessed before caching to make sure results make sense"
+              expected-results (qp/preprocess query)]
+          (testing "Check preprocess before caching to make sure results make sense"
             (is (schema= {:database (s/eq (data/id))
                           s/Keyword s/Any}
                          expected-results)))
@@ -492,6 +492,6 @@
               (is (= {:cached?  true
                       :num-rows 5}
                      (run-query))))
-            (testing "query->preprocessed should return same results even when query was cached."
+            (testing "preprocess should return same results even when query was cached."
               (is (= expected-results
-                     (qp/query->preprocessed query))))))))))
+                     (qp/preprocess query))))))))))
-- 
GitLab