|
41 | 41 | import java.util.Random;
|
42 | 42 | import java.util.TimeZone;
|
43 | 43 | import java.util.UUID;
|
| 44 | +import java.util.concurrent.TimeUnit; |
44 | 45 |
|
45 | 46 | import static org.testng.Assert.assertEquals;
|
46 | 47 | import static org.testng.Assert.assertFalse;
|
47 | 48 | import static org.testng.Assert.assertNull;
|
| 49 | +import static org.testng.Assert.assertThrows; |
48 | 50 | import static org.testng.Assert.assertTrue;
|
49 | 51 |
|
50 | 52 | @Test(groups = { "integration" })
|
@@ -550,6 +552,42 @@ public void testDateTypes() throws SQLException {
|
550 | 552 | }
|
551 | 553 | }
|
552 | 554 |
|
| 555 | + |
| 556 | + @Test(groups = { "integration" }) |
| 557 | + public void testTimeTypes() throws SQLException { |
| 558 | + Properties createProperties = new Properties(); |
| 559 | + createProperties.put(ClientConfigProperties.serverSetting("enable_time_time64_type"), "1"); |
| 560 | + runQuery("CREATE TABLE test_time64 (order Int8, " |
| 561 | + + "time Time('UTC'), time64 Time64(9) " |
| 562 | + + ") ENGINE = MergeTree ORDER BY ()", |
| 563 | + createProperties); |
| 564 | + |
| 565 | + runQuery("INSERT INTO test_time64 (order, time, time64) VALUES " + |
| 566 | + " (1, '-999:59:59', '-999:59:59.999999999'), " + |
| 567 | + " (2, '999:59:59', '999:59:59.999999999')"); |
| 568 | + |
| 569 | + // Check the results |
| 570 | + try (Statement stmt = getJdbcConnection().createStatement()) { |
| 571 | + try (ResultSet rs = stmt.executeQuery("SELECT * FROM test_time64")) { |
| 572 | + assertTrue(rs.next()); |
| 573 | + assertEquals(rs.getInt("order"), 1); |
| 574 | +// assertEquals(rs.getInt("time"), -(TimeUnit.HOURS.toSeconds(999) + TimeUnit.MINUTES.toSeconds(59) + 59)); |
| 575 | +// assertEquals(rs.getInt("time64"), -(TimeUnit.HOURS.toSeconds(999) + TimeUnit.MINUTES.toSeconds(59) + 59)); |
| 576 | + |
| 577 | + assertTrue(rs.next()); |
| 578 | + assertEquals(rs.getInt("order"), 2); |
| 579 | + assertEquals(rs.getInt("time"), (TimeUnit.HOURS.toSeconds(999) + TimeUnit.MINUTES.toSeconds(59) + 59)); |
| 580 | + assertEquals(rs.getLong("time64"), (TimeUnit.HOURS.toNanos(999) + TimeUnit.MINUTES.toNanos(59) + TimeUnit.SECONDS.toNanos(59)) + 999999999); |
| 581 | + |
| 582 | + assertThrows(SQLException.class, () -> rs.getTime("time")); |
| 583 | + assertThrows(SQLException.class, () -> rs.getDate("time")); |
| 584 | + assertThrows(SQLException.class, () -> rs.getTimestamp("time")); |
| 585 | + |
| 586 | + assertFalse(rs.next()); |
| 587 | + } |
| 588 | + } |
| 589 | + } |
| 590 | + |
553 | 591 | @Test(groups = { "integration" })
|
554 | 592 | public void testStringTypes() throws SQLException {
|
555 | 593 | runQuery("CREATE TABLE test_strings (order Int8, "
|
|
0 commit comments