From 8c16a56ef41f19beafba650a14cc6ea6eb2f8b2b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Markenson=20Paulo=20Fran=C3=A7a?= Date: Mon, 6 Apr 2020 16:40:52 -0300 Subject: [PATCH] Incluing date and time funcions --- csv/src/metabase/driver/csv.clj | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/csv/src/metabase/driver/csv.clj b/csv/src/metabase/driver/csv.clj index ae99f90..5de472d 100644 --- a/csv/src/metabase/driver/csv.clj +++ b/csv/src/metabase/driver/csv.clj @@ -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))