Skip to content

Commit 3f27aa3

Browse files
committed
added JDBC tests
1 parent 6c7e8f7 commit 3f27aa3

File tree

3 files changed

+46
-3
lines changed

3 files changed

+46
-3
lines changed

client-v2/src/main/java/com/clickhouse/client/api/data_formats/internal/AbstractBinaryFormatReader.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -477,7 +477,7 @@ public ZonedDateTime getZonedDateTime(String colName) {
477477
case Date32:
478478
return readValue(colName);
479479
default:
480-
throw new ClientException("Column of type " + column.getDataType() + " cannot be converted to Instant");
480+
throw new ClientException("Column of type " + column.getDataType() + " cannot be converted to ZonedDateTime");
481481
}
482482
}
483483

client-v2/src/test/java/com/clickhouse/client/datatypes/DataTypeTests.java

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -687,7 +687,7 @@ public void testAllDataTypesKnown() {
687687
}
688688

689689
@Test(groups = {"integration"})
690-
public void testTimeType() throws Exception {
690+
public void testTime64() throws Exception {
691691
if (isVersionMatch("(,25.4]")) {
692692
return;
693693
}
@@ -696,7 +696,7 @@ public void testTimeType() throws Exception {
696696
client.execute("DROP TABLE IF EXISTS " + table).get();
697697
client.execute(tableDefinition(table, "o_num UInt32", "time Time"), (CommandSettings) new CommandSettings().serverSetting("enable_time_time64_type", "1")).get();
698698

699-
String insertSQL = "INSERT INTO " + table + " VALUES (1, '999:00:00'), (2, '999:59:00'), (3, '000:00:00')";
699+
String insertSQL = "INSERT INTO " + table + " VALUES (1, '999:00:00'), (2, '999:59:00'), (3, '000:00:00'), (4, '-999:59:59')";
700700
try (QueryResponse response = client.query(insertSQL).get()) {}
701701

702702

@@ -716,6 +716,11 @@ record = records.get(2);
716716
Assert.assertEquals(record.getInteger("o_num"), 3);
717717
Assert.assertEquals(record.getInteger("time"), 0);
718718
Assert.assertEquals(record.getInstant("time"), Instant.ofEpochSecond(0));
719+
720+
record = records.get(3);
721+
Assert.assertEquals(record.getInteger("o_num"), 4);
722+
Assert.assertEquals(record.getInteger("time"), - (TimeUnit.HOURS.toSeconds(999) + TimeUnit.MINUTES.toSeconds(59)));
723+
Assert.assertEquals(record.getInstant("time"), Instant.ofEpochSecond(TimeUnit.HOURS.toSeconds(999) + TimeUnit.MINUTES.toSeconds(59)));
719724
}
720725

721726

jdbc-v2/src/test/java/com/clickhouse/jdbc/DataTypeTests.java

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,10 +41,12 @@
4141
import java.util.Random;
4242
import java.util.TimeZone;
4343
import java.util.UUID;
44+
import java.util.concurrent.TimeUnit;
4445

4546
import static org.testng.Assert.assertEquals;
4647
import static org.testng.Assert.assertFalse;
4748
import static org.testng.Assert.assertNull;
49+
import static org.testng.Assert.assertThrows;
4850
import static org.testng.Assert.assertTrue;
4951

5052
@Test(groups = { "integration" })
@@ -550,6 +552,42 @@ public void testDateTypes() throws SQLException {
550552
}
551553
}
552554

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+
553591
@Test(groups = { "integration" })
554592
public void testStringTypes() throws SQLException {
555593
runQuery("CREATE TABLE test_strings (order Int8, "

0 commit comments

Comments
 (0)