Skip to content
Snippets Groups Projects
Unverified Commit dc4d4de2 authored by dpsutton's avatar dpsutton Committed by GitHub
Browse files

Add `updated` special type for timestamps (#13818)

keyed off of column names that include "update" which are date, time,
or datetime columns.
parent 7ede73f8
No related branches found
No related tags found
No related merge requests found
......@@ -208,6 +208,21 @@ export const field_special_types = [
name: t`Deletion timestamp`,
section: t`Date and Time`,
},
{
id: TYPE.UpdatedDate,
name: t`Updated date`,
section: t`Date and Time`,
},
{
id: TYPE.UpdatedTime,
name: t`Updated time`,
section: t`Date and Time`,
},
{
id: TYPE.UpdatedTimestamp,
name: t`Updated timestamp`,
section: t`Date and Time`,
},
{
id: TYPE.JoinDate,
name: t`Join date`,
......
......@@ -47,6 +47,9 @@ window.MetabaseBootstrap = {
"type/State": ["type/Category", "type/Address", "type/Text"],
"type/CancelationDate": ["type/Date", "type/CancelationTimestamp"],
"type/CancelationTime": ["type/Date", "type/CancelationTimestamp"],
"type/UpdatedDate": ["type/Date", "type/UpdatedTimestamp"],
"type/UpdatedTime": ["type/Date", "type/UpdatedTimestamp"],
"type/UpdatedTimestamp": ["type/DateTime"],
"type/DeletionDate": ["type/Date", "type/DeletionTimestamp"],
"type/DateTimeWithZoneID": ["type/DateTimeWithTZ"],
"type/Address": ["type/*"],
......
......@@ -83,6 +83,9 @@
[#"delet(?:e|i)" date-type :type/DeletionDate]
[#"delet(?:e|i)" time-type :type/DeletionTime]
[#"delet(?:e|i)" timestamp-type :type/DeletionTimestamp]
[#"update" date-type :type/UpdatedDate]
[#"update" time-type :type/UpdatedTime]
[#"update" timestamp-type :type/UpdatedTimestamp]
[#"source" int-or-text-type :type/Source]
[#"channel" int-or-text-type :type/Source]
[#"share" float-type :type/Share]
......
......@@ -134,6 +134,12 @@
(derive :type/DeletionDate :type/Date)
(derive :type/DeletionDate :type/DeletionTimestamp)
(derive :type/UpdatedTimestamp :type/DateTime)
(derive :type/UpdatedTime :type/Date)
(derive :type/UpdatedTime :type/UpdatedTimestamp)
(derive :type/UpdatedDate :type/Date)
(derive :type/UpdatedDate :type/UpdatedTimestamp)
(derive :type/Birthdate :type/Date)
......
......@@ -46,6 +46,16 @@
:type/Name ["first_name"]
:type/Name ["name"]
:type/Quantity ["quantity" :type/Integer]))
(testing "name and type matches"
(testing "matches \"updated at\" style columns"
(let [classify (fn [table-name table-type] (-> {:name table-name :base_type table-type}
table/map->TableInstance
classify.names/infer-special-type))]
(doseq [[col-type expected] [[:type/Date :type/UpdatedDate]
[:type/DateTime :type/UpdatedTimestamp]
[:type/Time :type/UpdatedTime]]]
(doseq [column-name ["updated_at" "updated" "updated-at"]]
(is (= expected (classify column-name col-type))))))))
(testing "Doesn't mark state columns (#2735)"
(doseq [column-name ["state" "order_state" "state_of_order"]]
(is (not= :type/State (infer column-name)))))))
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment