You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@skywalking.apache.org by ha...@apache.org on 2022/02/28 12:04:52 UTC

[skywalking-banyandb] 01/01: Add groupBy to the measure query request

This is an automated email from the ASF dual-hosted git repository.

hanahmily pushed a commit to branch measure-groupby
in repository https://gitbox.apache.org/repos/asf/skywalking-banyandb.git

commit e2f9ff91b44b97e31bdf9c9395498c382ba76259
Author: Gao Hongtao <ha...@gmail.com>
AuthorDate: Mon Feb 28 12:00:43 2022 +0000

    Add groupBy to the measure query request
    
    Signed-off-by: Gao Hongtao <ha...@gmail.com>
---
 api/proto/banyandb/measure/v1/query.pb.go | 180 ++++++++++++++++++++++++------
 api/proto/banyandb/measure/v1/query.proto |  10 +-
 api/proto/banyandb/measure/v1/topn.pb.go  | 124 ++++++--------------
 api/proto/banyandb/measure/v1/topn.proto  |   7 +-
 api/proto/banyandb/model/v1/common.pb.go  | 127 ++++++++++++++++-----
 api/proto/banyandb/model/v1/common.proto  |   9 ++
 6 files changed, 298 insertions(+), 159 deletions(-)

diff --git a/api/proto/banyandb/measure/v1/query.pb.go b/api/proto/banyandb/measure/v1/query.pb.go
index 771faf7..249b72a 100644
--- a/api/proto/banyandb/measure/v1/query.pb.go
+++ b/api/proto/banyandb/measure/v1/query.pb.go
@@ -174,6 +174,10 @@ type QueryRequest struct {
 	TagProjection *v1.TagProjection `protobuf:"bytes,5,opt,name=tag_projection,json=tagProjection,proto3" json:"tag_projection,omitempty"`
 	// field_projection can be used to select fields of the data points in the response
 	FieldProjection *QueryRequest_FieldProjection `protobuf:"bytes,6,opt,name=field_projection,json=fieldProjection,proto3" json:"field_projection,omitempty"`
+	// group_by groups data points based on their field value for sepcific tags and this field'name
+	GroupBy *QueryRequest_GroupBy `protobuf:"bytes,7,opt,name=group_by,json=groupBy,proto3" json:"group_by,omitempty"`
+	// agg aggregates data points grouped by tags and a field's name
+	Agg v1.AggregationFunction `protobuf:"varint,8,opt,name=agg,proto3,enum=banyandb.model.v1.AggregationFunction" json:"agg,omitempty"`
 }
 
 func (x *QueryRequest) Reset() {
@@ -243,6 +247,20 @@ func (x *QueryRequest) GetFieldProjection() *QueryRequest_FieldProjection {
 	return nil
 }
 
+func (x *QueryRequest) GetGroupBy() *QueryRequest_GroupBy {
+	if x != nil {
+		return x.GroupBy
+	}
+	return nil
+}
+
+func (x *QueryRequest) GetAgg() v1.AggregationFunction {
+	if x != nil {
+		return x.Agg
+	}
+	return v1.AggregationFunction(0)
+}
+
 type DataPoint_Field struct {
 	state         protoimpl.MessageState
 	sizeCache     protoimpl.SizeCache
@@ -358,7 +376,7 @@ type QueryRequest_FieldProjection struct {
 	sizeCache     protoimpl.SizeCache
 	unknownFields protoimpl.UnknownFields
 
-	Name []string `protobuf:"bytes,1,rep,name=name,proto3" json:"name,omitempty"`
+	Names []string `protobuf:"bytes,1,rep,name=names,proto3" json:"names,omitempty"`
 }
 
 func (x *QueryRequest_FieldProjection) Reset() {
@@ -393,13 +411,68 @@ func (*QueryRequest_FieldProjection) Descriptor() ([]byte, []int) {
 	return file_banyandb_measure_v1_query_proto_rawDescGZIP(), []int{2, 1}
 }
 
-func (x *QueryRequest_FieldProjection) GetName() []string {
+func (x *QueryRequest_FieldProjection) GetNames() []string {
 	if x != nil {
-		return x.Name
+		return x.Names
 	}
 	return nil
 }
 
+type QueryRequest_GroupBy struct {
+	state         protoimpl.MessageState
+	sizeCache     protoimpl.SizeCache
+	unknownFields protoimpl.UnknownFields
+
+	TagProjection *v1.TagProjection `protobuf:"bytes,1,opt,name=tag_projection,json=tagProjection,proto3" json:"tag_projection,omitempty"`
+	FieldName     string            `protobuf:"bytes,2,opt,name=field_name,json=fieldName,proto3" json:"field_name,omitempty"`
+}
+
+func (x *QueryRequest_GroupBy) Reset() {
+	*x = QueryRequest_GroupBy{}
+	if protoimpl.UnsafeEnabled {
+		mi := &file_banyandb_measure_v1_query_proto_msgTypes[6]
+		ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
+		ms.StoreMessageInfo(mi)
+	}
+}
+
+func (x *QueryRequest_GroupBy) String() string {
+	return protoimpl.X.MessageStringOf(x)
+}
+
+func (*QueryRequest_GroupBy) ProtoMessage() {}
+
+func (x *QueryRequest_GroupBy) ProtoReflect() protoreflect.Message {
+	mi := &file_banyandb_measure_v1_query_proto_msgTypes[6]
+	if protoimpl.UnsafeEnabled && x != nil {
+		ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
+		if ms.LoadMessageInfo() == nil {
+			ms.StoreMessageInfo(mi)
+		}
+		return ms
+	}
+	return mi.MessageOf(x)
+}
+
+// Deprecated: Use QueryRequest_GroupBy.ProtoReflect.Descriptor instead.
+func (*QueryRequest_GroupBy) Descriptor() ([]byte, []int) {
+	return file_banyandb_measure_v1_query_proto_rawDescGZIP(), []int{2, 2}
+}
+
+func (x *QueryRequest_GroupBy) GetTagProjection() *v1.TagProjection {
+	if x != nil {
+		return x.TagProjection
+	}
+	return nil
+}
+
+func (x *QueryRequest_GroupBy) GetFieldName() string {
+	if x != nil {
+		return x.FieldName
+	}
+	return ""
+}
+
 var File_banyandb_measure_v1_query_proto protoreflect.FileDescriptor
 
 var file_banyandb_measure_v1_query_proto_rawDesc = []byte{
@@ -437,7 +510,7 @@ var file_banyandb_measure_v1_query_proto_rawDesc = []byte{
 	0x18, 0x01, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x1e, 0x2e, 0x62, 0x61, 0x6e, 0x79, 0x61, 0x6e, 0x64,
 	0x62, 0x2e, 0x6d, 0x65, 0x61, 0x73, 0x75, 0x72, 0x65, 0x2e, 0x76, 0x31, 0x2e, 0x44, 0x61, 0x74,
 	0x61, 0x50, 0x6f, 0x69, 0x6e, 0x74, 0x52, 0x0a, 0x64, 0x61, 0x74, 0x61, 0x50, 0x6f, 0x69, 0x6e,
-	0x74, 0x73, 0x22, 0x8d, 0x04, 0x0a, 0x0c, 0x51, 0x75, 0x65, 0x72, 0x79, 0x52, 0x65, 0x71, 0x75,
+	0x74, 0x73, 0x22, 0x82, 0x06, 0x0a, 0x0c, 0x51, 0x75, 0x65, 0x72, 0x79, 0x52, 0x65, 0x71, 0x75,
 	0x65, 0x73, 0x74, 0x12, 0x38, 0x0a, 0x08, 0x6d, 0x65, 0x74, 0x61, 0x64, 0x61, 0x74, 0x61, 0x18,
 	0x01, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x1c, 0x2e, 0x62, 0x61, 0x6e, 0x79, 0x61, 0x6e, 0x64, 0x62,
 	0x2e, 0x63, 0x6f, 0x6d, 0x6d, 0x6f, 0x6e, 0x2e, 0x76, 0x31, 0x2e, 0x4d, 0x65, 0x74, 0x61, 0x64,
@@ -460,24 +533,40 @@ var file_banyandb_measure_v1_query_proto_rawDesc = []byte{
 	0x2e, 0x6d, 0x65, 0x61, 0x73, 0x75, 0x72, 0x65, 0x2e, 0x76, 0x31, 0x2e, 0x51, 0x75, 0x65, 0x72,
 	0x79, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x2e, 0x46, 0x69, 0x65, 0x6c, 0x64, 0x50, 0x72,
 	0x6f, 0x6a, 0x65, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x52, 0x0f, 0x66, 0x69, 0x65, 0x6c, 0x64, 0x50,
-	0x72, 0x6f, 0x6a, 0x65, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x1a, 0x70, 0x0a, 0x08, 0x43, 0x72, 0x69,
+	0x72, 0x6f, 0x6a, 0x65, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x12, 0x44, 0x0a, 0x08, 0x67, 0x72, 0x6f,
+	0x75, 0x70, 0x5f, 0x62, 0x79, 0x18, 0x07, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x29, 0x2e, 0x62, 0x61,
+	0x6e, 0x79, 0x61, 0x6e, 0x64, 0x62, 0x2e, 0x6d, 0x65, 0x61, 0x73, 0x75, 0x72, 0x65, 0x2e, 0x76,
+	0x31, 0x2e, 0x51, 0x75, 0x65, 0x72, 0x79, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x2e, 0x47,
+	0x72, 0x6f, 0x75, 0x70, 0x42, 0x79, 0x52, 0x07, 0x67, 0x72, 0x6f, 0x75, 0x70, 0x42, 0x79, 0x12,
+	0x38, 0x0a, 0x03, 0x61, 0x67, 0x67, 0x18, 0x08, 0x20, 0x01, 0x28, 0x0e, 0x32, 0x26, 0x2e, 0x62,
+	0x61, 0x6e, 0x79, 0x61, 0x6e, 0x64, 0x62, 0x2e, 0x6d, 0x6f, 0x64, 0x65, 0x6c, 0x2e, 0x76, 0x31,
+	0x2e, 0x41, 0x67, 0x67, 0x72, 0x65, 0x67, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x46, 0x75, 0x6e, 0x63,
+	0x74, 0x69, 0x6f, 0x6e, 0x52, 0x03, 0x61, 0x67, 0x67, 0x1a, 0x70, 0x0a, 0x08, 0x43, 0x72, 0x69,
 	0x74, 0x65, 0x72, 0x69, 0x61, 0x12, 0x26, 0x0a, 0x0f, 0x74, 0x61, 0x67, 0x5f, 0x66, 0x61, 0x6d,
 	0x69, 0x6c, 0x79, 0x5f, 0x6e, 0x61, 0x6d, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0d,
 	0x74, 0x61, 0x67, 0x46, 0x61, 0x6d, 0x69, 0x6c, 0x79, 0x4e, 0x61, 0x6d, 0x65, 0x12, 0x3c, 0x0a,
 	0x0a, 0x63, 0x6f, 0x6e, 0x64, 0x69, 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x18, 0x02, 0x20, 0x03, 0x28,
 	0x0b, 0x32, 0x1c, 0x2e, 0x62, 0x61, 0x6e, 0x79, 0x61, 0x6e, 0x64, 0x62, 0x2e, 0x6d, 0x6f, 0x64,
 	0x65, 0x6c, 0x2e, 0x76, 0x31, 0x2e, 0x43, 0x6f, 0x6e, 0x64, 0x69, 0x74, 0x69, 0x6f, 0x6e, 0x52,
-	0x0a, 0x63, 0x6f, 0x6e, 0x64, 0x69, 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x1a, 0x25, 0x0a, 0x0f, 0x46,
-	0x69, 0x65, 0x6c, 0x64, 0x50, 0x72, 0x6f, 0x6a, 0x65, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x12, 0x12,
-	0x0a, 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x18, 0x01, 0x20, 0x03, 0x28, 0x09, 0x52, 0x04, 0x6e, 0x61,
-	0x6d, 0x65, 0x42, 0x70, 0x0a, 0x29, 0x6f, 0x72, 0x67, 0x2e, 0x61, 0x70, 0x61, 0x63, 0x68, 0x65,
-	0x2e, 0x73, 0x6b, 0x79, 0x77, 0x61, 0x6c, 0x6b, 0x69, 0x6e, 0x67, 0x2e, 0x62, 0x61, 0x6e, 0x79,
-	0x61, 0x6e, 0x64, 0x62, 0x2e, 0x6d, 0x65, 0x61, 0x73, 0x75, 0x72, 0x65, 0x2e, 0x76, 0x31, 0x5a,
-	0x43, 0x67, 0x69, 0x74, 0x68, 0x75, 0x62, 0x2e, 0x63, 0x6f, 0x6d, 0x2f, 0x61, 0x70, 0x61, 0x63,
-	0x68, 0x65, 0x2f, 0x73, 0x6b, 0x79, 0x77, 0x61, 0x6c, 0x6b, 0x69, 0x6e, 0x67, 0x2d, 0x62, 0x61,
-	0x6e, 0x79, 0x61, 0x6e, 0x64, 0x62, 0x2f, 0x61, 0x70, 0x69, 0x2f, 0x70, 0x72, 0x6f, 0x74, 0x6f,
-	0x2f, 0x62, 0x61, 0x6e, 0x79, 0x61, 0x6e, 0x64, 0x62, 0x2f, 0x6d, 0x65, 0x61, 0x73, 0x75, 0x72,
-	0x65, 0x2f, 0x76, 0x31, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33,
+	0x0a, 0x63, 0x6f, 0x6e, 0x64, 0x69, 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x1a, 0x27, 0x0a, 0x0f, 0x46,
+	0x69, 0x65, 0x6c, 0x64, 0x50, 0x72, 0x6f, 0x6a, 0x65, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x12, 0x14,
+	0x0a, 0x05, 0x6e, 0x61, 0x6d, 0x65, 0x73, 0x18, 0x01, 0x20, 0x03, 0x28, 0x09, 0x52, 0x05, 0x6e,
+	0x61, 0x6d, 0x65, 0x73, 0x1a, 0x71, 0x0a, 0x07, 0x47, 0x72, 0x6f, 0x75, 0x70, 0x42, 0x79, 0x12,
+	0x47, 0x0a, 0x0e, 0x74, 0x61, 0x67, 0x5f, 0x70, 0x72, 0x6f, 0x6a, 0x65, 0x63, 0x74, 0x69, 0x6f,
+	0x6e, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x20, 0x2e, 0x62, 0x61, 0x6e, 0x79, 0x61, 0x6e,
+	0x64, 0x62, 0x2e, 0x6d, 0x6f, 0x64, 0x65, 0x6c, 0x2e, 0x76, 0x31, 0x2e, 0x54, 0x61, 0x67, 0x50,
+	0x72, 0x6f, 0x6a, 0x65, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x52, 0x0d, 0x74, 0x61, 0x67, 0x50, 0x72,
+	0x6f, 0x6a, 0x65, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x12, 0x1d, 0x0a, 0x0a, 0x66, 0x69, 0x65, 0x6c,
+	0x64, 0x5f, 0x6e, 0x61, 0x6d, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x09, 0x66, 0x69,
+	0x65, 0x6c, 0x64, 0x4e, 0x61, 0x6d, 0x65, 0x42, 0x70, 0x0a, 0x29, 0x6f, 0x72, 0x67, 0x2e, 0x61,
+	0x70, 0x61, 0x63, 0x68, 0x65, 0x2e, 0x73, 0x6b, 0x79, 0x77, 0x61, 0x6c, 0x6b, 0x69, 0x6e, 0x67,
+	0x2e, 0x62, 0x61, 0x6e, 0x79, 0x61, 0x6e, 0x64, 0x62, 0x2e, 0x6d, 0x65, 0x61, 0x73, 0x75, 0x72,
+	0x65, 0x2e, 0x76, 0x31, 0x5a, 0x43, 0x67, 0x69, 0x74, 0x68, 0x75, 0x62, 0x2e, 0x63, 0x6f, 0x6d,
+	0x2f, 0x61, 0x70, 0x61, 0x63, 0x68, 0x65, 0x2f, 0x73, 0x6b, 0x79, 0x77, 0x61, 0x6c, 0x6b, 0x69,
+	0x6e, 0x67, 0x2d, 0x62, 0x61, 0x6e, 0x79, 0x61, 0x6e, 0x64, 0x62, 0x2f, 0x61, 0x70, 0x69, 0x2f,
+	0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2f, 0x62, 0x61, 0x6e, 0x79, 0x61, 0x6e, 0x64, 0x62, 0x2f, 0x6d,
+	0x65, 0x61, 0x73, 0x75, 0x72, 0x65, 0x2f, 0x76, 0x31, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f,
+	0x33,
 }
 
 var (
@@ -492,7 +581,7 @@ func file_banyandb_measure_v1_query_proto_rawDescGZIP() []byte {
 	return file_banyandb_measure_v1_query_proto_rawDescData
 }
 
-var file_banyandb_measure_v1_query_proto_msgTypes = make([]protoimpl.MessageInfo, 6)
+var file_banyandb_measure_v1_query_proto_msgTypes = make([]protoimpl.MessageInfo, 7)
 var file_banyandb_measure_v1_query_proto_goTypes = []interface{}{
 	(*DataPoint)(nil),                    // 0: banyandb.measure.v1.DataPoint
 	(*QueryResponse)(nil),                // 1: banyandb.measure.v1.QueryResponse
@@ -500,31 +589,36 @@ var file_banyandb_measure_v1_query_proto_goTypes = []interface{}{
 	(*DataPoint_Field)(nil),              // 3: banyandb.measure.v1.DataPoint.Field
 	(*QueryRequest_Criteria)(nil),        // 4: banyandb.measure.v1.QueryRequest.Criteria
 	(*QueryRequest_FieldProjection)(nil), // 5: banyandb.measure.v1.QueryRequest.FieldProjection
-	(*timestamppb.Timestamp)(nil),        // 6: google.protobuf.Timestamp
-	(*v1.TagFamily)(nil),                 // 7: banyandb.model.v1.TagFamily
-	(*v11.Metadata)(nil),                 // 8: banyandb.common.v1.Metadata
-	(*v1.TimeRange)(nil),                 // 9: banyandb.model.v1.TimeRange
-	(*v1.TagProjection)(nil),             // 10: banyandb.model.v1.TagProjection
-	(*v1.FieldValue)(nil),                // 11: banyandb.model.v1.FieldValue
-	(*v1.Condition)(nil),                 // 12: banyandb.model.v1.Condition
+	(*QueryRequest_GroupBy)(nil),         // 6: banyandb.measure.v1.QueryRequest.GroupBy
+	(*timestamppb.Timestamp)(nil),        // 7: google.protobuf.Timestamp
+	(*v1.TagFamily)(nil),                 // 8: banyandb.model.v1.TagFamily
+	(*v11.Metadata)(nil),                 // 9: banyandb.common.v1.Metadata
+	(*v1.TimeRange)(nil),                 // 10: banyandb.model.v1.TimeRange
+	(*v1.TagProjection)(nil),             // 11: banyandb.model.v1.TagProjection
+	(v1.AggregationFunction)(0),          // 12: banyandb.model.v1.AggregationFunction
+	(*v1.FieldValue)(nil),                // 13: banyandb.model.v1.FieldValue
+	(*v1.Condition)(nil),                 // 14: banyandb.model.v1.Condition
 }
 var file_banyandb_measure_v1_query_proto_depIdxs = []int32{
-	6,  // 0: banyandb.measure.v1.DataPoint.timestamp:type_name -> google.protobuf.Timestamp
-	7,  // 1: banyandb.measure.v1.DataPoint.tag_families:type_name -> banyandb.model.v1.TagFamily
+	7,  // 0: banyandb.measure.v1.DataPoint.timestamp:type_name -> google.protobuf.Timestamp
+	8,  // 1: banyandb.measure.v1.DataPoint.tag_families:type_name -> banyandb.model.v1.TagFamily
 	3,  // 2: banyandb.measure.v1.DataPoint.fields:type_name -> banyandb.measure.v1.DataPoint.Field
 	0,  // 3: banyandb.measure.v1.QueryResponse.data_points:type_name -> banyandb.measure.v1.DataPoint
-	8,  // 4: banyandb.measure.v1.QueryRequest.metadata:type_name -> banyandb.common.v1.Metadata
-	9,  // 5: banyandb.measure.v1.QueryRequest.time_range:type_name -> banyandb.model.v1.TimeRange
+	9,  // 4: banyandb.measure.v1.QueryRequest.metadata:type_name -> banyandb.common.v1.Metadata
+	10, // 5: banyandb.measure.v1.QueryRequest.time_range:type_name -> banyandb.model.v1.TimeRange
 	4,  // 6: banyandb.measure.v1.QueryRequest.criteria:type_name -> banyandb.measure.v1.QueryRequest.Criteria
-	10, // 7: banyandb.measure.v1.QueryRequest.tag_projection:type_name -> banyandb.model.v1.TagProjection
+	11, // 7: banyandb.measure.v1.QueryRequest.tag_projection:type_name -> banyandb.model.v1.TagProjection
 	5,  // 8: banyandb.measure.v1.QueryRequest.field_projection:type_name -> banyandb.measure.v1.QueryRequest.FieldProjection
-	11, // 9: banyandb.measure.v1.DataPoint.Field.value:type_name -> banyandb.model.v1.FieldValue
-	12, // 10: banyandb.measure.v1.QueryRequest.Criteria.conditions:type_name -> banyandb.model.v1.Condition
-	11, // [11:11] is the sub-list for method output_type
-	11, // [11:11] is the sub-list for method input_type
-	11, // [11:11] is the sub-list for extension type_name
-	11, // [11:11] is the sub-list for extension extendee
-	0,  // [0:11] is the sub-list for field type_name
+	6,  // 9: banyandb.measure.v1.QueryRequest.group_by:type_name -> banyandb.measure.v1.QueryRequest.GroupBy
+	12, // 10: banyandb.measure.v1.QueryRequest.agg:type_name -> banyandb.model.v1.AggregationFunction
+	13, // 11: banyandb.measure.v1.DataPoint.Field.value:type_name -> banyandb.model.v1.FieldValue
+	14, // 12: banyandb.measure.v1.QueryRequest.Criteria.conditions:type_name -> banyandb.model.v1.Condition
+	11, // 13: banyandb.measure.v1.QueryRequest.GroupBy.tag_projection:type_name -> banyandb.model.v1.TagProjection
+	14, // [14:14] is the sub-list for method output_type
+	14, // [14:14] is the sub-list for method input_type
+	14, // [14:14] is the sub-list for extension type_name
+	14, // [14:14] is the sub-list for extension extendee
+	0,  // [0:14] is the sub-list for field type_name
 }
 
 func init() { file_banyandb_measure_v1_query_proto_init() }
@@ -605,6 +699,18 @@ func file_banyandb_measure_v1_query_proto_init() {
 				return nil
 			}
 		}
+		file_banyandb_measure_v1_query_proto_msgTypes[6].Exporter = func(v interface{}, i int) interface{} {
+			switch v := v.(*QueryRequest_GroupBy); i {
+			case 0:
+				return &v.state
+			case 1:
+				return &v.sizeCache
+			case 2:
+				return &v.unknownFields
+			default:
+				return nil
+			}
+		}
 	}
 	type x struct{}
 	out := protoimpl.TypeBuilder{
@@ -612,7 +718,7 @@ func file_banyandb_measure_v1_query_proto_init() {
 			GoPackagePath: reflect.TypeOf(x{}).PkgPath(),
 			RawDescriptor: file_banyandb_measure_v1_query_proto_rawDesc,
 			NumEnums:      0,
-			NumMessages:   6,
+			NumMessages:   7,
 			NumExtensions: 0,
 			NumServices:   0,
 		},
diff --git a/api/proto/banyandb/measure/v1/query.proto b/api/proto/banyandb/measure/v1/query.proto
index 1f0063c..aab284c 100644
--- a/api/proto/banyandb/measure/v1/query.proto
+++ b/api/proto/banyandb/measure/v1/query.proto
@@ -62,8 +62,16 @@ message QueryRequest {
   // tag_projection can be used to select tags of the data points in the response
   model.v1.TagProjection tag_projection = 5;
   message FieldProjection {
-    repeated string name = 1;
+    repeated string names = 1;
   }
   // field_projection can be used to select fields of the data points in the response
   FieldProjection field_projection = 6;
+  message GroupBy {
+    model.v1.TagProjection tag_projection = 1;
+    string field_name = 2;
+  }
+  // group_by groups data points based on their field value for sepcific tags and this field'name
+  GroupBy group_by = 7;
+  // agg aggregates data points grouped by tags and a field's name
+  model.v1.AggregationFunction agg = 8;
 }
diff --git a/api/proto/banyandb/measure/v1/topn.pb.go b/api/proto/banyandb/measure/v1/topn.pb.go
index 4499fa7..49d4af1 100644
--- a/api/proto/banyandb/measure/v1/topn.pb.go
+++ b/api/proto/banyandb/measure/v1/topn.pb.go
@@ -42,52 +42,6 @@ const (
 	_ = protoimpl.EnforceVersion(protoimpl.MaxVersion - 20)
 )
 
-type AggregationFunction int32
-
-const (
-	AggregationFunction_AGGREGATION_FUNCTION_UNSPECIFIED AggregationFunction = 0
-	AggregationFunction_AGGREGATION_FUNCTION_MEAN        AggregationFunction = 1
-)
-
-// Enum value maps for AggregationFunction.
-var (
-	AggregationFunction_name = map[int32]string{
-		0: "AGGREGATION_FUNCTION_UNSPECIFIED",
-		1: "AGGREGATION_FUNCTION_MEAN",
-	}
-	AggregationFunction_value = map[string]int32{
-		"AGGREGATION_FUNCTION_UNSPECIFIED": 0,
-		"AGGREGATION_FUNCTION_MEAN":        1,
-	}
-)
-
-func (x AggregationFunction) Enum() *AggregationFunction {
-	p := new(AggregationFunction)
-	*p = x
-	return p
-}
-
-func (x AggregationFunction) String() string {
-	return protoimpl.X.EnumStringOf(x.Descriptor(), protoreflect.EnumNumber(x))
-}
-
-func (AggregationFunction) Descriptor() protoreflect.EnumDescriptor {
-	return file_banyandb_measure_v1_topn_proto_enumTypes[0].Descriptor()
-}
-
-func (AggregationFunction) Type() protoreflect.EnumType {
-	return &file_banyandb_measure_v1_topn_proto_enumTypes[0]
-}
-
-func (x AggregationFunction) Number() protoreflect.EnumNumber {
-	return protoreflect.EnumNumber(x)
-}
-
-// Deprecated: Use AggregationFunction.Descriptor instead.
-func (AggregationFunction) EnumDescriptor() ([]byte, []int) {
-	return file_banyandb_measure_v1_topn_proto_rawDescGZIP(), []int{0}
-}
-
 //TopNList contains a series of topN items
 type TopNList struct {
 	state         protoimpl.MessageState
@@ -209,7 +163,7 @@ type TopNRequest struct {
 	// top_n set the how many items should be returned in each list.
 	TopN int32 `protobuf:"varint,3,opt,name=top_n,json=topN,proto3" json:"top_n,omitempty"`
 	// agg aggregates lists grouped by field names in the time_range
-	Agg AggregationFunction `protobuf:"varint,4,opt,name=agg,proto3,enum=banyandb.measure.v1.AggregationFunction" json:"agg,omitempty"`
+	Agg v11.AggregationFunction `protobuf:"varint,4,opt,name=agg,proto3,enum=banyandb.model.v1.AggregationFunction" json:"agg,omitempty"`
 	// criteria select counters.
 	Conditions []*v11.Condition `protobuf:"bytes,5,rep,name=conditions,proto3" json:"conditions,omitempty"`
 }
@@ -267,11 +221,11 @@ func (x *TopNRequest) GetTopN() int32 {
 	return 0
 }
 
-func (x *TopNRequest) GetAgg() AggregationFunction {
+func (x *TopNRequest) GetAgg() v11.AggregationFunction {
 	if x != nil {
 		return x.Agg
 	}
-	return AggregationFunction_AGGREGATION_FUNCTION_UNSPECIFIED
+	return v11.AggregationFunction(0)
 }
 
 func (x *TopNRequest) GetConditions() []*v11.Condition {
@@ -367,7 +321,7 @@ var file_banyandb_measure_v1_topn_proto_rawDesc = []byte{
 	0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x33, 0x0a, 0x05, 0x6c, 0x69, 0x73, 0x74,
 	0x73, 0x18, 0x01, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x1d, 0x2e, 0x62, 0x61, 0x6e, 0x79, 0x61, 0x6e,
 	0x64, 0x62, 0x2e, 0x6d, 0x65, 0x61, 0x73, 0x75, 0x72, 0x65, 0x2e, 0x76, 0x31, 0x2e, 0x54, 0x6f,
-	0x70, 0x4e, 0x4c, 0x69, 0x73, 0x74, 0x52, 0x05, 0x6c, 0x69, 0x73, 0x74, 0x73, 0x22, 0x93, 0x02,
+	0x70, 0x4e, 0x4c, 0x69, 0x73, 0x74, 0x52, 0x05, 0x6c, 0x69, 0x73, 0x74, 0x73, 0x22, 0x91, 0x02,
 	0x0a, 0x0b, 0x54, 0x6f, 0x70, 0x4e, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x38, 0x0a,
 	0x08, 0x6d, 0x65, 0x74, 0x61, 0x64, 0x61, 0x74, 0x61, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0b, 0x32,
 	0x1c, 0x2e, 0x62, 0x61, 0x6e, 0x79, 0x61, 0x6e, 0x64, 0x62, 0x2e, 0x63, 0x6f, 0x6d, 0x6d, 0x6f,
@@ -377,28 +331,22 @@ var file_banyandb_measure_v1_topn_proto_rawDesc = []byte{
 	0x6e, 0x79, 0x61, 0x6e, 0x64, 0x62, 0x2e, 0x6d, 0x6f, 0x64, 0x65, 0x6c, 0x2e, 0x76, 0x31, 0x2e,
 	0x54, 0x69, 0x6d, 0x65, 0x52, 0x61, 0x6e, 0x67, 0x65, 0x52, 0x09, 0x74, 0x69, 0x6d, 0x65, 0x52,
 	0x61, 0x6e, 0x67, 0x65, 0x12, 0x13, 0x0a, 0x05, 0x74, 0x6f, 0x70, 0x5f, 0x6e, 0x18, 0x03, 0x20,
-	0x01, 0x28, 0x05, 0x52, 0x04, 0x74, 0x6f, 0x70, 0x4e, 0x12, 0x3a, 0x0a, 0x03, 0x61, 0x67, 0x67,
-	0x18, 0x04, 0x20, 0x01, 0x28, 0x0e, 0x32, 0x28, 0x2e, 0x62, 0x61, 0x6e, 0x79, 0x61, 0x6e, 0x64,
-	0x62, 0x2e, 0x6d, 0x65, 0x61, 0x73, 0x75, 0x72, 0x65, 0x2e, 0x76, 0x31, 0x2e, 0x41, 0x67, 0x67,
-	0x72, 0x65, 0x67, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x46, 0x75, 0x6e, 0x63, 0x74, 0x69, 0x6f, 0x6e,
-	0x52, 0x03, 0x61, 0x67, 0x67, 0x12, 0x3c, 0x0a, 0x0a, 0x63, 0x6f, 0x6e, 0x64, 0x69, 0x74, 0x69,
-	0x6f, 0x6e, 0x73, 0x18, 0x05, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x1c, 0x2e, 0x62, 0x61, 0x6e, 0x79,
-	0x61, 0x6e, 0x64, 0x62, 0x2e, 0x6d, 0x6f, 0x64, 0x65, 0x6c, 0x2e, 0x76, 0x31, 0x2e, 0x43, 0x6f,
-	0x6e, 0x64, 0x69, 0x74, 0x69, 0x6f, 0x6e, 0x52, 0x0a, 0x63, 0x6f, 0x6e, 0x64, 0x69, 0x74, 0x69,
-	0x6f, 0x6e, 0x73, 0x2a, 0x5a, 0x0a, 0x13, 0x41, 0x67, 0x67, 0x72, 0x65, 0x67, 0x61, 0x74, 0x69,
-	0x6f, 0x6e, 0x46, 0x75, 0x6e, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x12, 0x24, 0x0a, 0x20, 0x41, 0x47,
-	0x47, 0x52, 0x45, 0x47, 0x41, 0x54, 0x49, 0x4f, 0x4e, 0x5f, 0x46, 0x55, 0x4e, 0x43, 0x54, 0x49,
-	0x4f, 0x4e, 0x5f, 0x55, 0x4e, 0x53, 0x50, 0x45, 0x43, 0x49, 0x46, 0x49, 0x45, 0x44, 0x10, 0x00,
-	0x12, 0x1d, 0x0a, 0x19, 0x41, 0x47, 0x47, 0x52, 0x45, 0x47, 0x41, 0x54, 0x49, 0x4f, 0x4e, 0x5f,
-	0x46, 0x55, 0x4e, 0x43, 0x54, 0x49, 0x4f, 0x4e, 0x5f, 0x4d, 0x45, 0x41, 0x4e, 0x10, 0x01, 0x42,
-	0x70, 0x0a, 0x29, 0x6f, 0x72, 0x67, 0x2e, 0x61, 0x70, 0x61, 0x63, 0x68, 0x65, 0x2e, 0x73, 0x6b,
-	0x79, 0x77, 0x61, 0x6c, 0x6b, 0x69, 0x6e, 0x67, 0x2e, 0x62, 0x61, 0x6e, 0x79, 0x61, 0x6e, 0x64,
-	0x62, 0x2e, 0x6d, 0x65, 0x61, 0x73, 0x75, 0x72, 0x65, 0x2e, 0x76, 0x31, 0x5a, 0x43, 0x67, 0x69,
-	0x74, 0x68, 0x75, 0x62, 0x2e, 0x63, 0x6f, 0x6d, 0x2f, 0x61, 0x70, 0x61, 0x63, 0x68, 0x65, 0x2f,
-	0x73, 0x6b, 0x79, 0x77, 0x61, 0x6c, 0x6b, 0x69, 0x6e, 0x67, 0x2d, 0x62, 0x61, 0x6e, 0x79, 0x61,
-	0x6e, 0x64, 0x62, 0x2f, 0x61, 0x70, 0x69, 0x2f, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2f, 0x62, 0x61,
-	0x6e, 0x79, 0x61, 0x6e, 0x64, 0x62, 0x2f, 0x6d, 0x65, 0x61, 0x73, 0x75, 0x72, 0x65, 0x2f, 0x76,
-	0x31, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33,
+	0x01, 0x28, 0x05, 0x52, 0x04, 0x74, 0x6f, 0x70, 0x4e, 0x12, 0x38, 0x0a, 0x03, 0x61, 0x67, 0x67,
+	0x18, 0x04, 0x20, 0x01, 0x28, 0x0e, 0x32, 0x26, 0x2e, 0x62, 0x61, 0x6e, 0x79, 0x61, 0x6e, 0x64,
+	0x62, 0x2e, 0x6d, 0x6f, 0x64, 0x65, 0x6c, 0x2e, 0x76, 0x31, 0x2e, 0x41, 0x67, 0x67, 0x72, 0x65,
+	0x67, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x46, 0x75, 0x6e, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x52, 0x03,
+	0x61, 0x67, 0x67, 0x12, 0x3c, 0x0a, 0x0a, 0x63, 0x6f, 0x6e, 0x64, 0x69, 0x74, 0x69, 0x6f, 0x6e,
+	0x73, 0x18, 0x05, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x1c, 0x2e, 0x62, 0x61, 0x6e, 0x79, 0x61, 0x6e,
+	0x64, 0x62, 0x2e, 0x6d, 0x6f, 0x64, 0x65, 0x6c, 0x2e, 0x76, 0x31, 0x2e, 0x43, 0x6f, 0x6e, 0x64,
+	0x69, 0x74, 0x69, 0x6f, 0x6e, 0x52, 0x0a, 0x63, 0x6f, 0x6e, 0x64, 0x69, 0x74, 0x69, 0x6f, 0x6e,
+	0x73, 0x42, 0x70, 0x0a, 0x29, 0x6f, 0x72, 0x67, 0x2e, 0x61, 0x70, 0x61, 0x63, 0x68, 0x65, 0x2e,
+	0x73, 0x6b, 0x79, 0x77, 0x61, 0x6c, 0x6b, 0x69, 0x6e, 0x67, 0x2e, 0x62, 0x61, 0x6e, 0x79, 0x61,
+	0x6e, 0x64, 0x62, 0x2e, 0x6d, 0x65, 0x61, 0x73, 0x75, 0x72, 0x65, 0x2e, 0x76, 0x31, 0x5a, 0x43,
+	0x67, 0x69, 0x74, 0x68, 0x75, 0x62, 0x2e, 0x63, 0x6f, 0x6d, 0x2f, 0x61, 0x70, 0x61, 0x63, 0x68,
+	0x65, 0x2f, 0x73, 0x6b, 0x79, 0x77, 0x61, 0x6c, 0x6b, 0x69, 0x6e, 0x67, 0x2d, 0x62, 0x61, 0x6e,
+	0x79, 0x61, 0x6e, 0x64, 0x62, 0x2f, 0x61, 0x70, 0x69, 0x2f, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2f,
+	0x62, 0x61, 0x6e, 0x79, 0x61, 0x6e, 0x64, 0x62, 0x2f, 0x6d, 0x65, 0x61, 0x73, 0x75, 0x72, 0x65,
+	0x2f, 0x76, 0x31, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33,
 }
 
 var (
@@ -413,27 +361,26 @@ func file_banyandb_measure_v1_topn_proto_rawDescGZIP() []byte {
 	return file_banyandb_measure_v1_topn_proto_rawDescData
 }
 
-var file_banyandb_measure_v1_topn_proto_enumTypes = make([]protoimpl.EnumInfo, 1)
 var file_banyandb_measure_v1_topn_proto_msgTypes = make([]protoimpl.MessageInfo, 4)
 var file_banyandb_measure_v1_topn_proto_goTypes = []interface{}{
-	(AggregationFunction)(0),      // 0: banyandb.measure.v1.AggregationFunction
-	(*TopNList)(nil),              // 1: banyandb.measure.v1.TopNList
-	(*TopNResponse)(nil),          // 2: banyandb.measure.v1.TopNResponse
-	(*TopNRequest)(nil),           // 3: banyandb.measure.v1.TopNRequest
-	(*TopNList_Item)(nil),         // 4: banyandb.measure.v1.TopNList.Item
-	(*timestamppb.Timestamp)(nil), // 5: google.protobuf.Timestamp
-	(*v1.Metadata)(nil),           // 6: banyandb.common.v1.Metadata
-	(*v11.TimeRange)(nil),         // 7: banyandb.model.v1.TimeRange
+	(*TopNList)(nil),              // 0: banyandb.measure.v1.TopNList
+	(*TopNResponse)(nil),          // 1: banyandb.measure.v1.TopNResponse
+	(*TopNRequest)(nil),           // 2: banyandb.measure.v1.TopNRequest
+	(*TopNList_Item)(nil),         // 3: banyandb.measure.v1.TopNList.Item
+	(*timestamppb.Timestamp)(nil), // 4: google.protobuf.Timestamp
+	(*v1.Metadata)(nil),           // 5: banyandb.common.v1.Metadata
+	(*v11.TimeRange)(nil),         // 6: banyandb.model.v1.TimeRange
+	(v11.AggregationFunction)(0),  // 7: banyandb.model.v1.AggregationFunction
 	(*v11.Condition)(nil),         // 8: banyandb.model.v1.Condition
 	(*v11.FieldValue)(nil),        // 9: banyandb.model.v1.FieldValue
 }
 var file_banyandb_measure_v1_topn_proto_depIdxs = []int32{
-	5, // 0: banyandb.measure.v1.TopNList.timestamp:type_name -> google.protobuf.Timestamp
-	4, // 1: banyandb.measure.v1.TopNList.items:type_name -> banyandb.measure.v1.TopNList.Item
-	1, // 2: banyandb.measure.v1.TopNResponse.lists:type_name -> banyandb.measure.v1.TopNList
-	6, // 3: banyandb.measure.v1.TopNRequest.metadata:type_name -> banyandb.common.v1.Metadata
-	7, // 4: banyandb.measure.v1.TopNRequest.time_range:type_name -> banyandb.model.v1.TimeRange
-	0, // 5: banyandb.measure.v1.TopNRequest.agg:type_name -> banyandb.measure.v1.AggregationFunction
+	4, // 0: banyandb.measure.v1.TopNList.timestamp:type_name -> google.protobuf.Timestamp
+	3, // 1: banyandb.measure.v1.TopNList.items:type_name -> banyandb.measure.v1.TopNList.Item
+	0, // 2: banyandb.measure.v1.TopNResponse.lists:type_name -> banyandb.measure.v1.TopNList
+	5, // 3: banyandb.measure.v1.TopNRequest.metadata:type_name -> banyandb.common.v1.Metadata
+	6, // 4: banyandb.measure.v1.TopNRequest.time_range:type_name -> banyandb.model.v1.TimeRange
+	7, // 5: banyandb.measure.v1.TopNRequest.agg:type_name -> banyandb.model.v1.AggregationFunction
 	8, // 6: banyandb.measure.v1.TopNRequest.conditions:type_name -> banyandb.model.v1.Condition
 	9, // 7: banyandb.measure.v1.TopNList.Item.value:type_name -> banyandb.model.v1.FieldValue
 	8, // [8:8] is the sub-list for method output_type
@@ -503,14 +450,13 @@ func file_banyandb_measure_v1_topn_proto_init() {
 		File: protoimpl.DescBuilder{
 			GoPackagePath: reflect.TypeOf(x{}).PkgPath(),
 			RawDescriptor: file_banyandb_measure_v1_topn_proto_rawDesc,
-			NumEnums:      1,
+			NumEnums:      0,
 			NumMessages:   4,
 			NumExtensions: 0,
 			NumServices:   0,
 		},
 		GoTypes:           file_banyandb_measure_v1_topn_proto_goTypes,
 		DependencyIndexes: file_banyandb_measure_v1_topn_proto_depIdxs,
-		EnumInfos:         file_banyandb_measure_v1_topn_proto_enumTypes,
 		MessageInfos:      file_banyandb_measure_v1_topn_proto_msgTypes,
 	}.Build()
 	File_banyandb_measure_v1_topn_proto = out.File
diff --git a/api/proto/banyandb/measure/v1/topn.proto b/api/proto/banyandb/measure/v1/topn.proto
index bde07b6..b6f6f23 100644
--- a/api/proto/banyandb/measure/v1/topn.proto
+++ b/api/proto/banyandb/measure/v1/topn.proto
@@ -46,11 +46,6 @@ message TopNResponse {
     repeated TopNList lists = 1;
 }
 
-enum AggregationFunction {
-    AGGREGATION_FUNCTION_UNSPECIFIED = 0;
-    AGGREGATION_FUNCTION_MEAN = 1;
-}
-
 // TopNRequest is the request contract for query.
 message TopNRequest {
     // metadata is required
@@ -60,7 +55,7 @@ message TopNRequest {
     // top_n set the how many items should be returned in each list.
     int32 top_n = 3;
     // agg aggregates lists grouped by field names in the time_range
-    AggregationFunction agg = 4;
+    model.v1.AggregationFunction agg = 4;
     // criteria select counters.
     repeated model.v1.Condition conditions = 5;
 }
diff --git a/api/proto/banyandb/model/v1/common.pb.go b/api/proto/banyandb/model/v1/common.pb.go
index c282fdb..903563f 100644
--- a/api/proto/banyandb/model/v1/common.pb.go
+++ b/api/proto/banyandb/model/v1/common.pb.go
@@ -39,6 +39,64 @@ const (
 	_ = protoimpl.EnforceVersion(protoimpl.MaxVersion - 20)
 )
 
+type AggregationFunction int32
+
+const (
+	AggregationFunction_AGGREGATION_FUNCTION_UNSPECIFIED AggregationFunction = 0
+	AggregationFunction_AGGREGATION_FUNCTION_MEAN        AggregationFunction = 1
+	AggregationFunction_AGGREGATION_FUNCTION_MAX         AggregationFunction = 2
+	AggregationFunction_AGGREGATION_FUNCTION_MIN         AggregationFunction = 3
+	AggregationFunction_AGGREGATION_FUNCTION_COUNT       AggregationFunction = 4
+	AggregationFunction_AGGREGATION_FUNCTION_SUM         AggregationFunction = 5
+)
+
+// Enum value maps for AggregationFunction.
+var (
+	AggregationFunction_name = map[int32]string{
+		0: "AGGREGATION_FUNCTION_UNSPECIFIED",
+		1: "AGGREGATION_FUNCTION_MEAN",
+		2: "AGGREGATION_FUNCTION_MAX",
+		3: "AGGREGATION_FUNCTION_MIN",
+		4: "AGGREGATION_FUNCTION_COUNT",
+		5: "AGGREGATION_FUNCTION_SUM",
+	}
+	AggregationFunction_value = map[string]int32{
+		"AGGREGATION_FUNCTION_UNSPECIFIED": 0,
+		"AGGREGATION_FUNCTION_MEAN":        1,
+		"AGGREGATION_FUNCTION_MAX":         2,
+		"AGGREGATION_FUNCTION_MIN":         3,
+		"AGGREGATION_FUNCTION_COUNT":       4,
+		"AGGREGATION_FUNCTION_SUM":         5,
+	}
+)
+
+func (x AggregationFunction) Enum() *AggregationFunction {
+	p := new(AggregationFunction)
+	*p = x
+	return p
+}
+
+func (x AggregationFunction) String() string {
+	return protoimpl.X.EnumStringOf(x.Descriptor(), protoreflect.EnumNumber(x))
+}
+
+func (AggregationFunction) Descriptor() protoreflect.EnumDescriptor {
+	return file_banyandb_model_v1_common_proto_enumTypes[0].Descriptor()
+}
+
+func (AggregationFunction) Type() protoreflect.EnumType {
+	return &file_banyandb_model_v1_common_proto_enumTypes[0]
+}
+
+func (x AggregationFunction) Number() protoreflect.EnumNumber {
+	return protoreflect.EnumNumber(x)
+}
+
+// Deprecated: Use AggregationFunction.Descriptor instead.
+func (AggregationFunction) EnumDescriptor() ([]byte, []int) {
+	return file_banyandb_model_v1_common_proto_rawDescGZIP(), []int{0}
+}
+
 type Str struct {
 	state         protoimpl.MessageState
 	sizeCache     protoimpl.SizeCache
@@ -570,14 +628,28 @@ var file_banyandb_model_v1_common_proto_rawDesc = []byte{
 	0x6e, 0x74, 0x48, 0x00, 0x52, 0x03, 0x69, 0x6e, 0x74, 0x12, 0x21, 0x0a, 0x0b, 0x62, 0x69, 0x6e,
 	0x61, 0x72, 0x79, 0x5f, 0x64, 0x61, 0x74, 0x61, 0x18, 0x04, 0x20, 0x01, 0x28, 0x0c, 0x48, 0x00,
 	0x52, 0x0a, 0x62, 0x69, 0x6e, 0x61, 0x72, 0x79, 0x44, 0x61, 0x74, 0x61, 0x42, 0x07, 0x0a, 0x05,
-	0x76, 0x61, 0x6c, 0x75, 0x65, 0x42, 0x6c, 0x0a, 0x27, 0x6f, 0x72, 0x67, 0x2e, 0x61, 0x70, 0x61,
-	0x63, 0x68, 0x65, 0x2e, 0x73, 0x6b, 0x79, 0x77, 0x61, 0x6c, 0x6b, 0x69, 0x6e, 0x67, 0x2e, 0x62,
-	0x61, 0x6e, 0x79, 0x61, 0x6e, 0x64, 0x62, 0x2e, 0x6d, 0x6f, 0x64, 0x65, 0x6c, 0x2e, 0x76, 0x31,
-	0x5a, 0x41, 0x67, 0x69, 0x74, 0x68, 0x75, 0x62, 0x2e, 0x63, 0x6f, 0x6d, 0x2f, 0x61, 0x70, 0x61,
-	0x63, 0x68, 0x65, 0x2f, 0x73, 0x6b, 0x79, 0x77, 0x61, 0x6c, 0x6b, 0x69, 0x6e, 0x67, 0x2d, 0x62,
-	0x61, 0x6e, 0x79, 0x61, 0x6e, 0x64, 0x62, 0x2f, 0x61, 0x70, 0x69, 0x2f, 0x70, 0x72, 0x6f, 0x74,
-	0x6f, 0x2f, 0x62, 0x61, 0x6e, 0x79, 0x61, 0x6e, 0x64, 0x62, 0x2f, 0x6d, 0x6f, 0x64, 0x65, 0x6c,
-	0x2f, 0x76, 0x31, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33,
+	0x76, 0x61, 0x6c, 0x75, 0x65, 0x2a, 0xd4, 0x01, 0x0a, 0x13, 0x41, 0x67, 0x67, 0x72, 0x65, 0x67,
+	0x61, 0x74, 0x69, 0x6f, 0x6e, 0x46, 0x75, 0x6e, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x12, 0x24, 0x0a,
+	0x20, 0x41, 0x47, 0x47, 0x52, 0x45, 0x47, 0x41, 0x54, 0x49, 0x4f, 0x4e, 0x5f, 0x46, 0x55, 0x4e,
+	0x43, 0x54, 0x49, 0x4f, 0x4e, 0x5f, 0x55, 0x4e, 0x53, 0x50, 0x45, 0x43, 0x49, 0x46, 0x49, 0x45,
+	0x44, 0x10, 0x00, 0x12, 0x1d, 0x0a, 0x19, 0x41, 0x47, 0x47, 0x52, 0x45, 0x47, 0x41, 0x54, 0x49,
+	0x4f, 0x4e, 0x5f, 0x46, 0x55, 0x4e, 0x43, 0x54, 0x49, 0x4f, 0x4e, 0x5f, 0x4d, 0x45, 0x41, 0x4e,
+	0x10, 0x01, 0x12, 0x1c, 0x0a, 0x18, 0x41, 0x47, 0x47, 0x52, 0x45, 0x47, 0x41, 0x54, 0x49, 0x4f,
+	0x4e, 0x5f, 0x46, 0x55, 0x4e, 0x43, 0x54, 0x49, 0x4f, 0x4e, 0x5f, 0x4d, 0x41, 0x58, 0x10, 0x02,
+	0x12, 0x1c, 0x0a, 0x18, 0x41, 0x47, 0x47, 0x52, 0x45, 0x47, 0x41, 0x54, 0x49, 0x4f, 0x4e, 0x5f,
+	0x46, 0x55, 0x4e, 0x43, 0x54, 0x49, 0x4f, 0x4e, 0x5f, 0x4d, 0x49, 0x4e, 0x10, 0x03, 0x12, 0x1e,
+	0x0a, 0x1a, 0x41, 0x47, 0x47, 0x52, 0x45, 0x47, 0x41, 0x54, 0x49, 0x4f, 0x4e, 0x5f, 0x46, 0x55,
+	0x4e, 0x43, 0x54, 0x49, 0x4f, 0x4e, 0x5f, 0x43, 0x4f, 0x55, 0x4e, 0x54, 0x10, 0x04, 0x12, 0x1c,
+	0x0a, 0x18, 0x41, 0x47, 0x47, 0x52, 0x45, 0x47, 0x41, 0x54, 0x49, 0x4f, 0x4e, 0x5f, 0x46, 0x55,
+	0x4e, 0x43, 0x54, 0x49, 0x4f, 0x4e, 0x5f, 0x53, 0x55, 0x4d, 0x10, 0x05, 0x42, 0x6c, 0x0a, 0x27,
+	0x6f, 0x72, 0x67, 0x2e, 0x61, 0x70, 0x61, 0x63, 0x68, 0x65, 0x2e, 0x73, 0x6b, 0x79, 0x77, 0x61,
+	0x6c, 0x6b, 0x69, 0x6e, 0x67, 0x2e, 0x62, 0x61, 0x6e, 0x79, 0x61, 0x6e, 0x64, 0x62, 0x2e, 0x6d,
+	0x6f, 0x64, 0x65, 0x6c, 0x2e, 0x76, 0x31, 0x5a, 0x41, 0x67, 0x69, 0x74, 0x68, 0x75, 0x62, 0x2e,
+	0x63, 0x6f, 0x6d, 0x2f, 0x61, 0x70, 0x61, 0x63, 0x68, 0x65, 0x2f, 0x73, 0x6b, 0x79, 0x77, 0x61,
+	0x6c, 0x6b, 0x69, 0x6e, 0x67, 0x2d, 0x62, 0x61, 0x6e, 0x79, 0x61, 0x6e, 0x64, 0x62, 0x2f, 0x61,
+	0x70, 0x69, 0x2f, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2f, 0x62, 0x61, 0x6e, 0x79, 0x61, 0x6e, 0x64,
+	0x62, 0x2f, 0x6d, 0x6f, 0x64, 0x65, 0x6c, 0x2f, 0x76, 0x31, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74,
+	0x6f, 0x33,
 }
 
 var (
@@ -592,27 +664,29 @@ func file_banyandb_model_v1_common_proto_rawDescGZIP() []byte {
 	return file_banyandb_model_v1_common_proto_rawDescData
 }
 
+var file_banyandb_model_v1_common_proto_enumTypes = make([]protoimpl.EnumInfo, 1)
 var file_banyandb_model_v1_common_proto_msgTypes = make([]protoimpl.MessageInfo, 7)
 var file_banyandb_model_v1_common_proto_goTypes = []interface{}{
-	(*Str)(nil),               // 0: banyandb.model.v1.Str
-	(*Int)(nil),               // 1: banyandb.model.v1.Int
-	(*StrArray)(nil),          // 2: banyandb.model.v1.StrArray
-	(*IntArray)(nil),          // 3: banyandb.model.v1.IntArray
-	(*TagValue)(nil),          // 4: banyandb.model.v1.TagValue
-	(*TagFamilyForWrite)(nil), // 5: banyandb.model.v1.TagFamilyForWrite
-	(*FieldValue)(nil),        // 6: banyandb.model.v1.FieldValue
-	(structpb.NullValue)(0),   // 7: google.protobuf.NullValue
+	(AggregationFunction)(0),  // 0: banyandb.model.v1.AggregationFunction
+	(*Str)(nil),               // 1: banyandb.model.v1.Str
+	(*Int)(nil),               // 2: banyandb.model.v1.Int
+	(*StrArray)(nil),          // 3: banyandb.model.v1.StrArray
+	(*IntArray)(nil),          // 4: banyandb.model.v1.IntArray
+	(*TagValue)(nil),          // 5: banyandb.model.v1.TagValue
+	(*TagFamilyForWrite)(nil), // 6: banyandb.model.v1.TagFamilyForWrite
+	(*FieldValue)(nil),        // 7: banyandb.model.v1.FieldValue
+	(structpb.NullValue)(0),   // 8: google.protobuf.NullValue
 }
 var file_banyandb_model_v1_common_proto_depIdxs = []int32{
-	7, // 0: banyandb.model.v1.TagValue.null:type_name -> google.protobuf.NullValue
-	0, // 1: banyandb.model.v1.TagValue.str:type_name -> banyandb.model.v1.Str
-	2, // 2: banyandb.model.v1.TagValue.str_array:type_name -> banyandb.model.v1.StrArray
-	1, // 3: banyandb.model.v1.TagValue.int:type_name -> banyandb.model.v1.Int
-	3, // 4: banyandb.model.v1.TagValue.int_array:type_name -> banyandb.model.v1.IntArray
-	4, // 5: banyandb.model.v1.TagFamilyForWrite.tags:type_name -> banyandb.model.v1.TagValue
-	7, // 6: banyandb.model.v1.FieldValue.null:type_name -> google.protobuf.NullValue
-	0, // 7: banyandb.model.v1.FieldValue.str:type_name -> banyandb.model.v1.Str
-	1, // 8: banyandb.model.v1.FieldValue.int:type_name -> banyandb.model.v1.Int
+	8, // 0: banyandb.model.v1.TagValue.null:type_name -> google.protobuf.NullValue
+	1, // 1: banyandb.model.v1.TagValue.str:type_name -> banyandb.model.v1.Str
+	3, // 2: banyandb.model.v1.TagValue.str_array:type_name -> banyandb.model.v1.StrArray
+	2, // 3: banyandb.model.v1.TagValue.int:type_name -> banyandb.model.v1.Int
+	4, // 4: banyandb.model.v1.TagValue.int_array:type_name -> banyandb.model.v1.IntArray
+	5, // 5: banyandb.model.v1.TagFamilyForWrite.tags:type_name -> banyandb.model.v1.TagValue
+	8, // 6: banyandb.model.v1.FieldValue.null:type_name -> google.protobuf.NullValue
+	1, // 7: banyandb.model.v1.FieldValue.str:type_name -> banyandb.model.v1.Str
+	2, // 8: banyandb.model.v1.FieldValue.int:type_name -> banyandb.model.v1.Int
 	9, // [9:9] is the sub-list for method output_type
 	9, // [9:9] is the sub-list for method input_type
 	9, // [9:9] is the sub-list for extension type_name
@@ -730,13 +804,14 @@ func file_banyandb_model_v1_common_proto_init() {
 		File: protoimpl.DescBuilder{
 			GoPackagePath: reflect.TypeOf(x{}).PkgPath(),
 			RawDescriptor: file_banyandb_model_v1_common_proto_rawDesc,
-			NumEnums:      0,
+			NumEnums:      1,
 			NumMessages:   7,
 			NumExtensions: 0,
 			NumServices:   0,
 		},
 		GoTypes:           file_banyandb_model_v1_common_proto_goTypes,
 		DependencyIndexes: file_banyandb_model_v1_common_proto_depIdxs,
+		EnumInfos:         file_banyandb_model_v1_common_proto_enumTypes,
 		MessageInfos:      file_banyandb_model_v1_common_proto_msgTypes,
 	}.Build()
 	File_banyandb_model_v1_common_proto = out.File
diff --git a/api/proto/banyandb/model/v1/common.proto b/api/proto/banyandb/model/v1/common.proto
index e8dc2e2..bd6f077 100644
--- a/api/proto/banyandb/model/v1/common.proto
+++ b/api/proto/banyandb/model/v1/common.proto
@@ -63,3 +63,12 @@ message FieldValue {
         bytes binary_data = 4;
     }
 }
+
+enum AggregationFunction {
+    AGGREGATION_FUNCTION_UNSPECIFIED = 0;
+    AGGREGATION_FUNCTION_MEAN = 1;
+    AGGREGATION_FUNCTION_MAX = 2;
+    AGGREGATION_FUNCTION_MIN = 3;
+    AGGREGATION_FUNCTION_COUNT = 4;
+    AGGREGATION_FUNCTION_SUM = 5;
+}