Skip to content

Commit 4b9f279

Browse files
authored
Merge pull request #2022 from ClickHouse/metabase-issues
2 parents 49a2dbb + 636f428 commit 4b9f279

File tree

2 files changed

+30
-1
lines changed

2 files changed

+30
-1
lines changed

client-v2/src/main/java/com/clickhouse/client/api/data_formats/internal/BinaryStreamReader.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,8 @@ public <T> T readValue(ClickHouseColumn column, Class<?> typeHint) throws IOExce
210210
return (T) readTuple(column);
211211
case Nothing:
212212
return null;
213-
// case SimpleAggregateFunction:
213+
case SimpleAggregateFunction:
214+
return (T) readValue(column.getNestedColumns().get(0));
214215
case AggregateFunction:
215216
return (T) readBitmap( column);
216217
default:

client-v2/src/test/java/com/clickhouse/client/query/QueryTests.java

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@
5252
import java.net.Inet4Address;
5353
import java.net.Inet6Address;
5454
import java.net.InetAddress;
55+
import java.nio.charset.StandardCharsets;
5556
import java.time.LocalDate;
5657
import java.time.LocalDateTime;
5758
import java.time.ZoneId;
@@ -62,6 +63,7 @@
6263
import java.util.HashMap;
6364
import java.util.HashSet;
6465
import java.util.Iterator;
66+
import java.util.LinkedHashMap;
6567
import java.util.List;
6668
import java.util.Map;
6769
import java.util.Random;
@@ -73,6 +75,7 @@
7375
import java.util.concurrent.Executors;
7476
import java.util.concurrent.Future;
7577
import java.util.concurrent.TimeUnit;
78+
import java.util.concurrent.TimeoutException;
7679
import java.util.function.Consumer;
7780
import java.util.function.Function;
7881
import java.util.function.Supplier;
@@ -1929,4 +1932,29 @@ protected Client.Builder newClient() {
19291932
.allowBinaryReaderToReuseBuffers(usePreallocatedBuffers)
19301933
.useNewImplementation(System.getProperty("client.tests.useNewImplementation", "true").equals("true"));
19311934
}
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+
}
19321960
}

0 commit comments

Comments
 (0)