Skip to content

Commit

Permalink
Incluing date and time funcions
Browse files Browse the repository at this point in the history
  • Loading branch information
Markenson committed Apr 6, 2020
1 parent fdde5dd commit 8c16a56
Showing 1 changed file with 17 additions and 2 deletions.
19 changes: 17 additions & 2 deletions csv/src/metabase/driver/csv.clj
Original file line number Diff line number Diff line change
Expand Up @@ -18,19 +18,34 @@
[sync :as sql-jdbc.sync]]
[metabase.driver.sql.query-processor :as sql.qp]
[metabase.util
[date-2 :as du]
[honeysql-extensions :as hx]]
[schema.core :as s])
(:import [java.sql Time Timestamp]))
(:import [java.sql Time Timestamp]
[java.util Calendar]))

(driver/register! :csv, :parent :sql-jdbc)


(def ^:private database-type->base-type
(sql-jdbc.sync/pattern-based-database-type->base-type
[
[#"String" :type/Text]
]))

(defn week-of-year
[date]
(let [cal (Calendar/getInstance)]
(.setTime cal (.toDate date))
(.get cal Calendar/WEEK_OF_YEAR)))

(defmethod sql.qp/date [:csv :day] [_ _ expr] (hsql/call :substring expr 1 10))
(defmethod sql.qp/date [:csv :month] [_ _ expr] (hsql/call :substring expr 1 7))
(defmethod sql.qp/date [:csv :year] [_ _ expr] (hsql/call :year expr))
(defmethod sql.qp/date [:csv :second] [_ _ expr] (hsql/call :substring expr 1 10))
(defmethod sql.qp/date [:csv :minute] [_ _ expr] (hsql/call :substring expr 1 16))
(defmethod sql.qp/date [:csv :hour] [_ _ expr] (hsql/call :substring expr 1 13))
(defmethod sql.qp/date [:csv :hour-of-day] [_ _ expr] (hsql/call :substring expr 1 13))
(defmethod sql.qp/date [:csv :week] [_ _ expr] (:week-of-year expr))

(defmethod sql-jdbc.sync/database-type->base-type :csv [_ database-type]
(database-type->base-type database-type))
Expand Down

0 comments on commit 8c16a56

Please sign in to comment.