We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 001a14e commit b77b33aCopy full SHA for b77b33a
clickhouse/columns/factory.cpp
@@ -147,6 +147,9 @@ static ColumnRef CreateColumnFromAst(const TypeAst& ast) {
147
throw std::runtime_error("LowCardinality(" + nested.name + ") is not supported");
148
}
149
150
+ case TypeAst::SimpleAggregateFunction: {
151
+ return CreateTerminalColumn(ast.elements.back());
152
+ }
153
154
case TypeAst::Null:
155
case TypeAst::Number:
clickhouse/types/type_parser.cpp
@@ -79,6 +79,10 @@ static TypeAst::Meta GetTypeMeta(const StringView& name) {
79
return TypeAst::LowCardinality;
80
81
82
+ if (name == "SimpleAggregateFunction") {
83
+ return TypeAst::SimpleAggregateFunction;
84
85
+
86
return TypeAst::Terminal;
87
88
clickhouse/types/type_parser.h
@@ -19,6 +19,7 @@ struct TypeAst {
19
Tuple,
20
Enum,
21
LowCardinality,
22
+ SimpleAggregateFunction
23
};
24
25
/// Type's category.
ut/client_ut.cpp
@@ -284,6 +284,34 @@ TEST_P(ClientCase, Numbers) {
284
EXPECT_EQ(100000U, num);
285
286
287
+TEST_P(ClientCase, SimpleAggregateFunction) {
288
+ client_->Execute("DROP TABLE IF EXISTS test_clickhouse_cpp.SimpleAggregateFunction");
289
+ client_->Execute(
290
+ "CREATE TABLE IF NOT EXISTS test_clickhouse_cpp.SimpleAggregateFunction (saf SimpleAggregateFunction(sum, UInt64))"
291
+ "ENGINE = Memory");
292
293
+ constexpr size_t EXPECTED_ROWS = 10;
294
+ client_->Execute("INSERT INTO test_clickhouse_cpp.SimpleAggregateFunction (saf) SELECT number FROM system.numbers LIMIT 10");
295
296
+ size_t total_rows = 0;
297
+ client_->Select("Select * FROM test_clickhouse_cpp.SimpleAggregateFunction", [&total_rows](const Block & block) {
298
+ if (block.GetRowCount() == 0)
299
+ return;
300
301
+ total_rows += block.GetRowCount();
302
+ auto col = block[0]->As<ColumnUInt64>();
303
+ ASSERT_NE(nullptr, col);
304
305
+ for (size_t r = 0; r < col->Size(); ++r) {
306
+ EXPECT_EQ(r, col->At(r));
307
308
309
+ EXPECT_EQ(total_rows, col->Size());
310
+ });
311
312
+ EXPECT_EQ(EXPECTED_ROWS, total_rows);
313
+}
314
315
TEST_P(ClientCase, Cancellable) {
316
/// Create a table.
317
client_->Execute(
ut/columns_ut.cpp
@@ -1,6 +1,7 @@
1
#include <clickhouse/columns/array.h>
2
#include <clickhouse/columns/date.h>
3
#include <clickhouse/columns/enum.h>
4
+#include <clickhouse/columns/factory.h>
5
#include <clickhouse/columns/lowcardinality.h>
6
#include <clickhouse/columns/nullable.h>
7
#include <clickhouse/columns/numeric.h>
@@ -258,3 +259,11 @@ TEST(ColumnsCase, LowCardinalityString_Save) {
258
259
EXPECT_EQ(col.At(i), foobar(i)) << " at pos: " << i;
260
261
262
263
+TEST(ColumnsCase, CreateSimpleAggregateFunction) {
264
+ auto col = CreateColumnByType("SimpleAggregateFunction(funt, Int32");
265
266
+ ASSERT_EQ("Int32", col->Type()->GetName());
267
+ ASSERT_EQ(Type::Int32, col->Type()->GetCode());
268
+ ASSERT_NE(nullptr, col->As<ColumnInt32>());
269
ut/type_parser_ut.cpp
@@ -190,3 +190,20 @@ TEST(TypeParserCase, LowCardinality_FixedString) {
190
auto param = TypeAst{TypeAst::Number, Type::Void, "", 10, {}};
191
ASSERT_EQ(ast.elements[0].elements[0], param);
192
193
194
+TEST(TypeParserCase, SimpleAggregateFunction_UInt64) {
195
+ TypeAst ast;
196
+ TypeParser("SimpleAggregateFunction(func, UInt64)").Parse(&ast);
197
+ ASSERT_EQ(ast.meta, TypeAst::SimpleAggregateFunction);
198
+ ASSERT_EQ(ast.name, "SimpleAggregateFunction");
199
+ ASSERT_EQ(ast.code, Type::Void);
200
+ ASSERT_EQ(ast.elements.size(), 2u);
201
+ ASSERT_EQ(ast.elements[0].name, "func");
202
+ ASSERT_EQ(ast.elements[0].code, Type::Void);
203
+ ASSERT_EQ(ast.elements[0].meta, TypeAst::Terminal);
204
+ ASSERT_EQ(ast.elements[0].value, 0);
205
+ ASSERT_EQ(ast.elements[1].name, "UInt64");
206
+ ASSERT_EQ(ast.elements[1].code, Type::UInt64);
207
+ ASSERT_EQ(ast.elements[1].meta, TypeAst::Terminal);
208
+ ASSERT_EQ(ast.elements[1].value, 0);
209
0 commit comments