Skip to content
Snippets Groups Projects
Commit b008dd10 authored by Simon Belak's avatar Simon Belak
Browse files

Refactor, docsstrings, conform to code style

parent 958c7b68
Branches
Tags
No related merge requests found
......@@ -26,6 +26,8 @@
org.clojure/clojurescript]] ; fixed length queue implementation, used in log buffering
[amalloy/ring-gzip-middleware "0.1.3"] ; Ring middleware to GZIP responses if client can handle it
[aleph "0.4.3"] ; Async HTTP library; WebSockets
[bigml/histogram "4.1.3"] ; Streaming one-pass Histogram data structure
[bigml/sketchy "0.3.1"] ; Various sketching algorithms
[buddy/buddy-core "1.2.0"] ; various cryptograhpic functions
[buddy/buddy-sign "1.5.0"] ; JSON Web Tokens; High-Level message signing library
[cheshire "5.7.0"] ; fast JSON encoding (used by Ring JSON middleware)
......@@ -58,6 +60,7 @@
[environ "1.1.0"] ; easy environment management
[hiccup "1.0.5"] ; HTML templating
[honeysql "0.8.2"] ; Transform Clojure data structures to SQL
[kixi/stats "0.3.8"] ; Various statistic measures implemented as transducers
[log4j/log4j "1.2.17" ; logging framework
:exclusions [javax.mail/mail
javax.jms/jms
......@@ -76,21 +79,16 @@
[postgresql "9.3-1102.jdbc41"] ; Postgres driver
[io.crate/crate-jdbc "2.1.6"] ; Crate JDBC driver
[prismatic/schema "1.1.5"] ; Data schema declaration and validation library
[redux "0.1.4"] ; Utility functions for building and composing transducers
[ring/ring-core "1.6.0"]
[ring/ring-jetty-adapter "1.6.0"] ; Ring adapter using Jetty webserver (used to run a Ring server for unit tests)
[ring/ring-json "0.4.0"] ; Ring middleware for reading/writing JSON automatically
[stencil "0.5.0"] ; Mustache templates for Clojure
[tide "0.1.0-SNAPSHOT"] ; Various algorithms for working with timeseries
[toucan "1.0.3" ; Model layer, hydration, and DB utilities
:exclusions [honeysql]]
; Proposed additions for fingerprinting
[bigml/histogram "4.1.3"]
[bigml/sketchy "0.4.0"]
[kixi/stats "0.3.8"]
[tide "0.1.0-SNAPSHOT"]
[redux "0.1.4"]]
:exclusions [honeysql]]]
:repositories [["bintray" "https://dl.bintray.com/crate/crate"]] ; Repo for Crate JDBC driver
:plugins [[lein-environ "1.1.0"] ; easy access to environment variables
:plugins [[lein-environ "1.1.0"] ; easy access to environment variables
[lein-ring "0.11.0" ; start the HTTP server with 'lein ring server'
:exclusions [org.clojure/clojure]]] ; TODO - should this be a dev dependency ?
:main ^:skip-aot metabase.core
......
......@@ -5,13 +5,19 @@
(metabase.models [field :refer [Field]]
[table :refer [Table]]
[segment :refer [Segment]]
[card :refer [Card]])
[schema.core :as s]
[metabase.util.schema :as su]))
[card :refer [Card]])
[schema.core :as s]))
(def MaxQueryCost (s/maybe (s/enum "sample" "full-scan" "joins")))
(def MaxComputationCost (s/maybe (s/enum "linear" "unbounded" "yolo")))
(def Resolution (s/maybe (s/enum "month" "day")))
(def ^:private ^:const MaxQueryCost (s/maybe (s/enum "dont-touch"
"sample"
"full-scan"
"joins")))
(def ^:private ^:const MaxComputationCost (s/maybe (s/enum "linear"
"unbounded"
"yolo")))
(def ^:private ^:const Resolution (s/maybe (s/enum "month"
"day"
"raw")))
(defn- max-cost
[query computation]
......@@ -25,8 +31,8 @@
max_computation_cost MaxComputationCost}
(->> id
(api/read-check Field)
(fingerprinting/fingerprint
{:max-cost (max-cost max_query_cost max_computation_cost)})))
(fingerprinting/fingerprint {:max-cost (max-cost max_query_cost
max_computation_cost)})))
(api/defendpoint GET "/table/:id"
"Get fingerprint for a `Tield` with ID."
......@@ -35,8 +41,8 @@
max_computation_cost MaxComputationCost}
(->> id
(api/read-check Table)
(fingerprinting/fingerprint
{:max-cost (max-cost max_query_cost max_computation_cost)})))
(fingerprinting/fingerprint {:max-cost (max-cost max_query_cost
max_computation_cost)})))
(api/defendpoint GET "/segment/:id"
"Get fingerprint for a `Segment` with ID."
......@@ -45,8 +51,8 @@
max_computation_cost MaxComputationCost}
(->> id
(api/read-check Segment)
(fingerprinting/fingerprint
{:max-cost (max-cost max_query_cost max_computation_cost)})))
(fingerprinting/fingerprint {:max-cost (max-cost max_query_cost
max_computation_cost)})))
(api/defendpoint GET "/card/:id"
"Get fingerprint for a `Card` with ID."
......@@ -55,8 +61,8 @@
max_computation_cost MaxComputationCost}
(->> id
(api/read-check Card)
(fingerprinting/fingerprint
{:max-cost (max-cost max_query_cost max_computation_cost)})))
(fingerprinting/fingerprint {:max-cost (max-cost max_query_cost
max_computation_cost)})))
(api/defendpoint GET "/fields/:id1/:id2"
"Get a multi-field fingerprint for `Field`s with ID1 and ID2."
......@@ -67,8 +73,7 @@
(->> [id1 id2]
(map (partial api/read-check Field))
(apply fingerprinting/multifield-fingerprint
{:max-cost {:query (keyword max_query_cost)
:computation (keyword max_computation_cost)}
{:max-cost (max-cost max_query_cost max_computation_cost)
:resolution (keyword resolution)})))
(api/defendpoint GET "/compare/fields/:id1/:id2"
......@@ -79,8 +84,7 @@
(->> [id2 id2]
(map (partial api/read-check Field))
(apply fingerprinting/compare-fingerprints
{:max-cost {:query (keyword max_query_cost)
:computation (keyword max_computation_cost)}})))
{:max-cost (max-cost max_query_cost max_computation_cost)})))
(api/defendpoint GET "/compare/tables/:id1/:id2"
"Get comparison fingerprints for `Table`s with ID1 and ID2."
......@@ -90,8 +94,7 @@
(->> [id2 id2]
(map (partial api/read-check Table))
(apply fingerprinting/compare-fingerprints
{:max-cost {:query (keyword max_query_cost)
:computation (keyword max_computation_cost)}})))
{:max-cost (max-cost max_query_cost max_computation_cost)})))
(api/defendpoint GET "/compare/cards/:id1/:id2"
"Get comparison fingerprints for `Card`s with ID1 and ID2."
......@@ -101,8 +104,7 @@
(->> [id2 id2]
(map (partial api/read-check Card))
(apply fingerprinting/compare-fingerprints
{:max-cost {:query (keyword max_query_cost)
:computation (keyword max_computation_cost)}})))
{:max-cost (max-cost max_query_cost max_computation_cost)})))
(api/defendpoint GET "/compare/segments/:id1/:id2"
"Get comparison fingerprints for `Segment`s with ID1 and ID2."
......@@ -112,7 +114,6 @@
(->> [id2 id2]
(map (partial api/read-check Segment))
(apply fingerprinting/compare-fingerprints
{:max-cost {:query (keyword max_query_cost)
:computation (keyword max_computation_cost)}})))
{:max-cost (max-cost max_query_cost max_computation_cost)})))
(api/define-routes)
......@@ -54,24 +54,29 @@
(-> (field-query field (ql/aggregation {} (ql/count (ql/field-id field-id))))
first first int))
(defn db-id
"Fetch the database ID of a given entity."
[x]
(db/select-one-field :db_id 'Table :id (:table_id x)))
(defn field-values
"Return all the values of FIELD."
"Return all the values of FIELD for QUERY."
[field query]
(->> (qp/process-query
{:type :query
:database (db/select-one-field :db_id Table, :id (:table_id field))
:query (merge {:fields [[:field-id (:id field)]]
:source-table (:table_id field)}
query)})
{:type :query
:database (db-id field)
:query (merge {:fields [[:field-id (:id field)]]
:source-table (:table_id field)}
query)})
:data
:rows
(map first)))
(defn query-values
"Return all values for query"
"Return all values for QUERY."
[db-id query]
(-> (qp/process-query
{:type :query
{:type :query
:database db-id
:query query})
:query query})
:data))
This diff is collapsed.
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment