Skip to content
Snippets Groups Projects
Unverified Commit 037c47fc authored by Cam Saül's avatar Cam Saül
Browse files

Support postgres 'inet' (IP Address) type :information_source:

parent db933a9e
No related branches found
No related tags found
No related merge requests found
......@@ -34,7 +34,7 @@
:float4 :type/Float
:float8 :type/Float
:geometry :type/*
:inet :type/Text
:inet :type/IPAddress
:int :type/Integer
:int2 :type/Integer
:int4 :type/Integer
......@@ -81,8 +81,10 @@
"Attempt to determine the special-type of a Field given its name and Postgres column type."
[column-name column-type]
;; this is really, really simple right now. if its postgres :json type then it's :type/SerializedJSON special-type
(when (= column-type :json)
:type/SerializedJSON))
(case column-type
:json :type/SerializedJSON
:inet :type/IPAddress
nil))
(def ^:const ssl-params
"Params to include in the JDBC connection spec for an SSL connection."
......@@ -168,10 +170,12 @@
message))
(defn- prepare-value [{value :value, {:keys [base-type]} :field}]
(if (and (isa? base-type :type/UUID)
value)
(UUID/fromString value)
value))
(if-not value
value
(cond
(isa? base-type :type/UUID) (UUID/fromString value)
(isa? base-type :type/IPAddress) (hx/cast :inet value)
:else value)))
(defn- materialized-views
......
......@@ -42,6 +42,8 @@
(derive :type/SerializedJSON :type/Text)
(derive :type/SerializedJSON :type/Collection)
(derive :type/IPAddress :type/Text)
;;; DateTime Types
(derive :type/DateTime :type/*)
......
......@@ -62,7 +62,7 @@
;;; # UUID Support
(i/def-database-definition ^:const ^:private with-uuid
(i/def-database-definition ^:private with-uuid
["users"
[{:field-name "user_id", :base-type :type/UUID}]
[[#uuid "4f01dcfd-13f7-430c-8e6f-e505c0851027"]
......@@ -99,7 +99,7 @@
;; Make sure that Tables / Fields with dots in their names get escaped properly
(i/def-database-definition ^:const ^:private dots-in-names
(i/def-database-definition ^:private dots-in-names
["objects.stuff"
[{:field-name "dotted.name", :base-type :type/Text}]
[["toucan_cage"]
......@@ -117,7 +117,7 @@
;; Make sure that duplicate column names (e.g. caused by using a FK) still return both columns
(i/def-database-definition ^:const ^:private duplicate-names
(i/def-database-definition ^:private duplicate-names
["birds"
[{:field-name "name", :base-type :type/Text}]
[["Rasta"]
......@@ -136,6 +136,22 @@
:data (dissoc :cols :native_form)))
;;; Check support for `inet` columns
(i/def-database-definition ^:private ip-addresses
["addresses"
[{:field-name "ip", :base-type {:native "inet"}}]
[[(hsql/raw "'192.168.1.1'::inet")]
[(hsql/raw "'10.4.4.15'::inet")]]])
;; Filtering by inet columns should add the appropriate SQL cast, e.g. `cast('192.168.1.1' AS inet)` (otherwise this wouldn't work)
(expect-with-engine :postgres
[[1]]
(rows (data/dataset metabase.driver.postgres-test/ip-addresses
(data/run-query addresses
(ql/aggregation (ql/count))
(ql/filter (ql/= $ip "192.168.1.1"))))))
;; Check that we properly fetch materialized views.
;; As discussed in #2355 they don't come back from JDBC `DatabaseMetadata` so we have to fetch them manually.
(expect-with-engine :postgres
......
......@@ -16,6 +16,7 @@
:type/Decimal "DECIMAL"
:type/Float "FLOAT"
:type/Integer "INTEGER"
:type/IPAddress "INET"
:type/Text "TEXT"
:type/Time "TIME"
:type/UUID "UUID"})
......
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