1616 */
1717package org .apache .arrow .driver .jdbc ;
1818
19+ import static org .junit .jupiter .api .Assertions .assertEquals ;
20+
1921import com .google .common .collect .ImmutableList ;
2022import java .sql .Connection ;
23+ import java .sql .Date ;
2124import java .sql .PreparedStatement ;
2225import java .sql .ResultSet ;
2326import java .sql .SQLException ;
2629import java .time .Instant ;
2730import java .time .LocalDateTime ;
2831import java .time .OffsetDateTime ;
32+ import java .time .ZoneId ;
2933import java .time .ZoneOffset ;
3034import java .time .ZonedDateTime ;
3135import java .util .Calendar ;
5155 */
5256public class TimestampResultSetTest {
5357 private static final MockFlightSqlProducer FLIGHT_SQL_PRODUCER = new MockFlightSqlProducer ();
58+ private static Instant firstDay2025 =
59+ OffsetDateTime .of (2025 , 1 , 1 , 0 , 0 , 0 , 0 , ZoneOffset .UTC ).toInstant ();
5460
5561 @ RegisterExtension public static FlightServerTestExtension FLIGHT_SERVER_TEST_EXTENSION ;
5662
@@ -70,8 +76,6 @@ public class TimestampResultSetTest {
7076
7177 @ BeforeAll
7278 public static void setup () throws SQLException {
73- Instant firstDay2025 = OffsetDateTime .of (2025 , 1 , 1 , 0 , 0 , 0 , 0 , ZoneOffset .UTC ).toInstant ();
74-
7579 FLIGHT_SQL_PRODUCER .addSelectQuery (
7680 QUERY_STRING ,
7781 QUERY_SCHEMA ,
@@ -161,4 +165,56 @@ public void test() {
161165 throw new RuntimeException (e );
162166 }
163167 }
168+
169+ @ Test
170+ public void testTzConnectionOptionIsRespected () {
171+ TimeZone .setDefault (TimeZone .getTimeZone ("UTC" ));
172+ try (Connection connection = FLIGHT_SERVER_TEST_EXTENSION .getConnection ("GTM+1" )) {
173+ try (PreparedStatement s = connection .prepareStatement (QUERY_STRING )) {
174+ try (ResultSet rs = s .executeQuery ()) {
175+ int numCols = rs .getMetaData ().getColumnCount ();
176+ try {
177+ rs .next ();
178+ for (int i = 1 ; i <= numCols ; i ++) {
179+ int type = rs .getMetaData ().getColumnType (i );
180+ String name = rs .getMetaData ().getColumnName (i );
181+ Date date = rs .getDate (i );
182+ Timestamp timestamp = rs .getTimestamp (i );
183+ String string = rs .getString (i );
184+ Timestamp object = (Timestamp ) rs .getObject (i );
185+ Timestamp objectWithClass = rs .getObject (i , Timestamp .class );
186+ Timestamp timestampWithDefaultCalendar = rs .getTimestamp (i , Calendar .getInstance ());
187+ Timestamp timestampWithUTCCalendar =
188+ rs .getTimestamp (i , Calendar .getInstance (TimeZone .getTimeZone ("UTC" )));
189+ LocalDateTime objectLocalDateTime = rs .getObject (i , LocalDateTime .class );
190+
191+ assertEquals (timestamp , object , "Mismatch for column " + name );
192+ assertEquals (timestamp , objectWithClass , "Mismatch for column " + name );
193+ assertEquals (timestamp .toString (), string , "Mismatch for column " + name );
194+ assertEquals (timestamp .toString (), object .toString (), "Mismatch for column " + name );
195+ assertEquals (
196+ objectLocalDateTime ,
197+ LocalDateTime .ofInstant (firstDay2025 , ZoneId .of ("UTC" )),
198+ "Mismatch for column " + name );
199+
200+ if (type == Types .TIMESTAMP_WITH_TIMEZONE ) {
201+ Instant instant = rs .getObject (i , Instant .class );
202+ OffsetDateTime offsetDateTime = rs .getObject (i , OffsetDateTime .class );
203+ ZonedDateTime zonedDateTime = rs .getObject (i , ZonedDateTime .class );
204+ assertEquals (firstDay2025 , instant , "Mismatch for column " + name );
205+ assertEquals (
206+ firstDay2025 , offsetDateTime .toInstant (), "Mismatch for column " + name );
207+ assertEquals (
208+ firstDay2025 , zonedDateTime .toInstant (), "Mismatch for column " + name );
209+ }
210+ }
211+ } catch (SQLException e ) {
212+ throw new RuntimeException (e );
213+ }
214+ }
215+ }
216+ } catch (SQLException e ) {
217+ throw new RuntimeException (e );
218+ }
219+ }
164220}
0 commit comments