Skip to content
Snippets Groups Projects
Commit 3d7f94ff authored by Cam Saül's avatar Cam Saül
Browse files

Remove core.logic

parent 61badd34
No related branches found
No related tags found
No related merge requests found
...@@ -9,7 +9,6 @@ ...@@ -9,7 +9,6 @@
"generate-sample-dataset" ["with-profile" "+generate-sample-dataset" "run"]} "generate-sample-dataset" ["with-profile" "+generate-sample-dataset" "run"]}
:dependencies [[org.clojure/clojure "1.7.0"] :dependencies [[org.clojure/clojure "1.7.0"]
[org.clojure/core.async "0.1.346.0-17112a-alpha"] [org.clojure/core.async "0.1.346.0-17112a-alpha"]
[org.clojure/core.logic "0.8.10"]
[org.clojure/core.match "0.3.0-alpha4"] ; optimized pattern matching library for Clojure [org.clojure/core.match "0.3.0-alpha4"] ; optimized pattern matching library for Clojure
[org.clojure/core.memoize "0.5.7"] ; needed by core.match; has useful FIFO, LRU, etc. caching mechanisms [org.clojure/core.memoize "0.5.7"] ; needed by core.match; has useful FIFO, LRU, etc. caching mechanisms
[org.clojure/data.csv "0.1.3"] ; CSV parsing / generation [org.clojure/data.csv "0.1.3"] ; CSV parsing / generation
...@@ -17,7 +16,6 @@ ...@@ -17,7 +16,6 @@
[org.clojure/java.jdbc "0.4.2"] ; basic jdbc access from clojure [org.clojure/java.jdbc "0.4.2"] ; basic jdbc access from clojure
[org.clojure/math.numeric-tower "0.0.4"] ; math functions like `ceil` [org.clojure/math.numeric-tower "0.0.4"] ; math functions like `ceil`
[org.clojure/tools.logging "0.3.1"] ; logging framework [org.clojure/tools.logging "0.3.1"] ; logging framework
[org.clojure/tools.macro "0.1.5"] ; tools for writing macros
[org.clojure/tools.namespace "0.2.10"] [org.clojure/tools.namespace "0.2.10"]
[amalloy/ring-gzip-middleware "0.1.3"] ; Ring middleware to GZIP responses if client can handle it [amalloy/ring-gzip-middleware "0.1.3"] ; Ring middleware to GZIP responses if client can handle it
[cheshire "5.5.0"] ; fast JSON encoding (used by Ring JSON middleware) [cheshire "5.5.0"] ; fast JSON encoding (used by Ring JSON middleware)
......
This diff is collapsed.
...@@ -270,23 +270,28 @@ ...@@ -270,23 +270,28 @@
[^Throwable e] [^Throwable e]
(when e (when e
(when-let [stacktrace (.getStackTrace e)] (when-let [stacktrace (.getStackTrace e)]
(->> (map str (.getStackTrace e)) (filterv (partial re-find #"metabase")
(filterv (partial re-find #"metabase")))))) (map str (.getStackTrace e))))))
(defn wrap-try-catch (defn wrap-try-catch
"Returns a new function that wraps F in a `try-catch`. When an exception is caught, it is logged "Returns a new function that wraps F in a `try-catch`. When an exception is caught, it is logged
with `log/error` and returns `nil`." with `log/error` and returns `nil`."
[f] ([f]
(fn [& args] (wrap-try-catch f nil))
(try ([f f-name]
(apply f args) (let [exception-message (if f-name
(catch java.sql.SQLException e (format "Caught exception in %s: " f-name)
(log/error (color/red "Caught exception:\n" "Caught exception: ")]
(with-out-str (jdbc/print-sql-exception-chain e)) "\n" (fn [& args]
(pprint-to-str (filtered-stacktrace e))))) (try
(catch Throwable e (apply f args)
(log/error (color/red "Caught exception: " (or (.getMessage e) e) "\n" (catch java.sql.SQLException e
(pprint-to-str (filtered-stacktrace e)))))))) (log/error (color/red exception-message "\n"
(with-out-str (jdbc/print-sql-exception-chain e)) "\n"
(pprint-to-str (filtered-stacktrace e)))))
(catch Throwable e
(log/error (color/red exception-message (or (.getMessage e) e) "\n"
(pprint-to-str (filtered-stacktrace e))))))))))
(defn try-apply (defn try-apply
"Like `apply`, but wraps F inside a `try-catch` block and logs exceptions caught." "Like `apply`, but wraps F inside a `try-catch` block and logs exceptions caught."
...@@ -307,7 +312,7 @@ ...@@ -307,7 +312,7 @@
(let [varr (resolve fn-symb) (let [varr (resolve fn-symb)
{nmspc :ns, symb :name} (meta varr)] {nmspc :ns, symb :name} (meta varr)]
(println (format "wrap-try-catch! %s/%s" nmspc symb)) (println (format "wrap-try-catch! %s/%s" nmspc symb))
(intern nmspc symb (wrap-try-catch @varr)))) (intern nmspc symb (wrap-try-catch @varr fn-symb))))
(defn ns-wrap-try-catch! (defn ns-wrap-try-catch!
"Re-intern all functions in NAMESPACE as ones that wrap the originals with a `try-catch`. "Re-intern all functions in NAMESPACE as ones that wrap the originals with a `try-catch`.
......
(ns metabase.util.logic
"Useful relations for `core.logic`."
(:refer-clojure :exclude [==])
(:require [clojure.core.logic :refer :all]))
(defna butlast°
"A relation such that BUSTLASTV is all items but the last item LASTV of list L."
[butlastv lastv l]
([[] ?x [?x]])
([_ _ [?x . ?more]] (fresh [more-butlast]
(butlast° more-butlast lastv ?more)
(conso ?x more-butlast butlastv))))
(defna split°
"A relation such that HALF1 and HALF2 are even divisions of list L.
If L has an odd number of items, HALF1 will have one more item than HALF2."
[half1 half2 l]
([[] [] []])
([[?x] [] [?x]])
([[?x] [?y] [?x ?y]])
([[?x ?y . ?more-half1-butlast] [?more-half1-last . ?more-half2] [?x ?y . ?more]]
(fresh [more-half1]
(split° more-half1 ?more-half2 ?more)
(butlast° ?more-half1-butlast ?more-half1-last more-half1))))
(defn sorted-into°
"A relation such that OUT is the list L with V sorted into it doing comparisons with PRED-F."
[pred-f l v out]
(matche [l]
([[]] (== out [v]))
([[?x . ?more]] (conda
((pred-f v ?x) (conso v (lcons ?x ?more) out))
(s# (fresh [more]
(sorted-into° pred-f ?more v more)
(conso ?x more out)))))))
(defna sorted-permutation°
"A relation such that OUT is a permutation of L where all items are sorted by PRED-F."
[pred-f l out]
([_ [] []])
([_ [?x . ?more] _] (fresh [more]
(sorted-permutation° pred-f ?more more)
(sorted-into° pred-f more ?x out))))
(defn matches-seq-order°
"A relation such that V1 is present and comes before V2 in list L."
[v1 v2 l]
(conda
;; This is just an optimization for cases where L isn't a logic var; it's much faster <3
((nonlvaro l) ((fn -ordered° [[item & more]]
(conda
((== v1 item) s#)
((== v2 item) fail)
((when (seq more) s#) (-ordered° more))))
l))
(s# (conda
((firsto l v1))
((firsto l v2) fail)
((fresh [more]
(resto l more)
(matches-seq-order° v1 v2 more)))))))
...@@ -1316,8 +1316,8 @@ ...@@ -1316,8 +1316,8 @@
:type :query :type :query
:query {:source_table (id :checkins) :query {:source_table (id :checkins)
:aggregation ["count"] :aggregation ["count"]
:filter ["TIME_INTERVAL" (id :checkins :timestamp) "current" filter-by] :breakout [["datetime_field" (id :checkins :timestamp) "as" breakout-by]]
:breakout [["datetime_field" (id :checkins :timestamp) "as" breakout-by]]}})] :filter ["TIME_INTERVAL" (id :checkins :timestamp) "current" filter-by]}})]
{:rows (-> results :row_count) {:rows (-> results :row_count)
:unit (-> results :data :cols first :unit)}))) :unit (-> results :data :cols first :unit)})))
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment