Skip to content

Commit 0ac5de1

Browse files
committed
added test case to reproduce the issue
1 parent f000e1f commit 0ac5de1

File tree

1 file changed

+45
-0
lines changed

1 file changed

+45
-0
lines changed

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

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
import org.slf4j.Logger;
1111
import org.slf4j.LoggerFactory;
1212
import org.testng.annotations.BeforeClass;
13+
import org.testng.annotations.DataProvider;
1314
import org.testng.annotations.Test;
1415

1516
import java.math.BigDecimal;
@@ -1960,4 +1961,48 @@ public void testGeoMultiPolygon() throws Exception {
19601961
}
19611962
}
19621963

1964+
@Test(groups = { "integration" }, dataProvider = "testJSONReadDP")
1965+
public void testJSONRead(String json) throws Exception {
1966+
if (ClickHouseVersion.of(getServerVersion()).check("(,24.8]")) {
1967+
return; // JSON was introduced in 24.10
1968+
}
1969+
Properties createProperties = new Properties();
1970+
createProperties.put(ClientConfigProperties.serverSetting("allow_experimental_json_type"), "1");
1971+
runQuery("DROP TABLE IF EXISTS test_jdbc_json_read");
1972+
runQuery("CREATE TABLE test_jdbc_json_read (data JSON) ENGINE = MergeTree ORDER BY ()", createProperties);
1973+
1974+
try (Connection conn = getJdbcConnection(); Statement stmt = conn.createStatement()) {
1975+
final String sql = "INSERT INTO test_jdbc_json_read (data) VALUES ('%s'), ('{}')";
1976+
stmt.executeUpdate(String.format(sql, json));
1977+
1978+
try (ResultSet rs = stmt.executeQuery("SELECT * FROM test_jdbc_json_read")) {
1979+
1980+
assertTrue(rs.next());
1981+
Object jsonObj = rs.getObject(1);
1982+
assertTrue(rs.next());
1983+
Object emptyJsonObj = rs.getObject(1);
1984+
assertFalse(rs.next());
1985+
}
1986+
}
1987+
}
1988+
1989+
@DataProvider(name = "testJSONReadDP")
1990+
public Object[][] testJSONReadDP() {
1991+
return new Object[][] {
1992+
{"{\"key\": \"value\"}"}, // Simple object
1993+
{"{\"numbers\":[1, 2, 3]}"},
1994+
{"{\"strings\":[\"one\", \"two\", \"three\"]}"},
1995+
{"{\"nested\":{\"key\": \"value\"}}"}, // nested objects
1996+
{"{\"nested\":{\"numbers\":[1, 2, 3]}}"}, // nested objects
1997+
{"{\"nested\":{\"strings\":[\"one\", \"two\", \"three\"]}}"}, // nested objects
1998+
{"{\"array\":[{\"key\": \"value\"},{\"key\": \"value\"}]}"}, // array of objects
1999+
{"{\"array\":[{\"numbers\":[1, 2, 3]},{\"strings\":[\"one\", \"two\", \"three\"]}]}"}, // array of objects
2000+
{"{\"array\":[{\"nested\":{\"key\": \"value\"}},{\"nested\":{\"numbers\":[1, 2, 3]}}]}"}, // array of objects
2001+
{"{\"array\":[{\"nested\":{\"strings\":[\"one\", \"two\", \"three\"]}}]}"}, // array of objects
2002+
{"{\"array\":[{\"nested\":[{\"key\": \"value\"}]}]}"}, // simple array of objects
2003+
{"{\"level1\": {\"level2\": {\"level3\": \"value\"}}}"}, // deep nested objects
2004+
{"{\"level1\": {\"level2\": {\"level3\": {\"level4\": \"value\"}}}}"}, // deep nested objects
2005+
2006+
};
2007+
}
19632008
}

0 commit comments

Comments
 (0)