-
Notifications
You must be signed in to change notification settings - Fork 4.9k
/
types.clj
169 lines (119 loc) · 5.01 KB
/
types.clj
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
(ns metabase.types
"The Metabase Hierarchical Type System (MHTS). This is a hierarchy where types derive from one or more parent types,
which in turn derive from their own parents. This makes it possible to add new types without needing to add
corresponding mappings in the frontend or other places. For example, a Database may want a type called something
like `:type/CaseInsensitiveText`; we can add this type as a derivative of `:type/Text` and everywhere else can
continue to treat it as such until further notice.")
;; NOTE: be sure to update frontend/test/metabase-bootstrap.js when updating this
(derive :type/Collection :type/*)
(derive :type/Dictionary :type/Collection)
(derive :type/Array :type/Collection)
;;; Table (entity) Types
(derive :entity/GenericTable :entity/*)
(derive :entity/UserTable :entity/GenericTable)
(derive :entity/CompanyTable :entity/GenericTable)
(derive :entity/TransactionTable :entity/GenericTable)
(derive :entity/ProductTable :entity/GenericTable)
(derive :entity/SubscriptionTable :entity/GenericTable)
(derive :entity/EventTable :entity/GenericTable)
(derive :entity/GoogleAnalyticsTable :entity/GenericTable)
;;; Numeric Types
(derive :type/Number :type/*)
(derive :type/Integer :type/Number)
(derive :type/BigInteger :type/Integer)
(derive :type/Quantity :type/Integer)
(derive :type/Float :type/Number)
(derive :type/Decimal :type/Float)
(derive :type/Share :type/Float)
(derive :type/Currency :type/Float)
(derive :type/Income :type/Currency)
(derive :type/Discount :type/Currency)
(derive :type/Price :type/Currency)
(derive :type/GrossMargin :type/Currency)
(derive :type/Cost :type/Currency)
(derive :type/Coordinate :type/Float)
(derive :type/Latitude :type/Coordinate)
(derive :type/Longitude :type/Coordinate)
(derive :type/Score :type/Number)
(derive :type/Duration :type/Number)
;;; Text Types
(derive :type/Text :type/*)
(derive :type/UUID :type/Text)
(derive :type/URL :type/Text)
(derive :type/ImageURL :type/URL)
(derive :type/AvatarURL :type/ImageURL)
(derive :type/Email :type/Text)
(derive :type/City :type/Text)
(derive :type/State :type/Text)
(derive :type/Country :type/Text)
(derive :type/ZipCode :type/Text)
(derive :type/Name :type/Text)
(derive :type/Title :type/Text)
(derive :type/Description :type/Text)
(derive :type/Comment :type/Text)
(derive :type/SerializedJSON :type/Text)
(derive :type/SerializedJSON :type/Collection)
(derive :type/PostgresEnum :type/Text)
;;; DateTime Types
(derive :type/DateTime :type/*)
(derive :type/Time :type/DateTime)
(derive :type/Date :type/DateTime)
(derive :type/DateTimeWithTZ :type/DateTime)
(derive :type/UNIXTimestamp :type/DateTime)
(derive :type/UNIXTimestamp :type/Integer)
(derive :type/UNIXTimestampSeconds :type/UNIXTimestamp)
(derive :type/UNIXTimestampMilliseconds :type/UNIXTimestamp)
(derive :type/CreationTimestamp :type/DateTime)
(derive :type/CreationTime :type/Time)
(derive :type/CreationTime :type/CreationTimestamp)
(derive :type/CreationDate :type/Date)
(derive :type/CreationDate :type/CreationTimestamp)
(derive :type/JoinTimestamp :type/DateTime)
(derive :type/JoinTime :type/Date)
(derive :type/JoinTime :type/CreationTimestamp)
(derive :type/JoinDate :type/Date)
(derive :type/JoinDate :type/CreationTimestamp)
(derive :type/Birthdate :type/Date)
;;; Other
(derive :type/Boolean :type/*)
(derive :type/Enum :type/*)
(derive :type/DruidHyperUnique :type/*)
;;; Text-Like Types: Things that should be displayed as text for most purposes but that *shouldn't* support advanced
;;; filter options like starts with / contains
(derive :type/TextLike :type/*)
(derive :type/IPAddress :type/TextLike)
(derive :type/MongoBSONID :type/TextLike)
;;; "Virtual" Types
(derive :type/Address :type/*)
(derive :type/City :type/Address)
(derive :type/State :type/Address)
(derive :type/Country :type/Address)
(derive :type/ZipCode :type/Address)
;;; Legacy Special Types. These will hopefully be going away in the future when we add columns like `:is_pk` and
;;; `:cardinality`
(derive :type/Special :type/*)
(derive :type/FK :type/Special)
(derive :type/PK :type/Special)
(derive :type/Category :type/Special)
(derive :type/Name :type/Category)
(derive :type/Title :type/Category)
(derive :type/City :type/Category)
(derive :type/State :type/Category)
(derive :type/Country :type/Category)
(derive :type/User :type/*)
(derive :type/Author :type/User)
(derive :type/Owner :type/User)
(derive :type/Product :type/Category)
(derive :type/Company :type/Category)
(derive :type/Subscription :type/Category)
(derive :type/Source :type/Category)
(derive :type/Boolean :type/Category)
(derive :type/Enum :type/Category)
;;; ---------------------------------------------------- Util Fns ----------------------------------------------------
(defn types->parents
"Return a map of various types to their parent types.
This is intended for export to the frontend as part of `MetabaseBootstrap` so it can build its own implementation of `isa?`."
([] (types->parents :type/*))
([root]
(into {} (for [t (descendants root)]
{t (parents t)}))))