mirror of
https://github.com/milvus-io/milvus.git
synced 2026-07-21 18:25:44 +00:00
related: #36380 <!-- This is an auto-generated comment: release notes by coderabbit.ai --> - Core invariant: aggregation is centralized and schema-aware — all aggregate functions are created via the exec Aggregate registry (milvus::exec::Aggregate) and validated by ValidateAggFieldType, use a single in-memory accumulator layout (Accumulator/RowContainer) and grouping primitives (GroupingSet, HashTable, VectorHasher), ensuring consistent typing, null semantics and offsets across planner → exec → reducer conversion paths (toAggregateInfo, Aggregate::create, GroupingSet, AggResult converters). - Removed / simplified logic: removed ad‑hoc count/group-by and reducer code (CountNode/PhyCountNode, GroupByNode/PhyGroupByNode, cntReducer and its tests) and consolidated into a unified AggregationNode → PhyAggregationNode + GroupingSet + HashTable execution path and centralized reducers (MilvusAggReducer, InternalAggReducer, SegcoreAggReducer). AVG now implemented compositionally (SUM + COUNT) rather than a bespoke operator, eliminating duplicate implementations. - Why this does NOT cause data loss or regressions: existing data-access and serialization paths are preserved and explicitly validated — bulk_subscript / bulk_script_field_data and FieldData creation are used for output materialization; converters (InternalResult2AggResult ↔ AggResult2internalResult, SegcoreResults2AggResult ↔ AggResult2segcoreResult) enforce shape/type/row-count validation; proxy and plan-level checks (MatchAggregationExpression, translateOutputFields, ValidateAggFieldType, translateGroupByFieldIds) reject unsupported inputs (ARRAY/JSON, unsupported datatypes) early. Empty-result generation and explicit error returns guard against silent corruption. - New capability and scope: end-to-end GROUP BY and aggregation support added across the stack — proto (plan.proto, RetrieveRequest fields group_by_field_ids/aggregates), planner nodes (AggregationNode, ProjectNode, SearchGroupByNode), exec operators (PhyAggregationNode, PhyProjectNode) and aggregation core (Aggregate implementations: Sum/Count/Min/Max, SimpleNumericAggregate, RowContainer, GroupingSet, HashTable) plus proxy/querynode reducers and tests — enabling grouped and global aggregation (sum, count, min, max, avg via sum+count) with schema-aware validation and reduction. <!-- end of auto-generated comment: release notes by coderabbit.ai --> Signed-off-by: MrPresent-Han <chun.han@gmail.com> Co-authored-by: MrPresent-Han <chun.han@gmail.com>
93 lines
2.5 KiB
C++
93 lines
2.5 KiB
C++
// Licensed to the LF AI & Data foundation under one
|
|
// or more contributor license agreements. See the NOTICE file
|
|
// distributed with this work for additional information
|
|
// regarding copyright ownership. The ASF licenses this file
|
|
// to you under the Apache License, Version 2.0 (the
|
|
// "License"); you may not use this file except in compliance
|
|
// with the License. You may obtain a copy of the License at
|
|
//
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
|
//
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
// See the License for the specific language governing permissions and
|
|
// limitations under the License.
|
|
|
|
#pragma once
|
|
|
|
#include "common/Vector.h"
|
|
#include "common/Types.h"
|
|
#include "expr/ITypeExpr.h"
|
|
|
|
namespace milvus {
|
|
namespace exec {
|
|
class VectorHasher {
|
|
public:
|
|
VectorHasher(DataType data_type, column_index_t column_idx)
|
|
: channel_type_(data_type), channel_idx_(column_idx) {
|
|
}
|
|
|
|
static std::unique_ptr<VectorHasher>
|
|
create(DataType data_type, column_index_t col_idx) {
|
|
return std::make_unique<VectorHasher>(data_type, col_idx);
|
|
}
|
|
|
|
column_index_t
|
|
ChannelIndex() const {
|
|
return channel_idx_;
|
|
}
|
|
|
|
DataType
|
|
ChannelDataType() const {
|
|
return channel_type_;
|
|
}
|
|
|
|
void
|
|
hash(bool mix, std::vector<uint64_t>& result);
|
|
|
|
static constexpr uint64_t kNullHash = 1;
|
|
|
|
static bool
|
|
typeSupportValueIds(DataType type) {
|
|
switch (type) {
|
|
case DataType::BOOL:
|
|
case DataType::INT8:
|
|
case DataType::INT16:
|
|
case DataType::INT32:
|
|
case DataType::INT64:
|
|
case DataType::VARCHAR:
|
|
case DataType::STRING:
|
|
return true;
|
|
default:
|
|
return false;
|
|
}
|
|
}
|
|
|
|
template <DataType type>
|
|
void
|
|
hashValues(const ColumnVectorPtr& column_data, bool mix, uint64_t* result);
|
|
|
|
void
|
|
setColumnData(const ColumnVectorPtr& column_data) {
|
|
column_data_ = column_data;
|
|
}
|
|
|
|
const ColumnVectorPtr&
|
|
columnData() const {
|
|
return column_data_;
|
|
}
|
|
|
|
private:
|
|
const column_index_t channel_idx_;
|
|
const DataType channel_type_;
|
|
ColumnVectorPtr column_data_;
|
|
};
|
|
|
|
std::vector<std::unique_ptr<VectorHasher>>
|
|
createVectorHashers(const RowTypePtr& rowType,
|
|
const std::vector<expr::FieldAccessTypeExprPtr>& exprs);
|
|
|
|
} // namespace exec
|
|
} // namespace milvus
|