|
10 | 10 | import org.slf4j.Logger; |
11 | 11 | import org.slf4j.LoggerFactory; |
12 | 12 | import org.testng.annotations.BeforeClass; |
| 13 | +import org.testng.annotations.DataProvider; |
13 | 14 | import org.testng.annotations.Test; |
14 | 15 |
|
15 | 16 | import java.math.BigDecimal; |
@@ -1960,4 +1961,48 @@ public void testGeoMultiPolygon() throws Exception { |
1960 | 1961 | } |
1961 | 1962 | } |
1962 | 1963 |
|
| 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 | + } |
1963 | 2008 | } |
0 commit comments