From 696620dc0027f8488bb79e550b99bf54a18a8d62 Mon Sep 17 00:00:00 2001 From: github-actions Date: Thu, 15 Feb 2024 17:24:07 +0000 Subject: [PATCH] Update backend docs on Thu Feb 15 17:24:07 UTC 2024 --- index.html | 40 +++++++++++++++++++++++++++------------- 1 file changed, 27 insertions(+), 13 deletions(-) diff --git a/index.html b/index.html index 13b4b09..f420a0f 100644 --- a/index.html +++ b/index.html @@ -30006,7 +30006,10 @@

How to use and extend this method?

[metabase.util.malli.schema :as ms]) (:import (java.time.temporal Temporal))) -
(set! *warn-on-reflection* true)

Is param type :date or some subtype like :date/month-year?

+
(set! *warn-on-reflection* true)
+
(def ^:private temporal-units-regex #"(millisecond|second|minute|hour|day|week|month|quarter|year)")

Regex to match date exclusion values, e.g. exclude-days-Mon, exclude-months-Jan, etc.

+
(def date-exclude-regex
+  (re-pattern (str "exclude-" temporal-units-regex #"s-([-\p{Alnum}]+)")))

Is param type :date or some subtype like :date/month-year?

(mu/defn date-type?
   [param-type :- :keyword]
   (= (get-in mbql.s/parameter-types [param-type :type]) :date))

Does date param-type represent a range of dates, rather than a single absolute date? (The value may be relative, @@ -30014,7 +30017,14 @@

How to use and extend this method?

(defn not-single-date-type?
   [param-type]
   (and (date-type? param-type)
-       (not (#{:date/single :date} param-type))))

Both in MBQL and SQL parameter substitution a field value is compared to a date range, either relative or absolute. + (not (#{:date/single :date} param-type))))

When date param-type represent an exclusion of dates returns the temporal unit that's excluded.

+
(defn exclusion-date-type
+  [param-type value]
+  (when (and (date-type? param-type)
+             (string? value))
+    (some->> (re-matches date-exclude-regex value)
+             second
+             keyword)))

Both in MBQL and SQL parameter substitution a field value is compared to a date range, either relative or absolute. Currently the field value is casted to a day (ignoring the time of day), so the ranges should have the same granularity level.

@@ -30112,8 +30122,7 @@

How to use and extend this method?

2) Range decoder which takes the parser output and produces a date range relative to the given datetime 3) Filter decoder which takes the parser output and produces a mbql clause for a given mbql field reference

-
(def ^:private temporal-units-regex #"(millisecond|second|minute|hour|day|week|month|quarter|year)")
-(def ^:private relative-suffix-regex (re-pattern (format "(|~|-from-([0-9]+)%ss)" temporal-units-regex)))

Adding a tilde (~) at the end of a pasts filter means we should include the current time-unit (e.g. year, day, +

(def ^:private relative-suffix-regex (re-pattern (format "(|~|-from-([0-9]+)%ss)" temporal-units-regex)))

Adding a tilde (~) at the end of a pasts filter means we should include the current time-unit (e.g. year, day, week, or month).

(defn- include-current?
   [relative-suffix]
@@ -30231,9 +30240,7 @@ 

How to use and extend this method?

{:hour :hour-of-day :day :day-of-week :month :month-of-year - :quarter :quarter-of-year})

Regex to match date exclusion values, e.g. exclude-days-Mon, exclude-months-Jan, etc.

-
(def date-exclude-regex
-  (re-pattern (str "exclude-" temporal-units-regex #"s-([-\p{Alnum}]+)")))
+ :quarter :quarter-of-year})
(defn- absolute-date->unit
   [date-string]
   (if (str/includes? date-string "T")
@@ -36820,6 +36827,7 @@ 
`:abstract?` (default = false)
:as qp.wrap-value-literals] [metabase.query-processor.timezone :as qp.timezone] [metabase.query-processor.util.add-alias-info :as add] + [metabase.shared.util.time :as shared.ut] [metabase.util :as u] [metabase.util.date-2 :as u.date] [metabase.util.i18n :refer [tru]] @@ -36891,9 +36899,17 @@
`:abstract?` (default = false)
(when (params.dates/date-type? param-type) :day))
(defmethod align-temporal-unit-with-param-type-and-value :default
-  [driver field param-type _value]
-  #_{:clj-kondo/ignore [:deprecated-var]}
-  (align-temporal-unit-with-param-type driver field param-type))

------------------------------------------- ->replacement-snippet-info -------------------------------------------

+ [_driver _field param-type value] + (when (params.dates/date-type? param-type) + (if-let [exclusion-type (params.dates/exclusion-date-type param-type value)] + exclusion-type + (let [value* (if (params.dates/not-single-date-type? param-type) + (let [param-range (params.dates/date-string->range value)] + (or (:start param-range) (:end param-range))) ;; Before or after filters only have one of these + value)] + (if (re-matches shared.ut/local-date-regex value*) + :day + :minute)))))

------------------------------------------- ->replacement-snippet-info -------------------------------------------

(def ^:private ParamSnippetInfo
   [:map
@@ -37039,9 +37055,7 @@ 
`:abstract?` (default = false)
qp.wrap-value-literals/wrap-value-literals-in-mbql ->honeysql (honeysql->replacement-snippet-info driver)) - (and (params.dates/date-type? param-type) - (string? value) - (re-matches params.dates/date-exclude-regex value)) + (params.dates/exclusion-date-type param-type value) (let [field-clause (field->clause driver field param-type value)] (->> (params.dates/date-string->filter value field-clause) mbql.u/desugar-filter-clause