MCPcopy Create free account
hub / github.com/ClickHouse/ClickHouse / executeImpl

Method executeImpl

src/Functions/array/arrayReduce.cpp:74–169  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

72
73
74ColumnPtr FunctionArrayReduce::executeImpl(const ColumnsWithTypeAndName & arguments, const DataTypePtr & result_type, size_t input_rows_count) const
75{
76 const IAggregateFunction & agg_func = *aggregate_function;
77 std::unique_ptr<Arena> arena = std::make_unique<Arena>();
78
79 /// Aggregate functions do not support constant or lowcardinality columns. Therefore, we materialize them and
80 /// keep a reference so they are alive until we finish using their nested columns (array data/offset)
81 VectorWithMemoryTracking<ColumnPtr> materialized_columns;
82
83 const size_t num_arguments_columns = arguments.size() - 1;
84
85 VectorWithMemoryTracking<const IColumn *> aggregate_arguments_vec(num_arguments_columns);
86 const ColumnArray::Offsets * offsets = nullptr;
87
88 for (size_t i = 0; i < num_arguments_columns; ++i)
89 {
90 const IColumn * col = arguments[i + 1].column.get();
91 auto col_no_lowcardinality = recursiveRemoveLowCardinality(arguments[i + 1].column);
92 if (col_no_lowcardinality != arguments[i + 1].column)
93 {
94 materialized_columns.emplace_back(col_no_lowcardinality);
95 col = col_no_lowcardinality.get();
96 }
97
98 const ColumnArray::Offsets * offsets_i = nullptr;
99 if (const ColumnArray * arr = checkAndGetColumn<ColumnArray>(col))
100 {
101 aggregate_arguments_vec[i] = &arr->getData();
102 offsets_i = &arr->getOffsets();
103 }
104 else if (const ColumnConst * const_arr = checkAndGetColumnConst<ColumnArray>(col))
105 {
106 materialized_columns.emplace_back(const_arr->convertToFullColumn());
107 const auto & materialized_arr = typeid_cast<const ColumnArray &>(*materialized_columns.back());
108 aggregate_arguments_vec[i] = &materialized_arr.getData();
109 offsets_i = &materialized_arr.getOffsets();
110 }
111 else
112 throw Exception(ErrorCodes::ILLEGAL_COLUMN, "Illegal column {} as argument of function {}", col->getName(), getName());
113
114 if (i == 0)
115 offsets = offsets_i;
116 else if (*offsets_i != *offsets)
117 throw Exception(ErrorCodes::SIZES_OF_ARRAYS_DONT_MATCH, "Lengths of all arrays passed to {} must be equal.",
118 getName());
119 }
120 const IColumn ** aggregate_arguments = aggregate_arguments_vec.data();
121
122 MutableColumnPtr result_holder = result_type->createColumn();
123 IColumn & res_col = *result_holder;
124
125 PODArray<AggregateDataPtr> places(input_rows_count);
126 for (size_t i = 0; i < input_rows_count; ++i)
127 {
128 places[i] = arena->alignedAlloc(agg_func.sizeOfData(), agg_func.alignOfData());
129 try
130 {
131 agg_func.create(places[i]);

Callers

nothing calls this directly

Calls 15

alignedAllocMethod · 0.80
addBatchArrayMethod · 0.80
ExceptionClass · 0.50
getNameFunction · 0.50
sizeMethod · 0.45
getMethod · 0.45
emplace_backMethod · 0.45
getDataMethod · 0.45
getOffsetsMethod · 0.45
convertToFullColumnMethod · 0.45
backMethod · 0.45

Tested by

no test coverage detected