|
52 | 52 | import java.net.Inet4Address; |
53 | 53 | import java.net.Inet6Address; |
54 | 54 | import java.net.InetAddress; |
| 55 | +import java.nio.charset.StandardCharsets; |
55 | 56 | import java.time.LocalDate; |
56 | 57 | import java.time.LocalDateTime; |
57 | 58 | import java.time.ZoneId; |
|
62 | 63 | import java.util.HashMap; |
63 | 64 | import java.util.HashSet; |
64 | 65 | import java.util.Iterator; |
| 66 | +import java.util.LinkedHashMap; |
65 | 67 | import java.util.List; |
66 | 68 | import java.util.Map; |
67 | 69 | import java.util.Random; |
|
73 | 75 | import java.util.concurrent.Executors; |
74 | 76 | import java.util.concurrent.Future; |
75 | 77 | import java.util.concurrent.TimeUnit; |
| 78 | +import java.util.concurrent.TimeoutException; |
76 | 79 | import java.util.function.Consumer; |
77 | 80 | import java.util.function.Function; |
78 | 81 | import java.util.function.Supplier; |
@@ -1929,4 +1932,29 @@ protected Client.Builder newClient() { |
1929 | 1932 | .allowBinaryReaderToReuseBuffers(usePreallocatedBuffers) |
1930 | 1933 | .useNewImplementation(System.getProperty("client.tests.useNewImplementation", "true").equals("true")); |
1931 | 1934 | } |
| 1935 | + |
| 1936 | + @Test(groups = {"integration"}) |
| 1937 | + public void testReadingSimpleAggregateFunction() throws Exception { |
| 1938 | + final String tableName = "simple_aggregate_function_test_table"; |
| 1939 | + client.execute("DROP TABLE IF EXISTS " + tableName).get(); |
| 1940 | + client.execute("CREATE TABLE `" + tableName + "` " + |
| 1941 | + "(idx UInt8, lowest_value SimpleAggregateFunction(min, UInt8), count SimpleAggregateFunction(sum, Int64), mp SimpleAggregateFunction(maxMap, Map(UInt8, UInt8))) " + |
| 1942 | + "ENGINE Memory;").get(); |
| 1943 | + |
| 1944 | + |
| 1945 | + try (InsertResponse response = client.insert(tableName, new ByteArrayInputStream("1\t2\t3\t{1:2}".getBytes(StandardCharsets.UTF_8)), ClickHouseFormat.TSV).get(30, TimeUnit.SECONDS)) { |
| 1946 | + Assert.assertEquals(response.getWrittenRows(), 1); |
| 1947 | + } |
| 1948 | + |
| 1949 | + try (QueryResponse queryResponse = client.query("SELECT * FROM " + tableName + " LIMIT 1").get(30, TimeUnit.SECONDS)) { |
| 1950 | + |
| 1951 | + ClickHouseBinaryFormatReader reader = client.newBinaryFormatReader(queryResponse); |
| 1952 | + Assert.assertNotNull(reader.next()); |
| 1953 | + Assert.assertEquals(reader.getByte("idx"), Byte.valueOf("1")); |
| 1954 | + Assert.assertEquals((Short) reader.readValue("lowest_value"), Short.parseShort("2")); |
| 1955 | + Assert.assertEquals((Long) reader.readValue("count"), Long.parseLong("3")); |
| 1956 | + Assert.assertEquals(String.valueOf((LinkedHashMap) reader.readValue("mp")), "{1=2}"); |
| 1957 | + Assert.assertFalse(reader.hasNext()); |
| 1958 | + } |
| 1959 | + } |
1932 | 1960 | } |
0 commit comments