Skip to content
Snippets Groups Projects
Unverified Commit 19806cfc authored by Case Nelson's avatar Case Nelson Committed by GitHub
Browse files

Handle Interval values coming from Redshift (#28820)

Fixes #19501

Redshift jdbc driver wraps intervals in a special class whereas postgres
simply returns strings. This unwraps the special redshift class into the
same string representation.
parent c79dcc7f
No related branches found
No related tags found
No related merge requests found
......@@ -22,7 +22,8 @@
[metabase.util.i18n :refer [trs]]
[metabase.util.log :as log])
(:import
(java.sql Connection PreparedStatement ResultSet Types)
(com.amazon.redshift.util RedshiftInterval)
(java.sql Connection PreparedStatement ResultSet ResultSetMetaData Types)
(java.time OffsetTime)))
(set! *warn-on-reflection* true)
......@@ -282,6 +283,13 @@
[::sql-jdbc.legacy/use-legacy-classes-for-read-and-set Types/TIMESTAMP]
[:postgres Types/TIMESTAMP])
(defmethod sql-jdbc.execute/read-column-thunk
[:redshift Types/OTHER]
[driver ^ResultSet rs ^ResultSetMetaData rsmeta ^Integer i]
(if (= "interval" (.getColumnTypeName rsmeta i))
#(.getValue ^RedshiftInterval (.getObject rs i RedshiftInterval))
((get-method sql-jdbc.execute/read-column-thunk [:postgres (.getColumnType rsmeta i)]) driver rs rsmeta i)))
(prefer-method
sql-jdbc.execute/read-column-thunk
[::sql-jdbc.legacy/use-legacy-classes-for-read-and-set Types/TIME]
......
......@@ -356,3 +356,11 @@
(mt/with-native-query-testing-context query
(is (= [1 "2022-01-20T18:49:10.656Z"]
(mt/first-row (qp/process-query query))))))))))))
(deftest interval-test
(mt/test-drivers #{:postgres :redshift}
(testing "Redshift Interval values should behave the same as postgres (#19501)"
(is (= ["0 years 0 mons 5 days 0 hours 0 mins 0.0 secs"]
(mt/first-row
(qp/process-query
(mt/native-query {:query "select interval '5 days'"}))))))))
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