Skip to content
Snippets Groups Projects
Commit e72be01a authored by Allen Gilliland's avatar Allen Gilliland
Browse files

Merge pull request #2584 from metabase/crate-fixes

Crate fixes
parents 6b220353 82bdf50a
Branches
Tags
No related merge requests found
......@@ -32,13 +32,12 @@ test:
override:
# 0) runs unit tests w/ H2 local DB. Runs against H2, Mongo, MySQL, BigQuery
# 1) runs unit tests w/ Postgres local DB. Runs against H2, SQL Server
# 2) runs unit tests w/ MySQL local DB. Runs against H2, Postgres, SQLite
# 2) runs unit tests w/ MySQL local DB. Runs against H2, Postgres, SQLite, Crate
# 3) runs unit tests w/ H2 local DB. Runs against H2, Redshift, Druid
# 4) runs Eastwood linter, Bikeshed linter, docstring-checker & ./bin/reflection-linter
# 5) runs JS linter + JS test
# 6) runs lein uberjar. (We don't run bin/build because we're not really concerned about `npm install` (etc) in this test, which runs elsewhere)
# 7) runs unit tests w/ H2 local DB. Runs agains H2, Crate
- case $CIRCLE_NODE_INDEX in 0) ENGINES=h2,mongo,mysql,bigquery lein test ;; 1) ENGINES=h2,sqlserver MB_DB_TYPE=postgres MB_DB_DBNAME=circle_test MB_DB_PORT=5432 MB_DB_USER=ubuntu MB_DB_HOST=localhost lein test ;; 2) ENGINES=h2,postgres,sqlite MB_DB_TYPE=mysql MB_DB_DBNAME=circle_test MB_DB_PORT=3306 MB_DB_USER=ubuntu MB_DB_HOST=localhost lein test ;; 3) ENGINES=h2,redshift,druid lein test ;; 4) lein eastwood && lein bikeshed && lein docstring-checker && ./bin/reflection-linter ;; 5) npm install && npm run lint && npm run build && npm run test ;; 6) lein uberjar ;; 7) ENGINES=h2,crate lein test ;; esac:
- case $CIRCLE_NODE_INDEX in 0) ENGINES=h2,mongo,mysql,bigquery lein test ;; 1) ENGINES=h2,sqlserver MB_DB_TYPE=postgres MB_DB_DBNAME=circle_test MB_DB_PORT=5432 MB_DB_USER=ubuntu MB_DB_HOST=localhost lein test ;; 2) ENGINES=h2,crate,postgres,sqlite MB_DB_TYPE=mysql MB_DB_DBNAME=circle_test MB_DB_PORT=3306 MB_DB_USER=ubuntu MB_DB_HOST=localhost lein test ;; 3) ENGINES=h2,redshift,druid lein test ;; 4) lein eastwood && lein bikeshed && lein docstring-checker && ./bin/reflection-linter ;; 5) npm install && npm run lint && npm run build && npm run test ;; 6) lein uberjar ;; esac:
parallel: true
deployment:
master:
......
(ns metabase.driver.crate.util
(:require [metabase.util.korma-extensions :as kx]
[korma.sql.utils :as kutils]
(:refer-clojure :exclude [second])
(:require [korma.sql.utils :as kutils]
[korma.core :as k]
[metabase.driver.generic-sql.query-processor :as qp]
[metabase.util :as u]
[metabase.driver.generic-sql.query-processor :as qp])
[metabase.util.korma-extensions :as kx])
(:import (java.sql Timestamp)))
(defn unix-timestamp->timestamp [_ expr seconds-or-milliseconds]
(defn unix-timestamp->timestamp
"Converts datetime string to a valid timestamp"
[_ expr seconds-or-milliseconds]
(case seconds-or-milliseconds
:seconds (recur nil (kx/* expr 1000) :milliseconds)
:milliseconds (kutils/func (str "TRY_CAST(%s as TIMESTAMP)") [expr])))
(defn- date-trunc [unit expr]
(defn- date-trunc
"date_trunc('interval', timezone, timestamp): truncates a timestamp to a given interval"
[unit expr]
(let [timezone (get-in qp/*query* [:settings :report-timezone])]
(if (= (nil? timezone) true)
(k/sqlfn :DATE_TRUNC (kx/literal unit) expr)
(k/sqlfn :DATE_TRUNC (kx/literal unit) timezone expr))))
(defn- date-format [format expr]
(defn- date-format
"date_format('format_string', timezone, timestamp): formats the timestamp as string"
[fmt expr]
(let [timezone (get-in qp/*query* [:settings :report-timezone])]
(if (nil? timezone)
(k/sqlfn :DATE_FORMAT format expr)
(k/sqlfn :DATE_FORMAT format timezone expr))))
(k/sqlfn :DATE_FORMAT fmt expr)
(k/sqlfn :DATE_FORMAT fmt timezone expr))))
(defn- extract [unit expr]
(defn- extract
"extract(field from expr): extracts subfields of a timestamp"
[unit expr]
(case unit
;; Crate DOW starts with Monday (1) to Sunday (7)
:day_of_week (kx/+ (kx/mod (kutils/func (format "EXTRACT(%s FROM %%s)" (name unit)) [expr]) 7) 1)
......@@ -44,7 +49,9 @@
(def ^:private ^:const year (* 365 day))
(def ^:private ^:const month (Math/round (float (/ year 12))))
(defn date [_ unit expr]
(defn date
"ISQLDriver `date` implementation"
[_ unit expr]
(let [v (if (instance? Timestamp expr)
(kx/literal (u/date->iso-8601 expr))
expr)]
......@@ -71,8 +78,9 @@
(defn- sql-interval [unit amount]
(format "CURRENT_TIMESTAMP + %d" (* unit amount)))
(defn date-interval [_ unit amount]
(defn date-interval
"defines the sql command required for date-interval calculation"
[_ unit amount]
(case unit
:quarter (recur nil :month (kx/* amount 3))
:year (k/raw (sql-interval year amount))
......
......@@ -167,7 +167,10 @@
:= ['= (formatted value)]
:!= ['not= (formatted value)])}))
(defn filter-clause->predicate [{:keys [compound-type subclause subclauses], :as clause}]
(defn filter-clause->predicate
"Given a filter CLAUSE, return a Korma filter predicate form for use in korma `where`. If this is a compound
clause then we call `filter-subclause->predicate` on all of the subclauses."
[{:keys [compound-type subclause subclauses], :as clause}]
(case compound-type
:and (apply kfns/pred-and (map filter-clause->predicate subclauses))
:or (apply kfns/pred-or (map filter-clause->predicate subclauses))
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment