Skip to content

Commit 1bc5b01

Browse files
committed
added JDBC test
1 parent 70a905a commit 1bc5b01

File tree

1 file changed

+28
-1
lines changed

1 file changed

+28
-1
lines changed

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

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import com.clickhouse.client.api.ClientConfigProperties;
44
import com.clickhouse.client.api.DataTypeUtils;
55
import com.clickhouse.client.api.internal.ServerSettings;
6+
import com.clickhouse.client.api.sql.SQLUtils;
67
import com.clickhouse.data.ClickHouseVersion;
78
import com.clickhouse.data.Tuple;
89
import org.slf4j.Logger;
@@ -47,6 +48,7 @@
4748

4849
import static org.testng.Assert.assertEquals;
4950
import static org.testng.Assert.assertFalse;
51+
import static org.testng.Assert.assertNotEquals;
5052
import static org.testng.Assert.assertNull;
5153
import static org.testng.Assert.assertThrows;
5254
import static org.testng.Assert.assertTrue;
@@ -1372,7 +1374,32 @@ public void testJSONWritingAsString() throws SQLException {
13721374
}
13731375
}
13741376

1375-
@Test(groups = { "integration" }, enabled = false)
1377+
@Test(groups = { "integration" })
1378+
public void testReadingJSONBinary() throws SQLException {
1379+
if (ClickHouseVersion.of(getServerVersion()).check("(,24.8]")) {
1380+
return; // JSON was introduced in 24.10
1381+
}
1382+
1383+
Properties properties = new Properties();
1384+
properties.put(ClientConfigProperties.serverSetting("allow_experimental_json_type"), "1");
1385+
try (Connection conn = getJdbcConnection(properties);
1386+
Statement stmt = conn.createStatement()) {
1387+
1388+
final String json = "{\"count\": 1000, \"event\": { \"name\": \"start\", \"value\": 0.10} }";
1389+
String sql = String.format("SELECT %1$s::JSON(), %1$s::JSON(count Int16)", SQLUtils.enquoteLiteral(json));
1390+
try (ResultSet rs = stmt.executeQuery(sql)) {
1391+
rs.next();
1392+
1393+
Map<String, Object> val1 = (Map<String, Object>) rs.getObject(1);
1394+
assertEquals(val1.get("count"), 1000L);
1395+
Map<String, Object> val2 = (Map<String, Object>) rs.getObject(2);
1396+
assertEquals(val2.get("count"), (short)1000);
1397+
}
1398+
}
1399+
}
1400+
1401+
1402+
@Test(groups = { "integration" }, enabled = false)
13761403
public void testGeometricTypesSimpleStatement() throws SQLException {
13771404
// TODO: add LineString and MultiLineString support
13781405
runQuery("CREATE TABLE test_geometric (order Int8, "

0 commit comments

Comments
 (0)