Skip to content

Commit 73d37d0

Browse files
author
Paultagoras
committed
Update DataTypeTests.java
1 parent 42e4d02 commit 73d37d0

File tree

1 file changed

+131
-4
lines changed

1 file changed

+131
-4
lines changed

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

Lines changed: 131 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -572,6 +572,135 @@ public void testNullableTypesSimpleStatement() throws SQLException {
572572
}
573573
}
574574

575+
@Test
576+
public void testLowCardinalityTypeSimpleStatement() throws SQLException {
577+
runQuery("CREATE TABLE test_low_cardinality (order Int8, "
578+
+ "lowcardinality LowCardinality(String)"
579+
+ ") ENGINE = Memory");
580+
581+
// Insert random (valid) values
582+
long seed = System.currentTimeMillis();
583+
Random rand = new Random(seed);
584+
log.info("Random seed was: {}", seed);
585+
586+
String lowcardinality = "string" + rand.nextInt(1000);
587+
588+
insertData(String.format("INSERT INTO test_low_cardinality VALUES ( 1, '%s' )",
589+
lowcardinality));
590+
591+
// Check the results
592+
try (Connection conn = getConnection()) {
593+
try (Statement stmt = conn.createStatement()) {
594+
try (ResultSet rs = stmt.executeQuery("SELECT * FROM test_low_cardinality ORDER BY order")) {
595+
assertTrue(rs.next());
596+
assertEquals(rs.getString("lowcardinality"), lowcardinality);
597+
598+
assertFalse(rs.next());
599+
}
600+
}
601+
}
602+
}
603+
604+
@Test
605+
public void testSimpleAggregateFunction() throws SQLException {
606+
runQuery("CREATE TABLE test_aggregate (order Int8, "
607+
+ "int8 Int8"
608+
+ ") ENGINE = Memory");
609+
610+
// Insert random (valid) values
611+
long seed = System.currentTimeMillis();
612+
Random rand = new Random(seed);
613+
log.info("Random seed was: {}", seed);
614+
615+
int int8 = rand.nextInt(256) - 128;
616+
617+
insertData(String.format("INSERT INTO test_aggregate VALUES ( 1, %d )", int8));
618+
insertData(String.format("INSERT INTO test_aggregate VALUES ( 2, %d )", int8));
619+
insertData(String.format("INSERT INTO test_aggregate VALUES ( 3, %d )", int8));
620+
621+
// Check the results
622+
try (Connection conn = getConnection()) {
623+
try (Statement stmt = conn.createStatement()) {
624+
try (ResultSet rs = stmt.executeQuery("SELECT sum(int8) FROM test_aggregate")) {
625+
assertTrue(rs.next());
626+
assertEquals(rs.getInt(1), int8 * 3);
627+
}
628+
}
629+
}
630+
}
631+
632+
@Test
633+
public void testNestedTypeSimpleStatement() throws SQLException {
634+
runQuery("CREATE TABLE test_nested (order Int8, "
635+
+ "nested Nested (int8 Int8, int16 Int16, int32 Int32, int64 Int64, int128 Int128, int256 Int256)"
636+
+ ") ENGINE = Memory");
637+
638+
// Insert random (valid) values
639+
long seed = System.currentTimeMillis();
640+
Random rand = new Random(seed);
641+
log.info("Random seed was: {}", seed);
642+
643+
int int8 = rand.nextInt(256) - 128;
644+
int int16 = rand.nextInt(65536) - 32768;
645+
int int32 = rand.nextInt();
646+
long int64 = rand.nextLong();
647+
BigInteger int128 = new BigInteger(127, rand);
648+
BigInteger int256 = new BigInteger(255, rand);
649+
650+
String sql = String.format("INSERT INTO test_nested VALUES ( 1, [%s], [%s], [%s], [%s], [%s], [%s])",
651+
int8, int16, int32, int64, int128, int256);
652+
log.info("SQL: {}", sql);
653+
insertData(sql);
654+
655+
// Check the results
656+
try (Connection conn = getConnection()) {
657+
try (Statement stmt = conn.createStatement()) {
658+
try (ResultSet rs = stmt.executeQuery("SELECT * FROM test_nested ORDER BY order")) {
659+
assertTrue(rs.next());
660+
assertEquals(String.valueOf(((Object[])rs.getArray("nested.int8").getArray())[0]), String.valueOf(int8));
661+
assertEquals(String.valueOf(((Object[])rs.getArray("nested.int16").getArray())[0]), String.valueOf(int16));
662+
assertEquals(String.valueOf(((Object[])rs.getArray("nested.int32").getArray())[0]), String.valueOf(int32));
663+
assertEquals(String.valueOf(((Object[])rs.getArray("nested.int64").getArray())[0]), String.valueOf(int64));
664+
assertEquals(String.valueOf(((Object[])rs.getArray("nested.int128").getArray())[0]), String.valueOf(int128));
665+
assertEquals(String.valueOf(((Object[])rs.getArray("nested.int256").getArray())[0]), String.valueOf(int256));
666+
667+
assertFalse(rs.next());
668+
}
669+
}
670+
}
671+
}
672+
673+
674+
675+
@Test (enabled = false)//TODO: This type is experimental right now
676+
public void testJSONTypeSimpleStatement() throws SQLException {
677+
runQuery("CREATE TABLE test_json (order Int8, "
678+
+ "json JSON"
679+
+ ") ENGINE = Memory");
680+
681+
// Insert random (valid) values
682+
long seed = System.currentTimeMillis();
683+
Random rand = new Random(seed);
684+
log.info("Random seed was: {}", seed);
685+
686+
String json = "{\"key1\": \"" + rand.nextDouble() + "\", \"key2\": " + rand.nextInt() + ", \"key3\": [\"value3\", 4]}";
687+
insertData(String.format("INSERT INTO test_json VALUES ( 1, '%s' )", json));
688+
689+
// Check the results
690+
try (Connection conn = getConnection()) {
691+
try (Statement stmt = conn.createStatement()) {
692+
try (ResultSet rs = stmt.executeQuery("SELECT * FROM test_json ORDER BY order")) {
693+
assertTrue(rs.next());
694+
assertEquals(rs.getString("json"), json);
695+
696+
assertFalse(rs.next());
697+
}
698+
}
699+
}
700+
}
701+
702+
703+
575704
@Test (enabled = false)//TODO: The client doesn't support all of these yet
576705
public void testGeometricTypesSimpleStatement() throws SQLException {
577706
runQuery("CREATE TABLE test_geometric (order Int8, "
@@ -590,10 +719,8 @@ public void testGeometricTypesSimpleStatement() throws SQLException {
590719
String polygon = "[[(" + rand.nextInt(1000) + "," + rand.nextInt(1000) + ")],[(" + rand.nextInt(1000) + "," + rand.nextInt(1000) + "),(" + rand.nextInt(1000) + "," + rand.nextInt(1000) + ")]]";
591720
String multipolygon = "[[[(" + rand.nextInt(1000) + "," + rand.nextInt(1000) + ")],[(" + rand.nextInt(1000) + "," + rand.nextInt(1000) + "),(" + rand.nextInt(1000) + "," + rand.nextInt(1000) + ")]]]";
592721

593-
594-
String sql = String.format("INSERT INTO test_geometric VALUES ( 1, %s, %s, %s, %s, %s, %s )",
595-
point, ring, linestring, multilinestring, polygon, multipolygon);
596-
insertData(sql);
722+
insertData(String.format("INSERT INTO test_geometric VALUES ( 1, %s, %s, %s, %s, %s, %s )",
723+
point, ring, linestring, multilinestring, polygon, multipolygon));
597724

598725
// Check the results
599726
try (Connection conn = getConnection()) {

0 commit comments

Comments
 (0)