Skip to content
Snippets Groups Projects
Unverified Commit 2f59ea82 authored by metabase-bot[bot]'s avatar metabase-bot[bot] Committed by GitHub
Browse files

Handle Interval values coming from Redshift (#28820) (#28931)


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.

Co-authored-by: default avatarCase Nelson <case@metabase.com>
parent 50d27b32
Branches
Tags
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.
Please register or to comment