Closed
Description
Describe the bug
The #2022 hasn't brought full support for simple aggregate functions. When using ClickHouseBinaryFormatReader to read query response. If the table contains a column with SimpleAggregateFunctions using functions like getLong returns an error message saying that
Column counter SimpleAggregateFunction cannot be converted to long
This error seems to be also present for jdbc:
Caused by: com.clickhouse.client.api.ClientException: Column counter SimpleAggregateFunction cannot be converted to long
at com.clickhouse.client.api.data_formats.internal.AbstractBinaryFormatReader.readNumberValue(AbstractBinaryFormatReader.java:312) ~[jdbc-v2-0.8.0.jar:jdbc-v2 0.8.0 (revision: 5b5ac2e)]
at com.clickhouse.client.api.data_formats.internal.AbstractBinaryFormatReader.getLong(AbstractBinaryFormatReader.java:333) ~[jdbc-v2-0.8.0.jar:jdbc-v2 0.8.0 (revision: 5b5ac2e)]
at com.clickhouse.jdbc.ResultSetImpl.getLong(ResultSetImpl.java:293) ~[jdbc-v2-0.8.0.jar:clickhouse-jdbc 0.8.0 (revision: 5b5ac2e)]
Code example
This test is just adapted from the test case added in the #2022
public void testReadingSimpleAggregateFunction2() throws Exception {
final String tableName = "simple_aggregate_function_test_table";
client.execute("DROP TABLE IF EXISTS " + tableName).get();
client.execute("CREATE TABLE `" + tableName + "` " +
"(idx UInt8, lowest_value SimpleAggregateFunction(min, UInt8), count SimpleAggregateFunction(sum, Int64), mp SimpleAggregateFunction(maxMap, Map(UInt8, UInt8))) " +
"ENGINE Memory;").get();
try (InsertResponse response = client.insert(tableName, new ByteArrayInputStream("1\t2\t3\t{1:2}".getBytes(StandardCharsets.UTF_8)), ClickHouseFormat.TSV).get(30, TimeUnit.SECONDS)) {
Assert.assertEquals(response.getWrittenRows(), 1);
}
try (QueryResponse queryResponse = client.query("SELECT * FROM " + tableName + " LIMIT 1").get(30, TimeUnit.SECONDS)) {
ClickHouseBinaryFormatReader reader = client.newBinaryFormatReader(queryResponse);
Assert.assertNotNull(reader.next());
Assert.assertEquals(reader.getByte("idx"), Byte.valueOf("1"));
Assert.assertEquals((Short) reader.getShort("lowest_value"), Short.parseShort("2"));
Assert.assertEquals((Long) reader.getLong("count"), Long.parseLong("3"));
Assert.assertEquals(String.valueOf((LinkedHashMap) reader.readValue("mp")), "{1=2}");
Assert.assertFalse(reader.hasNext());
}
}
Error log
com.clickhouse.client.api.ClientException: Column lowest_value SimpleAggregateFunction cannot be converted to short
at com.clickhouse.client.api.data_formats.internal.AbstractBinaryFormatReader.readNumberValue(AbstractBinaryFormatReader.java:312)
at com.clickhouse.client.api.data_formats.internal.AbstractBinaryFormatReader.getShort(AbstractBinaryFormatReader.java:323)
at com.clickhouse.client.query.QueryTests.testReadingSimpleAggregateFunction2(QueryTests.java:1980)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:569)
at org.testng.internal.invokers.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:136)
at org.testng.internal.invokers.TestInvoker.invokeMethod(TestInvoker.java:658)
at org.testng.internal.invokers.TestInvoker.invokeTestMethod(TestInvoker.java:219)
at org.testng.internal.invokers.MethodRunner.runInSequence(MethodRunner.java:50)
at org.testng.internal.invokers.TestInvoker$MethodInvocationAgent.invoke(TestInvoker.java:923)
at org.testng.internal.invokers.TestInvoker.invokeTestMethods(TestInvoker.java:192)
at org.testng.internal.invokers.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:146)
at org.testng.internal.invokers.TestMethodWorker.run(TestMethodWorker.java:128)
at java.base/java.util.ArrayList.forEach(ArrayList.java:1511)
at org.testng.TestRunner.privateRun(TestRunner.java:808)
at org.testng.TestRunner.run(TestRunner.java:603)
at org.testng.SuiteRunner.runTest(SuiteRunner.java:429)
at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:423)
at org.testng.SuiteRunner.privateRun(SuiteRunner.java:383)
at org.testng.SuiteRunner.run(SuiteRunner.java:326)
at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:52)
at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:95)
at org.testng.TestNG.runSuitesSequentially(TestNG.java:1249)
at org.testng.TestNG.runSuitesLocally(TestNG.java:1169)
at org.testng.TestNG.runSuites(TestNG.java:1092)
at org.testng.TestNG.run(TestNG.java:1060)
at com.intellij.rt.testng.IDEARemoteTestNG.run(IDEARemoteTestNG.java:65)
at com.intellij.rt.testng.RemoteTestNGStarter.main(RemoteTestNGStarter.java:105