|
7 | 7 | import com.clickhouse.client.api.Client; |
8 | 8 | import com.clickhouse.client.api.DataTypeUtils; |
9 | 9 | import com.clickhouse.client.api.command.CommandSettings; |
| 10 | +import com.clickhouse.client.api.data_formats.ClickHouseBinaryFormatReader; |
| 11 | +import com.clickhouse.client.api.data_formats.internal.SerializerUtils; |
10 | 12 | import com.clickhouse.client.api.enums.Protocol; |
11 | 13 | import com.clickhouse.client.api.insert.InsertSettings; |
12 | 14 | import com.clickhouse.client.api.metadata.TableSchema; |
13 | 15 | import com.clickhouse.client.api.query.GenericRecord; |
14 | 16 | import com.clickhouse.client.api.query.QueryResponse; |
| 17 | +import com.clickhouse.client.api.sql.SQLUtils; |
15 | 18 | import com.clickhouse.data.ClickHouseDataType; |
16 | 19 | import com.clickhouse.data.ClickHouseVersion; |
17 | 20 | import lombok.AllArgsConstructor; |
@@ -874,6 +877,38 @@ private void testVariantWith(String withWhat, String[] fields, Object[] values, |
874 | 877 | } |
875 | 878 | } |
876 | 879 |
|
| 880 | + @Test(groups = {"integration"}, dataProvider = "testJSONBinaryFormat_dp") |
| 881 | + public void testJSONBinaryFormat(String jsonDef) throws Exception { |
| 882 | + if (isVersionMatch("(,24.8]")) { |
| 883 | + return; |
| 884 | + } |
| 885 | + |
| 886 | + final String table = "test_json_binary_format"; |
| 887 | + final String jsonCol = "value " + jsonDef; |
| 888 | + final String jsonValue = "{\"count\": 1000, \"stat\": {\"float\": 0.999, \"name\": \"temp\" }}"; |
| 889 | + |
| 890 | + client.execute("DROP TABLE IF EXISTS " + table).get().close(); |
| 891 | + client.execute(tableDefinition(table, jsonCol)).get().close(); |
| 892 | + client.execute("INSERT INTO " + table + " VALUES (" + SQLUtils.enquoteLiteral(jsonValue) + ")").get().close(); |
| 893 | + |
| 894 | + try (QueryResponse queryResponse = client.query("SELECT * FROM " + table + " LIMIT 1").get()) { |
| 895 | + ClickHouseBinaryFormatReader reader = client.newBinaryFormatReader(queryResponse); |
| 896 | + Map<String, Object> row = reader.next(); |
| 897 | + Object value = row.get("value"); |
| 898 | + System.out.println(value); |
| 899 | + } |
| 900 | + } |
| 901 | + |
| 902 | + @DataProvider |
| 903 | + public Object[][] testJSONBinaryFormat_dp() { |
| 904 | + |
| 905 | + return new Object[][] { |
| 906 | + {"JSON"}, |
| 907 | +// {"JSON(a Int32, d String)"}, |
| 908 | + {"JSON(stat.name String, count Int32)"}, |
| 909 | + }; |
| 910 | + } |
| 911 | + |
877 | 912 | public static String tableDefinition(String table, String... columns) { |
878 | 913 | StringBuilder sb = new StringBuilder(); |
879 | 914 | sb.append("CREATE TABLE " + table + " ( "); |
|
0 commit comments