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/03/02 02:25:38 UTC
[skywalking-banyandb] branch main updated: Add measure query (#89)
This is an automated email from the ASF dual-hosted git repository.
hanahmily pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/skywalking-banyandb.git
The following commit(s) were added to refs/heads/main by this push:
new 7f95762 Add measure query (#89)
7f95762 is described below
commit 7f957627bb893c9bb9360174e32fc886e1f71b64
Author: Jiajing LU <lu...@gmail.com>
AuthorDate: Wed Mar 2 10:25:30 2022 +0800
Add measure query (#89)
* add measure processors
* add measure tests
---
api/proto/banyandb/database/v1/rpc_grpc.pb.go | 4 +
api/proto/banyandb/measure/v1/query.pb.go | 249 +++++++-----------
api/proto/banyandb/measure/v1/query.proto | 8 +-
api/proto/banyandb/measure/v1/rpc_grpc.pb.go | 4 +
api/proto/banyandb/stream/v1/rpc_grpc.pb.go | 4 +
banyand/liaison/grpc/stream_test.go | 2 +-
banyand/measure/measure_write_test.go | 3 +-
banyand/query/processor.go | 5 +-
banyand/query/processor_test.go | 36 +--
banyand/stream/metadata.go | 2 +-
banyand/tsdb/bucket/bucket.go | 2 +
banyand/tsdb/shard_test.go | 3 +
pkg/pb/v1/query.go | 92 ++++++-
pkg/query/executor/interface.go | 27 +-
pkg/query/logical/common.go | 13 +-
pkg/query/logical/common_test.go | 77 ++++++
pkg/query/logical/expr.go | 68 +++--
pkg/query/logical/format.go | 2 +-
pkg/query/logical/interface.go | 2 -
.../logical/{analyzer.go => measure_analyzer.go} | 128 +++-------
pkg/query/logical/measure_analyzer_test.go | 218 ++++++++++++++++
pkg/query/logical/measure_plan_execution_test.go | 114 +++++++++
pkg/query/logical/measure_plan_indexscan_local.go | 256 +++++++++++++++++++
pkg/query/logical/plan_orderby.go | 6 +-
pkg/query/logical/schema.go | 282 +++++++++++++++------
.../logical/{analyzer.go => stream_analyzer.go} | 46 ++--
.../{analyzer_test.go => stream_analyzer_test.go} | 58 ++---
pkg/query/logical/{plan.go => stream_plan.go} | 8 +-
...ution_test.go => stream_plan_execution_test.go} | 23 +-
...n_global.go => stream_plan_indexscan_global.go} | 6 +-
...can_local.go => stream_plan_indexscan_local.go} | 29 ++-
pkg/query/logical/testdata/measure_query_data.json | 107 ++++++++
pkg/test/measure/testdata/index_rule_binding.json | 2 +-
.../index_rules/{entity_id.json => scope.json} | 4 +-
pkg/test/measure/testdata/measure.json | 4 +
scripts/build/base.mk | 6 +-
36 files changed, 1410 insertions(+), 490 deletions(-)
diff --git a/api/proto/banyandb/database/v1/rpc_grpc.pb.go b/api/proto/banyandb/database/v1/rpc_grpc.pb.go
index 9aaf0bc..7e89dfe 100644
--- a/api/proto/banyandb/database/v1/rpc_grpc.pb.go
+++ b/api/proto/banyandb/database/v1/rpc_grpc.pb.go
@@ -1,4 +1,8 @@
// Code generated by protoc-gen-go-grpc. DO NOT EDIT.
+// versions:
+// - protoc-gen-go-grpc v1.2.0
+// - protoc (unknown)
+// source: banyandb/database/v1/rpc.proto
package v1
diff --git a/api/proto/banyandb/measure/v1/query.pb.go b/api/proto/banyandb/measure/v1/query.pb.go
index 66b8932..74af964 100644
--- a/api/proto/banyandb/measure/v1/query.pb.go
+++ b/api/proto/banyandb/measure/v1/query.pb.go
@@ -168,8 +168,8 @@ type QueryRequest struct {
Metadata *v11.Metadata `protobuf:"bytes,1,opt,name=metadata,proto3" json:"metadata,omitempty"`
// time_range is a range query with begin/end time of entities in the timeunit of nanoseconds.
TimeRange *v1.TimeRange `protobuf:"bytes,2,opt,name=time_range,json=timeRange,proto3" json:"time_range,omitempty"`
- // criteria select the data points.
- Criteria []*QueryRequest_Criteria `protobuf:"bytes,4,rep,name=criteria,proto3" json:"criteria,omitempty"`
+ // tag_families are indexed.
+ Criteria []*v1.Criteria `protobuf:"bytes,4,rep,name=criteria,proto3" json:"criteria,omitempty"`
// tag_projection can be used to select tags of the data points in the response
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
@@ -226,7 +226,7 @@ func (x *QueryRequest) GetTimeRange() *v1.TimeRange {
return nil
}
-func (x *QueryRequest) GetCriteria() []*QueryRequest_Criteria {
+func (x *QueryRequest) GetCriteria() []*v1.Criteria {
if x != nil {
return x.Criteria
}
@@ -316,61 +316,6 @@ func (x *DataPoint_Field) GetValue() *v1.FieldValue {
return nil
}
-type QueryRequest_Criteria struct {
- state protoimpl.MessageState
- sizeCache protoimpl.SizeCache
- unknownFields protoimpl.UnknownFields
-
- TagFamilyName string `protobuf:"bytes,1,opt,name=tag_family_name,json=tagFamilyName,proto3" json:"tag_family_name,omitempty"`
- Conditions []*v1.Condition `protobuf:"bytes,2,rep,name=conditions,proto3" json:"conditions,omitempty"`
-}
-
-func (x *QueryRequest_Criteria) Reset() {
- *x = QueryRequest_Criteria{}
- if protoimpl.UnsafeEnabled {
- mi := &file_banyandb_measure_v1_query_proto_msgTypes[4]
- ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
- ms.StoreMessageInfo(mi)
- }
-}
-
-func (x *QueryRequest_Criteria) String() string {
- return protoimpl.X.MessageStringOf(x)
-}
-
-func (*QueryRequest_Criteria) ProtoMessage() {}
-
-func (x *QueryRequest_Criteria) ProtoReflect() protoreflect.Message {
- mi := &file_banyandb_measure_v1_query_proto_msgTypes[4]
- 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_Criteria.ProtoReflect.Descriptor instead.
-func (*QueryRequest_Criteria) Descriptor() ([]byte, []int) {
- return file_banyandb_measure_v1_query_proto_rawDescGZIP(), []int{2, 0}
-}
-
-func (x *QueryRequest_Criteria) GetTagFamilyName() string {
- if x != nil {
- return x.TagFamilyName
- }
- return ""
-}
-
-func (x *QueryRequest_Criteria) GetConditions() []*v1.Condition {
- if x != nil {
- return x.Conditions
- }
- return nil
-}
-
type QueryRequest_FieldProjection struct {
state protoimpl.MessageState
sizeCache protoimpl.SizeCache
@@ -382,7 +327,7 @@ type QueryRequest_FieldProjection struct {
func (x *QueryRequest_FieldProjection) Reset() {
*x = QueryRequest_FieldProjection{}
if protoimpl.UnsafeEnabled {
- mi := &file_banyandb_measure_v1_query_proto_msgTypes[5]
+ mi := &file_banyandb_measure_v1_query_proto_msgTypes[4]
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
ms.StoreMessageInfo(mi)
}
@@ -395,7 +340,7 @@ func (x *QueryRequest_FieldProjection) String() string {
func (*QueryRequest_FieldProjection) ProtoMessage() {}
func (x *QueryRequest_FieldProjection) ProtoReflect() protoreflect.Message {
- mi := &file_banyandb_measure_v1_query_proto_msgTypes[5]
+ mi := &file_banyandb_measure_v1_query_proto_msgTypes[4]
if protoimpl.UnsafeEnabled && x != nil {
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
if ms.LoadMessageInfo() == nil {
@@ -408,7 +353,7 @@ func (x *QueryRequest_FieldProjection) ProtoReflect() protoreflect.Message {
// Deprecated: Use QueryRequest_FieldProjection.ProtoReflect.Descriptor instead.
func (*QueryRequest_FieldProjection) Descriptor() ([]byte, []int) {
- return file_banyandb_measure_v1_query_proto_rawDescGZIP(), []int{2, 1}
+ return file_banyandb_measure_v1_query_proto_rawDescGZIP(), []int{2, 0}
}
func (x *QueryRequest_FieldProjection) GetNames() []string {
@@ -432,7 +377,7 @@ type QueryRequest_GroupBy struct {
func (x *QueryRequest_GroupBy) Reset() {
*x = QueryRequest_GroupBy{}
if protoimpl.UnsafeEnabled {
- mi := &file_banyandb_measure_v1_query_proto_msgTypes[6]
+ mi := &file_banyandb_measure_v1_query_proto_msgTypes[5]
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
ms.StoreMessageInfo(mi)
}
@@ -445,7 +390,7 @@ func (x *QueryRequest_GroupBy) String() string {
func (*QueryRequest_GroupBy) ProtoMessage() {}
func (x *QueryRequest_GroupBy) ProtoReflect() protoreflect.Message {
- mi := &file_banyandb_measure_v1_query_proto_msgTypes[6]
+ mi := &file_banyandb_measure_v1_query_proto_msgTypes[5]
if protoimpl.UnsafeEnabled && x != nil {
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
if ms.LoadMessageInfo() == nil {
@@ -458,7 +403,7 @@ func (x *QueryRequest_GroupBy) ProtoReflect() protoreflect.Message {
// Deprecated: Use QueryRequest_GroupBy.ProtoReflect.Descriptor instead.
func (*QueryRequest_GroupBy) Descriptor() ([]byte, []int) {
- return file_banyandb_measure_v1_query_proto_rawDescGZIP(), []int{2, 2}
+ return file_banyandb_measure_v1_query_proto_rawDescGZIP(), []int{2, 1}
}
func (x *QueryRequest_GroupBy) GetTagProjection() *v1.TagProjection {
@@ -488,7 +433,7 @@ type QueryRequest_Aggregation struct {
func (x *QueryRequest_Aggregation) Reset() {
*x = QueryRequest_Aggregation{}
if protoimpl.UnsafeEnabled {
- mi := &file_banyandb_measure_v1_query_proto_msgTypes[7]
+ mi := &file_banyandb_measure_v1_query_proto_msgTypes[6]
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
ms.StoreMessageInfo(mi)
}
@@ -501,7 +446,7 @@ func (x *QueryRequest_Aggregation) String() string {
func (*QueryRequest_Aggregation) ProtoMessage() {}
func (x *QueryRequest_Aggregation) ProtoReflect() protoreflect.Message {
- mi := &file_banyandb_measure_v1_query_proto_msgTypes[7]
+ 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 {
@@ -514,7 +459,7 @@ func (x *QueryRequest_Aggregation) ProtoReflect() protoreflect.Message {
// Deprecated: Use QueryRequest_Aggregation.ProtoReflect.Descriptor instead.
func (*QueryRequest_Aggregation) Descriptor() ([]byte, []int) {
- return file_banyandb_measure_v1_query_proto_rawDescGZIP(), []int{2, 3}
+ return file_banyandb_measure_v1_query_proto_rawDescGZIP(), []int{2, 2}
}
func (x *QueryRequest_Aggregation) GetFunction() v1.AggregationFunction {
@@ -568,7 +513,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, 0xfb, 0x06, 0x0a, 0x0c, 0x51, 0x75, 0x65, 0x72, 0x79, 0x52, 0x65, 0x71, 0x75,
+ 0x74, 0x73, 0x22, 0xfa, 0x05, 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,
@@ -576,62 +521,54 @@ var file_banyandb_measure_v1_query_proto_rawDesc = []byte{
0x0a, 0x74, 0x69, 0x6d, 0x65, 0x5f, 0x72, 0x61, 0x6e, 0x67, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28,
0x0b, 0x32, 0x1c, 0x2e, 0x62, 0x61, 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, 0x46, 0x0a, 0x08, 0x63, 0x72,
- 0x69, 0x74, 0x65, 0x72, 0x69, 0x61, 0x18, 0x04, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x2a, 0x2e, 0x62,
+ 0x09, 0x74, 0x69, 0x6d, 0x65, 0x52, 0x61, 0x6e, 0x67, 0x65, 0x12, 0x37, 0x0a, 0x08, 0x63, 0x72,
+ 0x69, 0x74, 0x65, 0x72, 0x69, 0x61, 0x18, 0x04, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x1b, 0x2e, 0x62,
+ 0x61, 0x6e, 0x79, 0x61, 0x6e, 0x64, 0x62, 0x2e, 0x6d, 0x6f, 0x64, 0x65, 0x6c, 0x2e, 0x76, 0x31,
+ 0x2e, 0x43, 0x72, 0x69, 0x74, 0x65, 0x72, 0x69, 0x61, 0x52, 0x08, 0x63, 0x72, 0x69, 0x74, 0x65,
+ 0x72, 0x69, 0x61, 0x12, 0x47, 0x0a, 0x0e, 0x74, 0x61, 0x67, 0x5f, 0x70, 0x72, 0x6f, 0x6a, 0x65,
+ 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x18, 0x05, 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, 0x5c, 0x0a, 0x10,
+ 0x66, 0x69, 0x65, 0x6c, 0x64, 0x5f, 0x70, 0x72, 0x6f, 0x6a, 0x65, 0x63, 0x74, 0x69, 0x6f, 0x6e,
+ 0x18, 0x06, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x31, 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, 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, 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,
- 0x43, 0x72, 0x69, 0x74, 0x65, 0x72, 0x69, 0x61, 0x52, 0x08, 0x63, 0x72, 0x69, 0x74, 0x65, 0x72,
- 0x69, 0x61, 0x12, 0x47, 0x0a, 0x0e, 0x74, 0x61, 0x67, 0x5f, 0x70, 0x72, 0x6f, 0x6a, 0x65, 0x63,
- 0x74, 0x69, 0x6f, 0x6e, 0x18, 0x05, 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, 0x5c, 0x0a, 0x10, 0x66,
- 0x69, 0x65, 0x6c, 0x64, 0x5f, 0x70, 0x72, 0x6f, 0x6a, 0x65, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x18,
- 0x06, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x31, 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, 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, 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,
- 0x3f, 0x0a, 0x03, 0x61, 0x67, 0x67, 0x18, 0x08, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x2d, 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,
- 0x41, 0x67, 0x67, 0x72, 0x65, 0x67, 0x61, 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, 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,
+ 0x47, 0x72, 0x6f, 0x75, 0x70, 0x42, 0x79, 0x52, 0x07, 0x67, 0x72, 0x6f, 0x75, 0x70, 0x42, 0x79,
+ 0x12, 0x3f, 0x0a, 0x03, 0x61, 0x67, 0x67, 0x18, 0x08, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x2d, 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, 0x41, 0x67, 0x67, 0x72, 0x65, 0x67, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x52, 0x03, 0x61, 0x67,
+ 0x67, 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, 0x1a, 0x70, 0x0a,
+ 0x0b, 0x41, 0x67, 0x67, 0x72, 0x65, 0x67, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x12, 0x42, 0x0a, 0x08,
+ 0x66, 0x75, 0x6e, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x18, 0x01, 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, 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, 0x1a, 0x70,
- 0x0a, 0x0b, 0x41, 0x67, 0x67, 0x72, 0x65, 0x67, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x12, 0x42, 0x0a,
- 0x08, 0x66, 0x75, 0x6e, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x18, 0x01, 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, 0x08, 0x66, 0x75, 0x6e, 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,
+ 0x76, 0x31, 0x2e, 0x41, 0x67, 0x67, 0x72, 0x65, 0x67, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x46, 0x75,
+ 0x6e, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x52, 0x08, 0x66, 0x75, 0x6e, 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 (
@@ -646,46 +583,44 @@ 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, 8)
+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
(*QueryRequest)(nil), // 2: banyandb.measure.v1.QueryRequest
(*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
- (*QueryRequest_GroupBy)(nil), // 6: banyandb.measure.v1.QueryRequest.GroupBy
- (*QueryRequest_Aggregation)(nil), // 7: banyandb.measure.v1.QueryRequest.Aggregation
- (*timestamppb.Timestamp)(nil), // 8: google.protobuf.Timestamp
- (*v1.TagFamily)(nil), // 9: banyandb.model.v1.TagFamily
- (*v11.Metadata)(nil), // 10: banyandb.common.v1.Metadata
- (*v1.TimeRange)(nil), // 11: banyandb.model.v1.TimeRange
+ (*QueryRequest_FieldProjection)(nil), // 4: banyandb.measure.v1.QueryRequest.FieldProjection
+ (*QueryRequest_GroupBy)(nil), // 5: banyandb.measure.v1.QueryRequest.GroupBy
+ (*QueryRequest_Aggregation)(nil), // 6: banyandb.measure.v1.QueryRequest.Aggregation
+ (*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.Criteria)(nil), // 11: banyandb.model.v1.Criteria
(*v1.TagProjection)(nil), // 12: banyandb.model.v1.TagProjection
(*v1.FieldValue)(nil), // 13: banyandb.model.v1.FieldValue
- (*v1.Condition)(nil), // 14: banyandb.model.v1.Condition
- (v1.AggregationFunction)(0), // 15: banyandb.model.v1.AggregationFunction
+ (v1.AggregationFunction)(0), // 14: banyandb.model.v1.AggregationFunction
}
var file_banyandb_measure_v1_query_proto_depIdxs = []int32{
- 8, // 0: banyandb.measure.v1.DataPoint.timestamp:type_name -> google.protobuf.Timestamp
- 9, // 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
- 10, // 4: banyandb.measure.v1.QueryRequest.metadata:type_name -> banyandb.common.v1.Metadata
- 11, // 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
+ 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
+ 11, // 6: banyandb.measure.v1.QueryRequest.criteria:type_name -> banyandb.model.v1.Criteria
12, // 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
- 6, // 9: banyandb.measure.v1.QueryRequest.group_by:type_name -> banyandb.measure.v1.QueryRequest.GroupBy
- 7, // 10: banyandb.measure.v1.QueryRequest.agg:type_name -> banyandb.measure.v1.QueryRequest.Aggregation
+ 4, // 8: banyandb.measure.v1.QueryRequest.field_projection:type_name -> banyandb.measure.v1.QueryRequest.FieldProjection
+ 5, // 9: banyandb.measure.v1.QueryRequest.group_by:type_name -> banyandb.measure.v1.QueryRequest.GroupBy
+ 6, // 10: banyandb.measure.v1.QueryRequest.agg:type_name -> banyandb.measure.v1.QueryRequest.Aggregation
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
- 12, // 13: banyandb.measure.v1.QueryRequest.GroupBy.tag_projection:type_name -> banyandb.model.v1.TagProjection
- 15, // 14: banyandb.measure.v1.QueryRequest.Aggregation.function:type_name -> banyandb.model.v1.AggregationFunction
- 15, // [15:15] is the sub-list for method output_type
- 15, // [15:15] is the sub-list for method input_type
- 15, // [15:15] is the sub-list for extension type_name
- 15, // [15:15] is the sub-list for extension extendee
- 0, // [0:15] is the sub-list for field type_name
+ 12, // 12: banyandb.measure.v1.QueryRequest.GroupBy.tag_projection:type_name -> banyandb.model.v1.TagProjection
+ 14, // 13: banyandb.measure.v1.QueryRequest.Aggregation.function:type_name -> banyandb.model.v1.AggregationFunction
+ 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() }
@@ -743,18 +678,6 @@ func file_banyandb_measure_v1_query_proto_init() {
}
}
file_banyandb_measure_v1_query_proto_msgTypes[4].Exporter = func(v interface{}, i int) interface{} {
- switch v := v.(*QueryRequest_Criteria); i {
- case 0:
- return &v.state
- case 1:
- return &v.sizeCache
- case 2:
- return &v.unknownFields
- default:
- return nil
- }
- }
- file_banyandb_measure_v1_query_proto_msgTypes[5].Exporter = func(v interface{}, i int) interface{} {
switch v := v.(*QueryRequest_FieldProjection); i {
case 0:
return &v.state
@@ -766,7 +689,7 @@ 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{} {
+ file_banyandb_measure_v1_query_proto_msgTypes[5].Exporter = func(v interface{}, i int) interface{} {
switch v := v.(*QueryRequest_GroupBy); i {
case 0:
return &v.state
@@ -778,7 +701,7 @@ func file_banyandb_measure_v1_query_proto_init() {
return nil
}
}
- file_banyandb_measure_v1_query_proto_msgTypes[7].Exporter = func(v interface{}, i int) interface{} {
+ file_banyandb_measure_v1_query_proto_msgTypes[6].Exporter = func(v interface{}, i int) interface{} {
switch v := v.(*QueryRequest_Aggregation); i {
case 0:
return &v.state
@@ -797,7 +720,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: 8,
+ 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 cb5f2fa..be34eb3 100644
--- a/api/proto/banyandb/measure/v1/query.proto
+++ b/api/proto/banyandb/measure/v1/query.proto
@@ -53,12 +53,8 @@ message QueryRequest {
common.v1.Metadata metadata = 1;
// time_range is a range query with begin/end time of entities in the timeunit of nanoseconds.
model.v1.TimeRange time_range = 2;
- message Criteria {
- string tag_family_name = 1;
- repeated model.v1.Condition conditions = 2;
- }
- // criteria select the data points.
- repeated Criteria criteria = 4;
+ // tag_families are indexed.
+ repeated model.v1.Criteria criteria = 4;
// tag_projection can be used to select tags of the data points in the response
model.v1.TagProjection tag_projection = 5;
message FieldProjection {
diff --git a/api/proto/banyandb/measure/v1/rpc_grpc.pb.go b/api/proto/banyandb/measure/v1/rpc_grpc.pb.go
index 22d61d6..b32c5f8 100644
--- a/api/proto/banyandb/measure/v1/rpc_grpc.pb.go
+++ b/api/proto/banyandb/measure/v1/rpc_grpc.pb.go
@@ -1,4 +1,8 @@
// Code generated by protoc-gen-go-grpc. DO NOT EDIT.
+// versions:
+// - protoc-gen-go-grpc v1.2.0
+// - protoc (unknown)
+// source: banyandb/measure/v1/rpc.proto
package v1
diff --git a/api/proto/banyandb/stream/v1/rpc_grpc.pb.go b/api/proto/banyandb/stream/v1/rpc_grpc.pb.go
index 3da4884..1c34ab5 100644
--- a/api/proto/banyandb/stream/v1/rpc_grpc.pb.go
+++ b/api/proto/banyandb/stream/v1/rpc_grpc.pb.go
@@ -1,4 +1,8 @@
// Code generated by protoc-gen-go-grpc. DO NOT EDIT.
+// versions:
+// - protoc-gen-go-grpc v1.2.0
+// - protoc (unknown)
+// source: banyandb/stream/v1/rpc.proto
package v1
diff --git a/banyand/liaison/grpc/stream_test.go b/banyand/liaison/grpc/stream_test.go
index b37cc2f..96ebd8e 100644
--- a/banyand/liaison/grpc/stream_test.go
+++ b/banyand/liaison/grpc/stream_test.go
@@ -171,7 +171,7 @@ func writeData() *streamv1.WriteRequest {
}
func queryCriteria(baseTs time.Time) *streamv1.QueryRequest {
- return pbv1.NewQueryRequestBuilder().
+ return pbv1.NewStreamQueryRequestBuilder().
Limit(10).
Offset(0).
Metadata("default", "sw").
diff --git a/banyand/measure/measure_write_test.go b/banyand/measure/measure_write_test.go
index eceaaff..f966785 100644
--- a/banyand/measure/measure_write_test.go
+++ b/banyand/measure/measure_write_test.go
@@ -63,13 +63,12 @@ func writeData(dataFile string, measure measure.Measure) (baseTime time.Time) {
content, err := dataFS.ReadFile("testdata/" + dataFile)
Expect(err).ShouldNot(HaveOccurred())
Expect(json.Unmarshal(content, &templates)).ShouldNot(HaveOccurred())
- now := time.Now()
for i, template := range templates {
rawDataPointValue, errMarshal := json.Marshal(template)
Expect(errMarshal).ShouldNot(HaveOccurred())
dataPointValue := &measurev1.DataPointValue{}
if dataPointValue.Timestamp == nil {
- dataPointValue.Timestamp = timestamppb.New(now.Add(time.Duration(i) * time.Minute))
+ dataPointValue.Timestamp = timestamppb.New(baseTime.Add(time.Duration(i) * time.Minute))
}
Expect(jsonpb.UnmarshalString(string(rawDataPointValue), dataPointValue)).ShouldNot(HaveOccurred())
errInner := measure.Write(dataPointValue)
diff --git a/banyand/query/processor.go b/banyand/query/processor.go
index ba1d544..f9d07a5 100644
--- a/banyand/query/processor.go
+++ b/banyand/query/processor.go
@@ -29,6 +29,7 @@ import (
"github.com/apache/skywalking-banyandb/banyand/stream"
"github.com/apache/skywalking-banyandb/pkg/bus"
"github.com/apache/skywalking-banyandb/pkg/logger"
+ "github.com/apache/skywalking-banyandb/pkg/query/executor"
"github.com/apache/skywalking-banyandb/pkg/query/logical"
)
@@ -67,7 +68,7 @@ func (q *queryProcessor) Rev(message bus.Message) (resp bus.Message) {
return
}
- analyzer, err := logical.CreateAnalyzerFromMetaService(q.metaService)
+ analyzer, err := logical.CreateStreamAnalyzerFromMetaService(q.metaService)
if err != nil {
q.log.Error().Err(err).Msg("fail to build analyzer")
return
@@ -87,7 +88,7 @@ func (q *queryProcessor) Rev(message bus.Message) (resp bus.Message) {
q.log.Debug().Str("plan", p.String()).Msg("query plan")
- entities, err := p.Execute(ec)
+ entities, err := p.(executor.StreamExecutable).Execute(ec)
if err != nil {
q.log.Error().Err(err).Msg("fail to execute the query plan")
return
diff --git a/banyand/query/processor_test.go b/banyand/query/processor_test.go
index 0f5e0d6..f402756 100644
--- a/banyand/query/processor_test.go
+++ b/banyand/query/processor_test.go
@@ -218,7 +218,7 @@ func TestQueryProcessor(t *testing.T) {
{
name: "query given timeRange is out of the time range of data",
queryGenerator: func(baseTs time.Time) *streamv1.QueryRequest {
- return pb.NewQueryRequestBuilder().
+ return pb.NewStreamQueryRequestBuilder().
Limit(10).
Offset(0).
Metadata("default", "sw").
@@ -231,7 +231,7 @@ func TestQueryProcessor(t *testing.T) {
{
name: "query given timeRange which covers all the segments with data binary projection",
queryGenerator: func(baseTs time.Time) *streamv1.QueryRequest {
- return pb.NewQueryRequestBuilder().
+ return pb.NewStreamQueryRequestBuilder().
Limit(10).
Offset(0).
Metadata("default", "sw").
@@ -246,7 +246,7 @@ func TestQueryProcessor(t *testing.T) {
{
name: "query max valid time-range which covers all the segments with data binary projection",
queryGenerator: func(baseTs time.Time) *streamv1.QueryRequest {
- return pb.NewQueryRequestBuilder().
+ return pb.NewStreamQueryRequestBuilder().
Limit(10).
Offset(0).
Metadata("default", "sw").
@@ -263,7 +263,7 @@ func TestQueryProcessor(t *testing.T) {
{
name: "query given timeRange which covers all the segments and sort by duration DESC",
queryGenerator: func(baseTs time.Time) *streamv1.QueryRequest {
- return pb.NewQueryRequestBuilder().
+ return pb.NewStreamQueryRequestBuilder().
Limit(10).
Offset(0).
Metadata("default", "sw").
@@ -280,11 +280,11 @@ func TestQueryProcessor(t *testing.T) {
{
name: "query TraceID given timeRange includes the time range of data",
queryGenerator: func(baseTs time.Time) *streamv1.QueryRequest {
- return pb.NewQueryRequestBuilder().
+ return pb.NewStreamQueryRequestBuilder().
Limit(10).
Offset(0).
Metadata("default", "sw").
- FieldsInTagFamily("searchable", "trace_id", "=", "1").
+ TagsInTagFamily("searchable", "trace_id", "=", "1").
TimeRange(sT, eT).
Projection("searchable", "trace_id").
Build()
@@ -295,11 +295,11 @@ func TestQueryProcessor(t *testing.T) {
{
name: "query TraceID given timeRange includes the time range of data with dataBinary projection",
queryGenerator: func(baseTs time.Time) *streamv1.QueryRequest {
- return pb.NewQueryRequestBuilder().
+ return pb.NewStreamQueryRequestBuilder().
Limit(10).
Offset(0).
Metadata("default", "sw").
- FieldsInTagFamily("searchable", "trace_id", "=", "1").
+ TagsInTagFamily("searchable", "trace_id", "=", "1").
TimeRange(sT, eT).
Projection("data", "data_binary").
Projection("searchable", "trace_id").
@@ -311,11 +311,11 @@ func TestQueryProcessor(t *testing.T) {
{
name: "Numerical Index - query duration < 500",
queryGenerator: func(baseTs time.Time) *streamv1.QueryRequest {
- return pb.NewQueryRequestBuilder().
+ return pb.NewStreamQueryRequestBuilder().
Limit(10).
Offset(0).
Metadata("default", "sw").
- FieldsInTagFamily("searchable", "duration", "<", 500).
+ TagsInTagFamily("searchable", "duration", "<", 500).
TimeRange(sT, eT).
Projection("searchable", "trace_id").
Build()
@@ -325,11 +325,11 @@ func TestQueryProcessor(t *testing.T) {
{
name: "Numerical Index - query duration <= 500",
queryGenerator: func(baseTs time.Time) *streamv1.QueryRequest {
- return pb.NewQueryRequestBuilder().
+ return pb.NewStreamQueryRequestBuilder().
Limit(10).
Offset(0).
Metadata("default", "sw").
- FieldsInTagFamily("searchable", "duration", "<=", 500).
+ TagsInTagFamily("searchable", "duration", "<=", 500).
TimeRange(sT, eT).
Projection("searchable", "trace_id").
Build()
@@ -339,11 +339,11 @@ func TestQueryProcessor(t *testing.T) {
{
name: "Textual Index - http.method == GET",
queryGenerator: func(baseTs time.Time) *streamv1.QueryRequest {
- return pb.NewQueryRequestBuilder().
+ return pb.NewStreamQueryRequestBuilder().
Limit(10).
Offset(0).
Metadata("default", "sw").
- FieldsInTagFamily("searchable", "http.method", "=", "GET").
+ TagsInTagFamily("searchable", "http.method", "=", "GET").
TimeRange(sT, eT).
Projection("searchable", "trace_id").
Build()
@@ -354,11 +354,11 @@ func TestQueryProcessor(t *testing.T) {
{
name: "Textual Index - http.method == GET with dataBinary projection",
queryGenerator: func(baseTs time.Time) *streamv1.QueryRequest {
- return pb.NewQueryRequestBuilder().
+ return pb.NewStreamQueryRequestBuilder().
Limit(10).
Offset(0).
Metadata("default", "sw").
- FieldsInTagFamily("searchable", "http.method", "=", "GET").
+ TagsInTagFamily("searchable", "http.method", "=", "GET").
TimeRange(sT, eT).
Projection("data", "data_binary").
Projection("searchable", "trace_id").
@@ -370,11 +370,11 @@ func TestQueryProcessor(t *testing.T) {
{
name: "Mixed Index - status_code == 500 AND duration <= 100",
queryGenerator: func(baseTs time.Time) *streamv1.QueryRequest {
- return pb.NewQueryRequestBuilder().
+ return pb.NewStreamQueryRequestBuilder().
Limit(10).
Offset(0).
Metadata("default", "sw").
- FieldsInTagFamily("searchable", "status_code", "=", "500", "duration", "<=", 100).
+ TagsInTagFamily("searchable", "status_code", "=", "500", "duration", "<=", 100).
TimeRange(sT, eT).
Projection("searchable", "trace_id").
Build()
diff --git a/banyand/stream/metadata.go b/banyand/stream/metadata.go
index eb150f9..97972ba 100644
--- a/banyand/stream/metadata.go
+++ b/banyand/stream/metadata.go
@@ -14,7 +14,7 @@
// KIND, either express or implied. See the License for the
// specific language governing permissions and limitations
// under the License.
-//
+
package stream
import (
diff --git a/banyand/tsdb/bucket/bucket.go b/banyand/tsdb/bucket/bucket.go
index dc1b77f..aec2b33 100644
--- a/banyand/tsdb/bucket/bucket.go
+++ b/banyand/tsdb/bucket/bucket.go
@@ -18,6 +18,7 @@
package bucket
import (
+ "fmt"
"time"
"github.com/apache/skywalking-banyandb/pkg/timestamp"
@@ -67,6 +68,7 @@ func (tr *timeBasedReporter) Report() Channel {
for {
select {
case <-ticker.C:
+ fmt.Printf("tick for %v\n", interval)
status := Status{
Capacity: int(tr.End.UnixNano() - tr.Start.UnixNano()),
Volume: int(time.Now().UnixNano() - tr.Start.UnixNano()),
diff --git a/banyand/tsdb/shard_test.go b/banyand/tsdb/shard_test.go
index 1ed4126..870e6ad 100644
--- a/banyand/tsdb/shard_test.go
+++ b/banyand/tsdb/shard_test.go
@@ -20,6 +20,7 @@ package tsdb_test
import (
"context"
"errors"
+ "fmt"
"os"
"path"
"time"
@@ -74,10 +75,12 @@ var _ = Describe("Shard", func() {
Expect(err).NotTo(HaveOccurred())
return num
}).WithTimeout(30 * time.Second).Should(BeNumerically(">=", 3))
+ fmt.Printf("=========%s========\n", "start eventually 2")
for _, d := range segDirectories {
Eventually(func() int {
num := 0
err := tsdb.WalkDir(d, "block-", func(suffix, absolutePath string) error {
+ fmt.Printf("=========%s========\n", absolutePath)
num++
return nil
})
diff --git a/pkg/pb/v1/query.go b/pkg/pb/v1/query.go
index d66e0f3..fa9d482 100644
--- a/pkg/pb/v1/query.go
+++ b/pkg/pb/v1/query.go
@@ -23,6 +23,7 @@ import (
"google.golang.org/protobuf/types/known/timestamppb"
commonv1 "github.com/apache/skywalking-banyandb/api/proto/banyandb/common/v1"
+ measurev1 "github.com/apache/skywalking-banyandb/api/proto/banyandb/measure/v1"
modelv1 "github.com/apache/skywalking-banyandb/api/proto/banyandb/model/v1"
streamv1 "github.com/apache/skywalking-banyandb/api/proto/banyandb/stream/v1"
"github.com/apache/skywalking-banyandb/pkg/convert"
@@ -41,19 +42,19 @@ var (
}
)
-type QueryRequestBuilder struct {
+type StreamQueryRequestBuilder struct {
ec *streamv1.QueryRequest
}
-func NewQueryRequestBuilder() *QueryRequestBuilder {
- return &QueryRequestBuilder{
+func NewStreamQueryRequestBuilder() *StreamQueryRequestBuilder {
+ return &StreamQueryRequestBuilder{
ec: &streamv1.QueryRequest{
Projection: &modelv1.TagProjection{},
},
}
}
-func (b *QueryRequestBuilder) Metadata(group, name string) *QueryRequestBuilder {
+func (b *StreamQueryRequestBuilder) Metadata(group, name string) *StreamQueryRequestBuilder {
b.ec.Metadata = &commonv1.Metadata{
Group: group,
Name: name,
@@ -61,17 +62,17 @@ func (b *QueryRequestBuilder) Metadata(group, name string) *QueryRequestBuilder
return b
}
-func (b *QueryRequestBuilder) Limit(limit uint32) *QueryRequestBuilder {
+func (b *StreamQueryRequestBuilder) Limit(limit uint32) *StreamQueryRequestBuilder {
b.ec.Limit = limit
return b
}
-func (b *QueryRequestBuilder) Offset(offset uint32) *QueryRequestBuilder {
+func (b *StreamQueryRequestBuilder) Offset(offset uint32) *StreamQueryRequestBuilder {
b.ec.Offset = offset
return b
}
-func (b *QueryRequestBuilder) FieldsInTagFamily(tagFamilyName string, items ...interface{}) *QueryRequestBuilder {
+func (b *StreamQueryRequestBuilder) TagsInTagFamily(tagFamilyName string, items ...interface{}) *StreamQueryRequestBuilder {
if len(items)%3 != 0 {
panic("expect 3 to be a factor of the length of items")
}
@@ -148,7 +149,7 @@ func buildTagValue(value interface{}) *modelv1.TagValue {
panic("not supported")
}
-func (b *QueryRequestBuilder) Projection(tagFamily string, projections ...string) *QueryRequestBuilder {
+func (b *StreamQueryRequestBuilder) Projection(tagFamily string, projections ...string) *StreamQueryRequestBuilder {
b.ec.Projection.TagFamilies = append(b.ec.Projection.GetTagFamilies(), &modelv1.TagProjection_TagFamily{
Name: tagFamily,
Tags: projections,
@@ -156,7 +157,7 @@ func (b *QueryRequestBuilder) Projection(tagFamily string, projections ...string
return b
}
-func (b *QueryRequestBuilder) OrderBy(indexRuleName string, sort modelv1.Sort) *QueryRequestBuilder {
+func (b *StreamQueryRequestBuilder) OrderBy(indexRuleName string, sort modelv1.Sort) *StreamQueryRequestBuilder {
b.ec.OrderBy = &modelv1.QueryOrder{
IndexRuleName: indexRuleName,
Sort: sort,
@@ -164,7 +165,7 @@ func (b *QueryRequestBuilder) OrderBy(indexRuleName string, sort modelv1.Sort) *
return b
}
-func (b *QueryRequestBuilder) TimeRange(sT, eT time.Time) *QueryRequestBuilder {
+func (b *StreamQueryRequestBuilder) TimeRange(sT, eT time.Time) *StreamQueryRequestBuilder {
b.ec.TimeRange = &modelv1.TimeRange{
Begin: timestamppb.New(sT),
End: timestamppb.New(eT),
@@ -172,7 +173,7 @@ func (b *QueryRequestBuilder) TimeRange(sT, eT time.Time) *QueryRequestBuilder {
return b
}
-func (b *QueryRequestBuilder) Build() *streamv1.QueryRequest {
+func (b *StreamQueryRequestBuilder) Build() *streamv1.QueryRequest {
return b.ec
}
@@ -220,3 +221,72 @@ func (qeb *QueryResponseElementBuilder) FieldsInTagFamily(tagFamily string, item
func (qeb *QueryResponseElementBuilder) Build() *streamv1.Element {
return qeb.elem
}
+
+type MeasureQueryRequestBuilder struct {
+ ec *measurev1.QueryRequest
+}
+
+func NewMeasureQueryRequestBuilder() *MeasureQueryRequestBuilder {
+ return &MeasureQueryRequestBuilder{
+ ec: &measurev1.QueryRequest{
+ TagProjection: &modelv1.TagProjection{},
+ FieldProjection: &measurev1.QueryRequest_FieldProjection{},
+ },
+ }
+}
+
+func (b *MeasureQueryRequestBuilder) Metadata(group, name string) *MeasureQueryRequestBuilder {
+ b.ec.Metadata = &commonv1.Metadata{
+ Group: group,
+ Name: name,
+ }
+ return b
+}
+
+func (b *MeasureQueryRequestBuilder) TagsInTagFamily(tagFamilyName string, items ...interface{}) *MeasureQueryRequestBuilder {
+ if len(items)%3 != 0 {
+ panic("expect 3 to be a factor of the length of items")
+ }
+
+ criteriaConditions := make([]*modelv1.Condition, len(items)/3)
+ for i := 0; i < len(items)/3; i++ {
+ key, op, values := items[i*3+0], items[i*3+1], items[i*3+2]
+ criteriaConditions[i] = &modelv1.Condition{
+ Name: key.(string),
+ Op: binaryOpsMap[op.(string)],
+ Value: buildTagValue(values),
+ }
+ }
+
+ b.ec.Criteria = append(b.ec.Criteria, &modelv1.Criteria{
+ TagFamilyName: tagFamilyName,
+ Conditions: criteriaConditions,
+ })
+
+ return b
+}
+
+func (b *MeasureQueryRequestBuilder) TagProjection(tagFamily string, projections ...string) *MeasureQueryRequestBuilder {
+ b.ec.TagProjection.TagFamilies = append(b.ec.TagProjection.GetTagFamilies(), &modelv1.TagProjection_TagFamily{
+ Name: tagFamily,
+ Tags: projections,
+ })
+ return b
+}
+
+func (b *MeasureQueryRequestBuilder) FieldProjection(projections ...string) *MeasureQueryRequestBuilder {
+ b.ec.FieldProjection.Names = append(b.ec.FieldProjection.Names, projections...)
+ return b
+}
+
+func (b *MeasureQueryRequestBuilder) TimeRange(sT, eT time.Time) *MeasureQueryRequestBuilder {
+ b.ec.TimeRange = &modelv1.TimeRange{
+ Begin: timestamppb.New(sT),
+ End: timestamppb.New(eT),
+ }
+ return b
+}
+
+func (b *MeasureQueryRequestBuilder) Build() *measurev1.QueryRequest {
+ return b.ec
+}
diff --git a/pkg/query/executor/interface.go b/pkg/query/executor/interface.go
index 6868eac..9b0cf0f 100644
--- a/pkg/query/executor/interface.go
+++ b/pkg/query/executor/interface.go
@@ -18,14 +18,33 @@
package executor
import (
+ "github.com/apache/skywalking-banyandb/api/common"
+ measurev1 "github.com/apache/skywalking-banyandb/api/proto/banyandb/measure/v1"
+ modelv1 "github.com/apache/skywalking-banyandb/api/proto/banyandb/model/v1"
streamv1 "github.com/apache/skywalking-banyandb/api/proto/banyandb/stream/v1"
- "github.com/apache/skywalking-banyandb/banyand/stream"
+ "github.com/apache/skywalking-banyandb/banyand/tsdb"
)
type ExecutionContext interface {
- stream.Stream
+ Shards(entity tsdb.Entity) ([]tsdb.Shard, error)
+ Shard(id common.ShardID) (tsdb.Shard, error)
+ ParseTagFamily(family string, item tsdb.Item) (*modelv1.TagFamily, error)
}
-type Executable interface {
- Execute(ExecutionContext) ([]*streamv1.Element, error)
+type StreamExecutionContext interface {
+ ExecutionContext
+ ParseElementID(item tsdb.Item) (string, error)
+}
+
+type StreamExecutable interface {
+ Execute(StreamExecutionContext) ([]*streamv1.Element, error)
+}
+
+type MeasureExecutionContext interface {
+ ExecutionContext
+ ParseField(name string, item tsdb.Item) (*measurev1.DataPoint_Field, error)
+}
+
+type MeasureExecutable interface {
+ Execute(MeasureExecutionContext) ([]*measurev1.DataPoint, error)
}
diff --git a/pkg/query/logical/common.go b/pkg/query/logical/common.go
index 2960c7b..bef9938 100644
--- a/pkg/query/logical/common.go
+++ b/pkg/query/logical/common.go
@@ -28,6 +28,15 @@ import (
"github.com/apache/skywalking-banyandb/pkg/timestamp"
)
+var (
+ ErrTagNotDefined = errors.New("tag is not defined")
+ ErrFieldNotDefined = errors.New("field is not defined")
+ ErrInvalidConditionType = errors.New("invalid pair type")
+ ErrIncompatibleQueryCondition = errors.New("incompatible query condition type")
+ ErrIndexNotDefined = errors.New("index is not define for the tag")
+ ErrMultipleGlobalIndexes = errors.New("multiple global indexes are not supported")
+)
+
var ErrInvalidData = errors.New("data is invalid")
type (
@@ -45,11 +54,11 @@ func createComparator(sortDirection modelv1.Sort) comparator {
}
}
-// projectItem parses the item within the ExecutionContext.
+// projectItem parses the item within the StreamExecutionContext.
// projectionFieldRefs must be prepared before calling this method, projectionFieldRefs should be a list of
// tag list where the inner list must exist in the same tag family.
// Strict order can be guaranteed in the result.
-func projectItem(ec executor.ExecutionContext, item tsdb.Item, projectionFieldRefs [][]*FieldRef) ([]*modelv1.TagFamily, error) {
+func projectItem(ec executor.ExecutionContext, item tsdb.Item, projectionFieldRefs [][]*TagRef) ([]*modelv1.TagFamily, error) {
tagFamily := make([]*modelv1.TagFamily, len(projectionFieldRefs))
for i, refs := range projectionFieldRefs {
if len(refs) == 0 {
diff --git a/pkg/query/logical/common_test.go b/pkg/query/logical/common_test.go
index aa82eec..6e51af1 100644
--- a/pkg/query/logical/common_test.go
+++ b/pkg/query/logical/common_test.go
@@ -33,14 +33,17 @@ import (
"google.golang.org/protobuf/types/known/timestamppb"
commonv1 "github.com/apache/skywalking-banyandb/api/proto/banyandb/common/v1"
+ measurev1 "github.com/apache/skywalking-banyandb/api/proto/banyandb/measure/v1"
modelv1 "github.com/apache/skywalking-banyandb/api/proto/banyandb/model/v1"
streamv1 "github.com/apache/skywalking-banyandb/api/proto/banyandb/stream/v1"
"github.com/apache/skywalking-banyandb/banyand/discovery"
+ "github.com/apache/skywalking-banyandb/banyand/measure"
"github.com/apache/skywalking-banyandb/banyand/metadata"
"github.com/apache/skywalking-banyandb/banyand/queue"
"github.com/apache/skywalking-banyandb/banyand/stream"
"github.com/apache/skywalking-banyandb/pkg/logger"
"github.com/apache/skywalking-banyandb/pkg/test"
+ testmeasure "github.com/apache/skywalking-banyandb/pkg/test/measure"
teststream "github.com/apache/skywalking-banyandb/pkg/test/stream"
)
@@ -134,3 +137,77 @@ func setup(t *require.Assertions) (stream.Stream, metadata.Service, func()) {
_ = os.RemoveAll(etcdRootDir)
}
}
+
+func setupMeasure(t *require.Assertions) (measure.Measure, metadata.Service, func()) {
+ t.NoError(logger.Init(logger.Logging{
+ Env: "dev",
+ Level: "info",
+ }))
+
+ tempDir, deferFunc := test.Space(t)
+ // Init `Discovery` module
+ repo, err := discovery.NewServiceRepo(context.Background())
+ t.NoError(err)
+ // Init `Queue` module
+ pipeline, err := queue.NewQueue(context.TODO(), repo)
+ t.NoError(err)
+
+ metadataSvc, err := metadata.NewService(context.TODO())
+ t.NoError(err)
+
+ etcdRootDir := testmeasure.RandomTempDir()
+ err = metadataSvc.FlagSet().Parse([]string{"--metadata-root-path=" + etcdRootDir})
+ t.NoError(err)
+
+ measureSvc, err := measure.NewService(context.TODO(), metadataSvc, repo, pipeline)
+ t.NoError(err)
+
+ // 1 - (MeasureService).PreRun
+ err = metadataSvc.PreRun()
+ t.NoError(err)
+
+ err = testmeasure.PreloadSchema(metadataSvc.SchemaRegistry())
+ t.NoError(err)
+
+ err = measureSvc.FlagSet().Parse([]string{"--root-path=" + tempDir})
+ t.NoError(err)
+
+ // 2 - (MeasureService).PreRun
+ err = measureSvc.PreRun()
+ t.NoError(err)
+
+ m, err := measureSvc.Measure(&commonv1.Metadata{
+ Name: "cpm",
+ Group: "default",
+ })
+ t.NoError(err)
+ t.NotNil(m)
+
+ return m, metadataSvc, func() {
+ _ = m.Close()
+ metadataSvc.GracefulStop()
+ deferFunc()
+ _ = os.RemoveAll(etcdRootDir)
+ }
+}
+
+func setupMeasureQueryData(testing *testing.T, dataFile string, measure measure.Measure) (baseTime time.Time) {
+ t := assert.New(testing)
+ var templates []interface{}
+ baseTime = time.Now()
+ content, err := dataFS.ReadFile("testdata/" + dataFile)
+ t.NoError(err)
+ t.NoError(json.Unmarshal(content, &templates))
+ for i, template := range templates {
+ rawDataPointValue, errMarshal := json.Marshal(template)
+ t.NoError(errMarshal)
+ dataPointValue := &measurev1.DataPointValue{}
+ if dataPointValue.Timestamp == nil {
+ dataPointValue.Timestamp = timestamppb.New(baseTime.Add(time.Duration(i) * time.Minute))
+ }
+ t.NoError(jsonpb.UnmarshalString(string(rawDataPointValue), dataPointValue))
+ errInner := measure.Write(dataPointValue)
+ t.NoError(errInner)
+ }
+ return baseTime
+}
diff --git a/pkg/query/logical/expr.go b/pkg/query/logical/expr.go
index 591ee1f..04d2801 100644
--- a/pkg/query/logical/expr.go
+++ b/pkg/query/logical/expr.go
@@ -37,33 +37,33 @@ var binaryOpFactory = map[modelv1.Condition_BinaryOp]func(l, r Expr) Expr{
modelv1.Condition_BINARY_OP_NOT_HAVING: NotHaving,
}
-var _ ResolvableExpr = (*FieldRef)(nil)
+var _ ResolvableExpr = (*TagRef)(nil)
-// FieldRef is the reference to the field
-// also it holds the definition/schema of the field
-type FieldRef struct {
+// TagRef is the reference to the field
+// also it holds the definition (derived from the streamSchema, measureSchema) of the tag
+type TagRef struct {
// tag defines the family name and name of the Tag
tag *Tag
- // spec contains the index of the key in the schema, as well as the underlying FieldSpec
+ // spec contains the index of the key in the streamSchema/measureSchema, as well as the underlying tagSpec
Spec *tagSpec
}
-func (f *FieldRef) Equal(expr Expr) bool {
- if other, ok := expr.(*FieldRef); ok {
+func (f *TagRef) Equal(expr Expr) bool {
+ if other, ok := expr.(*TagRef); ok {
return other.tag.GetTagName() == f.tag.GetTagName() && other.Spec.spec.GetType() == f.Spec.spec.GetType()
}
return false
}
-func (f *FieldRef) FieldType() databasev1.TagType {
+func (f *TagRef) FieldType() databasev1.TagType {
if f.Spec == nil {
panic("should be resolved first")
}
return f.Spec.spec.GetType()
}
-func (f *FieldRef) Resolve(s Schema) error {
- specs, err := s.CreateRef([]*Tag{f.tag})
+func (f *TagRef) Resolve(s Schema) error {
+ specs, err := s.CreateTagRef([]*Tag{f.tag})
if err != nil {
return err
}
@@ -71,23 +71,59 @@ func (f *FieldRef) Resolve(s Schema) error {
return nil
}
-func (f *FieldRef) String() string {
+func (f *TagRef) String() string {
return fmt.Sprintf("#%s<%s>", f.tag.GetCompoundName(), f.Spec.spec.GetType().String())
}
-func NewFieldRef(familyName, tagName string) *FieldRef {
- return &FieldRef{
+func NewFieldRef(familyName, tagName string) *TagRef {
+ return &TagRef{
tag: NewTag(familyName, tagName),
}
}
-// NewSearchableFieldRef is a short-hand method for creating a FieldRef to the tag in the searchable family
-func NewSearchableFieldRef(tagName string) *FieldRef {
- return &FieldRef{
+// NewSearchableFieldRef is a short-handed method for creating a TagRef to the tag in the searchable family
+func NewSearchableFieldRef(tagName string) *TagRef {
+ return &TagRef{
tag: NewTag("searchable", tagName),
}
}
+var _ ResolvableExpr = (*FieldRef)(nil)
+
+// FieldRef is the reference to the field
+// also it holds the definition (derived from measureSchema) of the field
+type FieldRef struct {
+ // field defines the name of the Field
+ field *Field
+ // spec contains the index of the key in the measureSchema, as well as the underlying FieldSpec
+ Spec *fieldSpec
+}
+
+func (f *FieldRef) String() string {
+ return fmt.Sprintf("#%s<%s>", f.Spec.spec.GetName(), f.Spec.spec.GetFieldType().String())
+}
+
+func (f *FieldRef) FieldType() databasev1.TagType {
+ // TODO: what shall we return?
+ panic("Tag Type")
+}
+
+func (f *FieldRef) Equal(expr Expr) bool {
+ if other, ok := expr.(*FieldRef); ok {
+ return other.field.name == f.field.name && other.Spec.spec.GetFieldType() == f.Spec.spec.GetFieldType()
+ }
+ return false
+}
+
+func (f *FieldRef) Resolve(s Schema) error {
+ specs, err := s.CreateFieldRef(f.field)
+ if err != nil {
+ return err
+ }
+ f.Spec = specs[0].Spec
+ return nil
+}
+
var _ ResolvableExpr = (*binaryExpr)(nil)
// binaryExpr is composed of two operands with one op as the operator
diff --git a/pkg/query/logical/format.go b/pkg/query/logical/format.go
index c880b82..d3aa9d9 100644
--- a/pkg/query/logical/format.go
+++ b/pkg/query/logical/format.go
@@ -41,7 +41,7 @@ func formatWithIndent(p Plan, indent int) string {
return res
}
-func formatExpr(sep string, exprGroup ...[]*FieldRef) string {
+func formatExpr(sep string, exprGroup ...[]*TagRef) string {
var exprsStr []string
for _, exprs := range exprGroup {
for i := 0; i < len(exprs); i++ {
diff --git a/pkg/query/logical/interface.go b/pkg/query/logical/interface.go
index b9fcd3e..813577c 100644
--- a/pkg/query/logical/interface.go
+++ b/pkg/query/logical/interface.go
@@ -21,7 +21,6 @@ import (
"fmt"
databasev1 "github.com/apache/skywalking-banyandb/api/proto/banyandb/database/v1"
- "github.com/apache/skywalking-banyandb/pkg/query/executor"
)
type PlanType uint8
@@ -40,7 +39,6 @@ type UnresolvedPlan interface {
type Plan interface {
fmt.Stringer
Type() PlanType
- executor.Executable
Equal(Plan) bool
Children() []Plan
Schema() Schema
diff --git a/pkg/query/logical/analyzer.go b/pkg/query/logical/measure_analyzer.go
similarity index 52%
copy from pkg/query/logical/analyzer.go
copy to pkg/query/logical/measure_analyzer.go
index e9ce0b9..0ec6f15 100644
--- a/pkg/query/logical/analyzer.go
+++ b/pkg/query/logical/measure_analyzer.go
@@ -20,77 +20,38 @@ package logical
import (
"context"
- "github.com/pkg/errors"
-
commonv1 "github.com/apache/skywalking-banyandb/api/proto/banyandb/common/v1"
+ measurev1 "github.com/apache/skywalking-banyandb/api/proto/banyandb/measure/v1"
modelv1 "github.com/apache/skywalking-banyandb/api/proto/banyandb/model/v1"
- streamv1 "github.com/apache/skywalking-banyandb/api/proto/banyandb/stream/v1"
"github.com/apache/skywalking-banyandb/banyand/metadata"
"github.com/apache/skywalking-banyandb/banyand/tsdb"
"github.com/apache/skywalking-banyandb/pkg/convert"
)
-var (
- ErrFieldNotDefined = errors.New("field is not defined")
- ErrInvalidConditionType = errors.New("invalid pair type")
- ErrIncompatibleQueryCondition = errors.New("incompatible query condition type")
- ErrIndexNotDefined = errors.New("index is not define for the field")
- ErrMultipleGlobalIndexes = errors.New("multiple global indexes are not supported")
-)
-
-var (
- DefaultLimit uint32 = 100
-)
-
-type Tag struct {
- familyName, name string
-}
-
-func NewTag(family, name string) *Tag {
- return &Tag{
- familyName: family,
- name: name,
- }
-}
-
-// NewTags create an array of Tag within a TagFamily
-func NewTags(family string, tagNames ...string) []*Tag {
- tags := make([]*Tag, len(tagNames))
- for i, name := range tagNames {
- tags[i] = NewTag(family, name)
- }
- return tags
-}
-
-// GetCompoundName is only used for error message
-func (t *Tag) GetCompoundName() string {
- return t.familyName + ":" + t.name
+type Field struct {
+ name string
}
-func (t *Tag) GetTagName() string {
- return t.name
+func NewField(name string) *Field {
+ return &Field{name: name}
}
-func (t *Tag) GetFamilyName() string {
- return t.familyName
-}
-
-type Analyzer struct {
+type MeasureAnalyzer struct {
metadataRepoImpl metadata.Repo
}
-func CreateAnalyzerFromMetaService(metaSvc metadata.Service) (*Analyzer, error) {
- return &Analyzer{
+func CreateMeasureAnalyzerFromMetaService(metaSvc metadata.Service) (*MeasureAnalyzer, error) {
+ return &MeasureAnalyzer{
metaSvc,
}, nil
}
-func (a *Analyzer) BuildStreamSchema(ctx context.Context, metadata *commonv1.Metadata) (Schema, error) {
+func (a *MeasureAnalyzer) BuildMeasureSchema(ctx context.Context, metadata *commonv1.Metadata) (Schema, error) {
group, err := a.metadataRepoImpl.GroupRegistry().GetGroup(ctx, metadata.GetGroup())
if err != nil {
return nil, err
}
- stream, err := a.metadataRepoImpl.StreamRegistry().GetStream(ctx, metadata)
+ measure, err := a.metadataRepoImpl.MeasureRegistry().GetMeasure(ctx, metadata)
if err != nil {
return nil, err
@@ -102,63 +63,49 @@ func (a *Analyzer) BuildStreamSchema(ctx context.Context, metadata *commonv1.Met
return nil, err
}
- s := &schema{
- group: group,
- stream: stream,
- indexRules: indexRules,
- fieldMap: make(map[string]*tagSpec),
- entityList: stream.GetEntity().GetTagNames(),
+ ms := &measureSchema{
+ common: &commonSchema{
+ group: group,
+ indexRules: indexRules,
+ tagMap: make(map[string]*tagSpec),
+ entityList: measure.GetEntity().GetTagNames(),
+ },
+ measure: measure,
+ fieldMap: make(map[string]*fieldSpec),
}
- // generate the schema of the fields for the traceSeries
- for tagFamilyIdx, tagFamily := range stream.GetTagFamilies() {
+ for tagFamilyIdx, tagFamily := range measure.GetTagFamilies() {
for tagIdx, spec := range tagFamily.GetTags() {
- s.registerField(spec.GetName(), tagFamilyIdx, tagIdx, spec)
+ ms.registerTag(tagFamilyIdx, tagIdx, spec)
}
}
- return s, nil
+ for fieldIdx, spec := range measure.GetFields() {
+ ms.registerField(fieldIdx, spec)
+ }
+
+ return ms, nil
}
-func (a *Analyzer) Analyze(_ context.Context, criteria *streamv1.QueryRequest, metadata *commonv1.Metadata, s Schema) (Plan, error) {
+func (a *MeasureAnalyzer) Analyze(_ context.Context, criteria *measurev1.QueryRequest, metadata *commonv1.Metadata, s Schema) (Plan, error) {
// parse fields
- plan, err := parseFields(criteria, metadata, s)
+ plan, err := parseMeasureFields(criteria, metadata, s)
if err != nil {
return nil, err
}
- // parse orderBy
- queryOrder := criteria.GetOrderBy()
- if queryOrder != nil {
- if v, ok := plan.(*unresolvedIndexScan); ok {
- v.unresolvedOrderBy = OrderBy(queryOrder.GetIndexRuleName(), queryOrder.GetSort())
- }
- }
-
- // parse offset
- plan = Offset(plan, criteria.GetOffset())
-
- // parse limit
- limitParameter := criteria.GetLimit()
- if limitParameter == 0 {
- limitParameter = DefaultLimit
- }
- plan = Limit(plan, limitParameter)
-
return plan.Analyze(s)
}
-// parseFields parses the query request to decide which kind of plan should be generated
+// parseMeasureFields parses the query request to decide which kind of plan should be generated
// Basically,
// 1 - If no criteria is given, we can only scan all shards
-// 2 - If criteria is given, but all of those fields exist in the "entity" definition,
-// i.e. they are top-level sharding keys. For example, for the current skywalking's schema,
-// we use service_id + service_instance_id + state as the compound sharding keys.
-func parseFields(criteria *streamv1.QueryRequest, metadata *commonv1.Metadata, s Schema) (UnresolvedPlan, error) {
+// 2 - If criteria is given, but all of those fields exist in the "entity" definition
+func parseMeasureFields(criteria *measurev1.QueryRequest, metadata *commonv1.Metadata, s Schema) (UnresolvedPlan, error) {
timeRange := criteria.GetTimeRange()
- projTags := make([][]*Tag, len(criteria.GetProjection().GetTagFamilies()))
- for i, tagFamily := range criteria.GetProjection().GetTagFamilies() {
+ projTags := make([][]*Tag, len(criteria.GetTagProjection().GetTagFamilies()))
+ for i, tagFamily := range criteria.GetTagProjection().GetTagFamilies() {
var projTagInFamily []*Tag
for _, tagName := range tagFamily.GetTags() {
projTagInFamily = append(projTagInFamily, NewTag(tagFamily.GetName(), tagName))
@@ -166,6 +113,11 @@ func parseFields(criteria *streamv1.QueryRequest, metadata *commonv1.Metadata, s
projTags[i] = projTagInFamily
}
+ projFields := make([]*Field, len(criteria.GetFieldProjection().GetNames()))
+ for i, fieldNameProj := range criteria.GetFieldProjection().GetNames() {
+ projFields[i] = NewField(fieldNameProj)
+ }
+
var tagExprs []Expr
entityList := s.EntityList()
@@ -217,6 +169,6 @@ func parseFields(criteria *streamv1.QueryRequest, metadata *commonv1.Metadata, s
}
}
- return IndexScan(timeRange.GetBegin().AsTime(), timeRange.GetEnd().AsTime(), metadata,
- tagExprs, entity, nil, projTags...), nil
+ return MeasureIndexScan(timeRange.GetBegin().AsTime(), timeRange.GetEnd().AsTime(), metadata,
+ tagExprs, entity, projTags, projFields), nil
}
diff --git a/pkg/query/logical/measure_analyzer_test.go b/pkg/query/logical/measure_analyzer_test.go
new file mode 100644
index 0000000..f29c16c
--- /dev/null
+++ b/pkg/query/logical/measure_analyzer_test.go
@@ -0,0 +1,218 @@
+// Licensed to Apache Software Foundation (ASF) under one or more contributor
+// license agreements. See the NOTICE file distributed with
+// this work for additional information regarding copyright
+// ownership. Apache Software Foundation (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.
+
+package logical_test
+
+import (
+ "context"
+ "os"
+ "testing"
+ "time"
+
+ "github.com/google/go-cmp/cmp"
+ "github.com/stretchr/testify/require"
+
+ "github.com/apache/skywalking-banyandb/banyand/metadata"
+ "github.com/apache/skywalking-banyandb/banyand/tsdb"
+ pb "github.com/apache/skywalking-banyandb/pkg/pb/v1"
+ "github.com/apache/skywalking-banyandb/pkg/query/logical"
+ testmeasure "github.com/apache/skywalking-banyandb/pkg/test/measure"
+)
+
+// setUpMeasureAnalyzer creates a default analyzer for testing.
+// You have to close the underlying metadata after testmeasure
+func setUpMeasureAnalyzer() (*logical.MeasureAnalyzer, func(), error) {
+ metadataService, err := metadata.NewService(context.TODO())
+ if err != nil {
+ return nil, func() {
+ }, err
+ }
+
+ rootDir := testmeasure.RandomTempDir()
+ err = metadataService.FlagSet().Parse([]string{"--metadata-root-path=" + rootDir})
+
+ if err != nil {
+ return nil, func() {
+ }, err
+ }
+
+ err = metadataService.PreRun()
+ if err != nil {
+ return nil, func() {
+ }, err
+ }
+
+ err = testmeasure.PreloadSchema(metadataService.SchemaRegistry())
+ if err != nil {
+ return nil, func() {
+ }, err
+ }
+
+ ana, err := logical.CreateMeasureAnalyzerFromMetaService(metadataService)
+ if err != nil {
+ return nil, func() {
+ }, err
+ }
+ return ana, func() {
+ metadataService.GracefulStop()
+ os.RemoveAll(rootDir)
+ }, nil
+}
+
+func TestMeasureAnalyzer_SimpleTimeScan(t *testing.T) {
+ assert := require.New(t)
+
+ ana, stopFunc, err := setUpMeasureAnalyzer()
+ assert.NoError(err)
+ assert.NotNil(ana)
+ defer stopFunc()
+
+ sT, eT := time.Now().Add(-3*time.Hour), time.Now()
+
+ criteria := pb.NewMeasureQueryRequestBuilder().
+ Metadata("default", "cpm").
+ TimeRange(sT, eT).
+ Build()
+
+ metadata := criteria.GetMetadata()
+
+ schema, err := ana.BuildMeasureSchema(context.TODO(), metadata)
+ assert.NoError(err)
+
+ plan, err := ana.Analyze(context.TODO(), criteria, metadata, schema)
+ assert.NoError(err)
+ assert.NotNil(plan)
+ correctPlan, err := logical.MeasureIndexScan(sT, eT, metadata, nil,
+ tsdb.Entity{tsdb.AnyEntry},
+ nil, nil).
+ Analyze(schema)
+ assert.NoError(err)
+ assert.NotNil(correctPlan)
+ assert.True(cmp.Equal(plan, correctPlan), "plan is not equal to correct plan")
+}
+
+func TestMeasureAnalyzer_ComplexQuery(t *testing.T) {
+ assert := require.New(t)
+
+ ana, stopFunc, err := setUpMeasureAnalyzer()
+ assert.NoError(err)
+ assert.NotNil(ana)
+ defer stopFunc()
+
+ sT, eT := time.Now().Add(-3*time.Hour), time.Now()
+
+ criteria := pb.NewMeasureQueryRequestBuilder().
+ Metadata("default", "cpm").
+ TagProjection("default", "entity_id", "scope").
+ TagsInTagFamily("default", "entity_id", "=", "abc", "scope", "=", "endpoint").
+ FieldProjection("summation", "count", "value").
+ TimeRange(sT, eT).
+ Build()
+
+ metadata := criteria.GetMetadata()
+
+ schema, err := ana.BuildMeasureSchema(context.TODO(), metadata)
+ assert.NoError(err)
+
+ plan, err := ana.Analyze(context.TODO(), criteria, metadata, schema)
+ assert.NoError(err)
+ assert.NotNil(plan)
+
+ correctPlan, err := logical.MeasureIndexScan(sT, eT, metadata,
+ []logical.Expr{
+ logical.Eq(logical.NewFieldRef("default", "scope"), logical.Str("endpoint")),
+ }, tsdb.Entity{tsdb.Entry("abc")},
+ [][]*logical.Tag{logical.NewTags("default", "entity_id", "scope")},
+ []*logical.Field{logical.NewField("summation"), logical.NewField("count"), logical.NewField("value")},
+ ).Analyze(schema)
+ assert.NoError(err)
+ assert.NotNil(correctPlan)
+ assert.True(cmp.Equal(plan, correctPlan), "plan is not equal to correct plan")
+}
+
+func TestMeasureAnalyzer_Projection_TagNotDefined(t *testing.T) {
+ assert := require.New(t)
+
+ ana, stopFunc, err := setUpMeasureAnalyzer()
+ assert.NoError(err)
+ assert.NotNil(ana)
+ defer stopFunc()
+
+ criteria := pb.NewMeasureQueryRequestBuilder().
+ Metadata("default", "cpm").
+ TagProjection("default", "scope", "entity_id", "unknown").
+ FieldProjection("summation", "count", "value").
+ TimeRange(time.Now().Add(-3*time.Hour), time.Now()).
+ Build()
+
+ metadata := criteria.GetMetadata()
+
+ schema, err := ana.BuildMeasureSchema(context.TODO(), metadata)
+ assert.NoError(err)
+
+ _, err = ana.Analyze(context.TODO(), criteria, metadata, schema)
+ assert.ErrorIs(err, logical.ErrTagNotDefined)
+}
+
+func TestMeasureAnalyzer_Projection_FieldNotDefined(t *testing.T) {
+ assert := require.New(t)
+
+ ana, stopFunc, err := setUpMeasureAnalyzer()
+ assert.NoError(err)
+ assert.NotNil(ana)
+ defer stopFunc()
+
+ criteria := pb.NewMeasureQueryRequestBuilder().
+ Metadata("default", "cpm").
+ TagProjection("default", "scope", "entity_id").
+ FieldProjection("summation", "count", "value", "unknown").
+ TimeRange(time.Now().Add(-3*time.Hour), time.Now()).
+ Build()
+
+ metadata := criteria.GetMetadata()
+
+ schema, err := ana.BuildMeasureSchema(context.TODO(), metadata)
+ assert.NoError(err)
+
+ _, err = ana.Analyze(context.TODO(), criteria, metadata, schema)
+ assert.ErrorIs(err, logical.ErrFieldNotDefined)
+}
+
+func TestMeasureAnalyzer_Fields_IndexNotDefined(t *testing.T) {
+ assert := require.New(t)
+
+ ana, stopFunc, err := setUpMeasureAnalyzer()
+ assert.NoError(err)
+ assert.NotNil(ana)
+ defer stopFunc()
+
+ criteria := pb.NewMeasureQueryRequestBuilder().
+ Metadata("default", "cpm").
+ TagProjection("default", "scope", "entity_id").
+ FieldProjection("summation", "count", "value").
+ TimeRange(time.Now().Add(-3*time.Hour), time.Now()).
+ TagsInTagFamily("searchable", "unindexed-tag", ">", 10000).
+ Build()
+
+ metadata := criteria.GetMetadata()
+
+ schema, err := ana.BuildMeasureSchema(context.TODO(), metadata)
+ assert.NoError(err)
+
+ _, err = ana.Analyze(context.TODO(), criteria, metadata, schema)
+ assert.ErrorIs(err, logical.ErrIndexNotDefined)
+}
diff --git a/pkg/query/logical/measure_plan_execution_test.go b/pkg/query/logical/measure_plan_execution_test.go
new file mode 100644
index 0000000..a78d7d6
--- /dev/null
+++ b/pkg/query/logical/measure_plan_execution_test.go
@@ -0,0 +1,114 @@
+// Licensed to Apache Software Foundation (ASF) under one or more contributor
+// license agreements. See the NOTICE file distributed with
+// this work for additional information regarding copyright
+// ownership. Apache Software Foundation (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.
+
+package logical_test
+
+import (
+ "context"
+ "testing"
+ "time"
+
+ "github.com/stretchr/testify/require"
+
+ commonv1 "github.com/apache/skywalking-banyandb/api/proto/banyandb/common/v1"
+ "github.com/apache/skywalking-banyandb/banyand/tsdb"
+ "github.com/apache/skywalking-banyandb/pkg/query/executor"
+ "github.com/apache/skywalking-banyandb/pkg/query/logical"
+)
+
+func TestMeasurePlanExecution_IndexScan(t *testing.T) {
+ tester := require.New(t)
+ measureSvc, metaService, deferFunc := setupMeasure(tester)
+ defer deferFunc()
+ baseTs := setupMeasureQueryData(t, "measure_query_data.json", measureSvc)
+
+ metadata := &commonv1.Metadata{
+ Name: "cpm",
+ Group: "default",
+ }
+
+ sT, eT := baseTs, baseTs.Add(1*time.Hour)
+
+ analyzer, err := logical.CreateMeasureAnalyzerFromMetaService(metaService)
+ tester.NoError(err)
+ tester.NotNil(analyzer)
+
+ tests := []struct {
+ name string
+ unresolvedPlan logical.UnresolvedPlan
+ wantLength int
+ tagLength []int
+ fieldLength int
+ }{
+ {
+ name: "Single Index Search using scope returns all results",
+ unresolvedPlan: logical.MeasureIndexScan(sT, eT, metadata, []logical.Expr{
+ logical.Eq(logical.NewFieldRef("default", "scope"), logical.Str("minute")),
+ }, tsdb.Entity{tsdb.AnyEntry}, nil, nil),
+ wantLength: 3,
+ },
+ {
+ name: "Single Index Search using scope returns all results",
+ unresolvedPlan: logical.MeasureIndexScan(sT, eT, metadata, []logical.Expr{
+ logical.Eq(logical.NewFieldRef("default", "scope"), logical.Str("hour")),
+ }, tsdb.Entity{tsdb.AnyEntry}, nil, nil),
+ wantLength: 0,
+ },
+ {
+ name: "Single Index Search using scope returns all results with tag projection",
+ unresolvedPlan: logical.MeasureIndexScan(sT, eT, metadata, []logical.Expr{
+ logical.Eq(logical.NewFieldRef("default", "scope"), logical.Str("minute")),
+ }, tsdb.Entity{tsdb.AnyEntry}, [][]*logical.Tag{{logical.NewTag("default", "scope")}},
+ nil),
+ wantLength: 3,
+ tagLength: []int{1},
+ },
+ {
+ name: "Single Index Search using scope returns all results with field projection",
+ unresolvedPlan: logical.MeasureIndexScan(sT, eT, metadata, []logical.Expr{
+ logical.Eq(logical.NewFieldRef("default", "scope"), logical.Str("minute")),
+ }, tsdb.Entity{tsdb.AnyEntry}, nil,
+ []*logical.Field{logical.NewField("summation"), logical.NewField("count"), logical.NewField("value")}),
+ wantLength: 3,
+ fieldLength: 3,
+ },
+ }
+
+ for _, tt := range tests {
+ t.Run(tt.name, func(t *testing.T) {
+ tester := require.New(t)
+ schema, err := analyzer.BuildMeasureSchema(context.TODO(), metadata)
+ tester.NoError(err)
+
+ plan, err := tt.unresolvedPlan.Analyze(schema)
+ tester.NoError(err)
+ tester.NotNil(plan)
+
+ dataPoints, err := plan.(executor.MeasureExecutable).Execute(measureSvc)
+ tester.NoError(err)
+ tester.Len(dataPoints, tt.wantLength)
+
+ for _, dp := range dataPoints {
+ tester.Len(dp.GetFields(), tt.fieldLength)
+ tester.Len(dp.GetTagFamilies(), len(tt.tagLength))
+ for tagFamilyIdx, tagFamily := range dp.GetTagFamilies() {
+ tester.Len(tagFamily.GetTags(), tt.tagLength[tagFamilyIdx])
+ }
+ }
+ })
+ }
+}
diff --git a/pkg/query/logical/measure_plan_indexscan_local.go b/pkg/query/logical/measure_plan_indexscan_local.go
new file mode 100644
index 0000000..6ec6366
--- /dev/null
+++ b/pkg/query/logical/measure_plan_indexscan_local.go
@@ -0,0 +1,256 @@
+// Licensed to Apache Software Foundation (ASF) under one or more contributor
+// license agreements. See the NOTICE file distributed with
+// this work for additional information regarding copyright
+// ownership. Apache Software Foundation (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.
+
+package logical
+
+import (
+ "bytes"
+ "fmt"
+ "strings"
+ "time"
+
+ "github.com/google/go-cmp/cmp"
+ "github.com/pkg/errors"
+ "google.golang.org/protobuf/types/known/timestamppb"
+
+ commonv1 "github.com/apache/skywalking-banyandb/api/proto/banyandb/common/v1"
+ databasev1 "github.com/apache/skywalking-banyandb/api/proto/banyandb/database/v1"
+ measurev1 "github.com/apache/skywalking-banyandb/api/proto/banyandb/measure/v1"
+ modelv1 "github.com/apache/skywalking-banyandb/api/proto/banyandb/model/v1"
+ "github.com/apache/skywalking-banyandb/banyand/tsdb"
+ "github.com/apache/skywalking-banyandb/pkg/query/executor"
+ "github.com/apache/skywalking-banyandb/pkg/timestamp"
+)
+
+var _ UnresolvedPlan = (*unresolvedMeasureIndexScan)(nil)
+
+type unresolvedMeasureIndexScan struct {
+ startTime time.Time
+ endTime time.Time
+ metadata *commonv1.Metadata
+ conditions []Expr
+ projectionTags [][]*Tag
+ projectionFields []*Field
+ entity tsdb.Entity
+}
+
+func (uis *unresolvedMeasureIndexScan) Analyze(s Schema) (Plan, error) {
+ localConditionMap := make(map[*databasev1.IndexRule][]Expr)
+ for _, cond := range uis.conditions {
+ if resolvable, ok := cond.(ResolvableExpr); ok {
+ err := resolvable.Resolve(s)
+ if err != nil {
+ return nil, err
+ }
+
+ if bCond, ok := cond.(*binaryExpr); ok {
+ tag := bCond.l.(*TagRef).tag
+ if defined, indexObj := s.IndexDefined(tag); defined {
+ if indexObj.GetLocation() == databasev1.IndexRule_LOCATION_SERIES {
+ if v, exist := localConditionMap[indexObj]; exist {
+ v = append(v, cond)
+ localConditionMap[indexObj] = v
+ } else {
+ localConditionMap[indexObj] = []Expr{cond}
+ }
+ }
+ } else {
+ return nil, errors.Wrap(ErrIndexNotDefined, tag.GetCompoundName())
+ }
+ }
+ }
+ }
+
+ var projTagsRefs [][]*TagRef
+ if len(uis.projectionTags) > 0 {
+ var err error
+ projTagsRefs, err = s.CreateTagRef(uis.projectionTags...)
+ if err != nil {
+ return nil, err
+ }
+ }
+
+ var projFieldRefs []*FieldRef
+ if len(uis.projectionFields) > 0 {
+ var err error
+ projFieldRefs, err = s.CreateFieldRef(uis.projectionFields...)
+ if err != nil {
+ return nil, err
+ }
+ }
+
+ return &localMeasureIndexScan{
+ timeRange: timestamp.NewInclusiveTimeRange(uis.startTime, uis.endTime),
+ schema: s,
+ projectionTagsRefs: projTagsRefs,
+ projectionFieldsRefs: projFieldRefs,
+ metadata: uis.metadata,
+ conditionMap: localConditionMap,
+ entity: uis.entity,
+ }, nil
+}
+
+var _ Plan = (*localMeasureIndexScan)(nil)
+
+type localMeasureIndexScan struct {
+ timeRange timestamp.TimeRange
+ schema Schema
+ metadata *commonv1.Metadata
+ conditionMap map[*databasev1.IndexRule][]Expr
+ projectionTagsRefs [][]*TagRef
+ projectionFieldsRefs []*FieldRef
+ entity tsdb.Entity
+}
+
+func (i *localMeasureIndexScan) Execute(ec executor.MeasureExecutionContext) ([]*measurev1.DataPoint, error) {
+ shards, err := ec.Shards(i.entity)
+ if err != nil {
+ return nil, err
+ }
+ var iters []tsdb.Iterator
+ for _, shard := range shards {
+ itersInShard, innerErr := i.executeInShard(shard)
+ if innerErr != nil {
+ return nil, innerErr
+ }
+ if itersInShard == nil {
+ continue
+ }
+ iters = append(iters, itersInShard...)
+ }
+
+ var dataPoints []*measurev1.DataPoint
+
+ if len(iters) == 0 {
+ return dataPoints, nil
+ }
+
+ c := createComparator(modelv1.Sort_SORT_DESC)
+ it := NewItemIter(iters, c)
+ for it.HasNext() {
+ nextItem := it.Next()
+ tagFamilies, innerErr := projectItem(ec, nextItem, i.projectionTagsRefs)
+ if innerErr != nil {
+ return nil, innerErr
+ }
+ var dpFields []*measurev1.DataPoint_Field
+ for _, f := range i.projectionFieldsRefs {
+ fieldVal, parserFieldErr := ec.ParseField(f.field.name, nextItem)
+ if parserFieldErr != nil {
+ return nil, parserFieldErr
+ }
+ dpFields = append(dpFields, fieldVal)
+ }
+ dataPoints = append(dataPoints, &measurev1.DataPoint{
+ Fields: dpFields,
+ TagFamilies: tagFamilies,
+ Timestamp: timestamppb.New(time.Unix(0, int64(nextItem.Time()))),
+ })
+ }
+ return dataPoints, nil
+}
+
+func (i *localMeasureIndexScan) executeInShard(shard tsdb.Shard) ([]tsdb.Iterator, error) {
+ seriesList, err := shard.Series().List(tsdb.NewPath(i.entity))
+ if err != nil {
+ return nil, err
+ }
+
+ if len(seriesList) == 0 {
+ return nil, nil
+ }
+
+ var builders []seekerBuilder
+
+ // TODO: shall we support other sort options?
+ builders = append(builders, func(builder tsdb.SeekerBuilder) {
+ builder.OrderByTime(modelv1.Sort_SORT_DESC)
+ })
+
+ if i.conditionMap != nil && len(i.conditionMap) > 0 {
+ builders = append(builders, func(b tsdb.SeekerBuilder) {
+ for idxRule, exprs := range i.conditionMap {
+ b.Filter(idxRule, exprToCondition(exprs))
+ }
+ })
+ }
+
+ return executeForShard(seriesList, i.timeRange, builders...)
+}
+
+func (i *localMeasureIndexScan) String() string {
+ exprStr := make([]string, 0, len(i.conditionMap))
+ for _, conditions := range i.conditionMap {
+ var conditionStr []string
+ for _, cond := range conditions {
+ conditionStr = append(conditionStr, cond.String())
+ }
+ exprStr = append(exprStr, fmt.Sprintf("(%s)", strings.Join(conditionStr, " AND ")))
+ }
+ if len(i.projectionTagsRefs) == 0 {
+ return fmt.Sprintf("IndexScan: startTime=%d,endTime=%d,Metadata{group=%s,name=%s},conditions=%s; projection=None",
+ i.timeRange.Start.Unix(), i.timeRange.End.Unix(), i.metadata.GetGroup(), i.metadata.GetName(), strings.Join(exprStr, " AND "))
+ }
+ return fmt.Sprintf("IndexScan: startTime=%d,endTime=%d,Metadata{group=%s,name=%s},conditions=%s; projection=%s",
+ i.timeRange.Start.Unix(), i.timeRange.End.Unix(), i.metadata.GetGroup(), i.metadata.GetName(),
+ strings.Join(exprStr, " AND "), formatExpr(", ", i.projectionTagsRefs...))
+}
+
+func (i *localMeasureIndexScan) Type() PlanType {
+ return PlanLocalIndexScan
+}
+
+func (i *localMeasureIndexScan) Children() []Plan {
+ return []Plan{}
+}
+
+func (i *localMeasureIndexScan) Schema() Schema {
+ if len(i.projectionTagsRefs) == 0 {
+ return i.schema
+ }
+ return i.schema.Proj(i.projectionTagsRefs...)
+}
+
+func (i *localMeasureIndexScan) Equal(plan Plan) bool {
+ if plan.Type() != PlanLocalIndexScan {
+ return false
+ }
+ other := plan.(*localMeasureIndexScan)
+ return i.metadata.GetGroup() == other.metadata.GetGroup() &&
+ i.metadata.GetName() == other.metadata.GetName() &&
+ i.timeRange.Start.UnixNano() == other.timeRange.Start.UnixNano() &&
+ i.timeRange.End.UnixNano() == other.timeRange.End.UnixNano() &&
+ len(i.entity) == len(other.entity) &&
+ bytes.Equal(i.entity.Marshal(), other.entity.Marshal()) &&
+ cmp.Equal(i.projectionTagsRefs, other.projectionTagsRefs) &&
+ cmp.Equal(i.projectionFieldsRefs, other.projectionFieldsRefs) &&
+ cmp.Equal(i.schema, other.schema) &&
+ cmp.Equal(i.conditionMap, other.conditionMap)
+}
+
+func MeasureIndexScan(startTime, endTime time.Time, metadata *commonv1.Metadata, conditions []Expr, entity tsdb.Entity,
+ projectionTags [][]*Tag, projectionFields []*Field) UnresolvedPlan {
+ return &unresolvedMeasureIndexScan{
+ startTime: startTime,
+ endTime: endTime,
+ metadata: metadata,
+ conditions: conditions,
+ projectionTags: projectionTags,
+ projectionFields: projectionFields,
+ entity: entity,
+ }
+}
diff --git a/pkg/query/logical/plan_orderby.go b/pkg/query/logical/plan_orderby.go
index 9cfec41..1f9805f 100644
--- a/pkg/query/logical/plan_orderby.go
+++ b/pkg/query/logical/plan_orderby.go
@@ -54,10 +54,10 @@ func (u *UnresolvedOrderBy) analyze(s Schema) (*orderBy, error) {
return nil, errors.Wrap(ErrIndexNotDefined, u.targetIndexRuleName)
}
- projFieldSpecs, err := s.CreateRef(NewTags("", indexRule.GetTags()...))
+ projFieldSpecs, err := s.CreateTagRef(NewTags("", indexRule.GetTags()...))
if err != nil {
- return nil, ErrFieldNotDefined
+ return nil, ErrTagNotDefined
}
return &orderBy{
@@ -74,7 +74,7 @@ type orderBy struct {
// while orderBySort describes the sort direction
sort modelv1.Sort
// TODO: support multiple tags. Currently only the first member will be used for sorting.
- fieldRefs []*FieldRef
+ fieldRefs []*TagRef
}
func (o *orderBy) Equal(other interface{}) bool {
diff --git a/pkg/query/logical/schema.go b/pkg/query/logical/schema.go
index 1b81c1f..b8be5d7 100644
--- a/pkg/query/logical/schema.go
+++ b/pkg/query/logical/schema.go
@@ -31,10 +31,10 @@ type Schema interface {
EntityList() []string
IndexDefined(*Tag) (bool, *databasev1.IndexRule)
IndexRuleDefined(string) (bool, *databasev1.IndexRule)
- FieldSubscript(string) (bool, int)
- FieldDefined(string) bool
- CreateRef(tags ...[]*Tag) ([][]*FieldRef, error)
- Proj(refs ...[]*FieldRef) Schema
+ TagDefined(string) bool
+ CreateTagRef(tags ...[]*Tag) ([][]*TagRef, error)
+ CreateFieldRef(fields ...*Field) ([]*FieldRef, error)
+ Proj(refs ...[]*TagRef) Schema
Equal(Schema) bool
ShardNumber() uint32
TraceIDFieldName() string
@@ -42,7 +42,7 @@ type Schema interface {
type tagSpec struct {
// Idx is defined as
- // 1) the field index based on the (trace) schema for the underlying plans which
+ // 1) the field index based on the (stream/measure) schema for the underlying plans which
// directly interact with the database and index modules,
// 2) the projection index given by the users for those plans which can only access the data from parent plans,
// e.g. orderBy plan uses this projection index to access the data entities (normally a projection view)
@@ -57,37 +57,63 @@ func (fs *tagSpec) Equal(other *tagSpec) bool {
fs.spec.GetType() == other.spec.GetType() && fs.spec.GetName() == other.spec.GetName()
}
-var _ Schema = (*schema)(nil)
+var _ Schema = (*streamSchema)(nil)
-type schema struct {
+type commonSchema struct {
group *commonv1.Group
- stream *databasev1.Stream
indexRules []*databasev1.IndexRule
- fieldMap map[string]*tagSpec
+ tagMap map[string]*tagSpec
entityList []string
}
-func (s *schema) IndexRuleDefined(indexRuleName string) (bool, *databasev1.IndexRule) {
- for _, idxRule := range s.indexRules {
- if idxRule.GetMetadata().GetName() == indexRuleName {
- return true, idxRule
+func (cs *commonSchema) Proj(refs ...[]*TagRef) *commonSchema {
+ if len(refs) == 0 {
+ return nil
+ }
+ newCommonSchema := &commonSchema{
+ indexRules: cs.indexRules,
+ tagMap: make(map[string]*tagSpec),
+ entityList: cs.entityList,
+ }
+ for projFamilyIdx, refInFamily := range refs {
+ for projIdx, ref := range refInFamily {
+ newCommonSchema.tagMap[ref.tag.GetTagName()] = &tagSpec{
+ TagFamilyIdx: projFamilyIdx,
+ TagIdx: projIdx,
+ spec: ref.Spec.spec,
+ }
}
}
- return false, nil
+ return newCommonSchema
}
-func (s *schema) EntityList() []string {
- return s.entityList
+// registerTag registers the tag spec with given tagFamilyName, tagName and indexes.
+func (cs *commonSchema) registerTag(tagFamilyIdx, tagIdx int, spec *databasev1.TagSpec) {
+ cs.tagMap[spec.GetName()] = &tagSpec{
+ TagIdx: tagIdx,
+ TagFamilyIdx: tagFamilyIdx,
+ spec: spec,
+ }
}
-func (s *schema) TraceIDFieldName() string {
- // TODO: how to extract trace_id?
- return "trace_id"
+func (cs *commonSchema) ShardNumber() uint32 {
+ return cs.group.ResourceOpts.ShardNum
+}
+
+func (cs *commonSchema) EntityList() []string {
+ return cs.entityList
+}
+
+func (cs *commonSchema) TagDefined(name string) bool {
+ if _, ok := cs.tagMap[name]; ok {
+ return true
+ }
+ return false
}
// IndexDefined checks whether the field given is indexed
-func (s *schema) IndexDefined(tag *Tag) (bool, *databasev1.IndexRule) {
- for _, idxRule := range s.indexRules {
+func (cs *commonSchema) IndexDefined(tag *Tag) (bool, *databasev1.IndexRule) {
+ for _, idxRule := range cs.indexRules {
for _, tagName := range idxRule.GetTags() {
if tag.GetTagName() == tagName {
return true, idxRule
@@ -97,88 +123,192 @@ func (s *schema) IndexDefined(tag *Tag) (bool, *databasev1.IndexRule) {
return false, nil
}
-func (s *schema) FieldSubscript(field string) (bool, int) {
- // TODO: what does this mean
- for i, indexObj := range s.indexRules {
- for _, fieldName := range indexObj.GetTags() {
- if field == fieldName {
- return true, i
- }
+func (cs *commonSchema) IndexRuleDefined(indexRuleName string) (bool, *databasev1.IndexRule) {
+ for _, idxRule := range cs.indexRules {
+ if idxRule.GetMetadata().GetName() == indexRuleName {
+ return true, idxRule
}
}
- return false, -1
+ return false, nil
}
-func (s *schema) Equal(s2 Schema) bool {
- if other, ok := s2.(*schema); ok {
- return cmp.Equal(other.fieldMap, s.fieldMap)
+// CreateRef create TagRef to the given tags.
+// The family name of the tag is actually not used
+// since the uniqueness of the tag names can be guaranteed across families.
+func (cs *commonSchema) CreateRef(tags ...[]*Tag) ([][]*TagRef, error) {
+ tagRefs := make([][]*TagRef, len(tags))
+ for i, tagInFamily := range tags {
+ var tagRefsInFamily []*TagRef
+ for _, tag := range tagInFamily {
+ if ts, ok := cs.tagMap[tag.GetTagName()]; ok {
+ tagRefsInFamily = append(tagRefsInFamily, &TagRef{tag, ts})
+ } else {
+ return nil, errors.Wrap(ErrTagNotDefined, tag.GetCompoundName())
+ }
+ }
+ tagRefs[i] = tagRefsInFamily
}
- return false
+ return tagRefs, nil
}
-// registerField registers the field spec with given tagFamilyName, tagName and indexes.
-func (s *schema) registerField(tagName string, tagFamilyIdx, tagIdx int, spec *databasev1.TagSpec) {
- s.fieldMap[tagName] = &tagSpec{
- TagIdx: tagIdx,
- TagFamilyIdx: tagFamilyIdx,
- spec: spec,
- }
+type streamSchema struct {
+ stream *databasev1.Stream
+ common *commonSchema
}
-func (s *schema) FieldDefined(name string) bool {
- if _, ok := s.fieldMap[name]; ok {
- return true
+func (s *streamSchema) CreateFieldRef(fields ...*Field) ([]*FieldRef, error) {
+ panic("no field for stream")
+}
+
+func (s *streamSchema) TagDefined(tagName string) bool {
+ return s.common.TagDefined(tagName)
+}
+
+func (s *streamSchema) IndexRuleDefined(indexRuleName string) (bool, *databasev1.IndexRule) {
+ return s.common.IndexRuleDefined(indexRuleName)
+}
+
+func (s *streamSchema) EntityList() []string {
+ return s.common.EntityList()
+}
+
+func (s *streamSchema) TraceIDFieldName() string {
+ // TODO: how to extract trace_id?
+ return "trace_id"
+}
+
+// IndexDefined checks whether the field given is indexed
+func (s *streamSchema) IndexDefined(tag *Tag) (bool, *databasev1.IndexRule) {
+ return s.common.IndexDefined(tag)
+}
+
+func (s *streamSchema) Equal(s2 Schema) bool {
+ if other, ok := s2.(*streamSchema); ok {
+ return cmp.Equal(other.common.tagMap, s.common.tagMap)
}
return false
}
-// CreateRef create FieldRef to the given tags.
+// registerTag registers the tag spec with given tagFamilyName, tagName and indexes.
+func (s *streamSchema) registerTag(tagFamilyIdx, tagIdx int, spec *databasev1.TagSpec) {
+ s.common.registerTag(tagFamilyIdx, tagIdx, spec)
+}
+
+// CreateTagRef create TagRef to the given tags.
// The family name of the tag is actually not used
// since the uniqueness of the tag names can be guaranteed across families.
-func (s *schema) CreateRef(tags ...[]*Tag) ([][]*FieldRef, error) {
- fieldRefs := make([][]*FieldRef, len(tags))
- for i, tagInFamily := range tags {
- var fieldRefsInFamily []*FieldRef
- for _, tag := range tagInFamily {
- if fs, ok := s.fieldMap[tag.GetTagName()]; ok {
- fieldRefsInFamily = append(fieldRefsInFamily, &FieldRef{tag, fs})
- } else {
- return nil, errors.Wrap(ErrFieldNotDefined, tag.GetCompoundName())
- }
- }
- fieldRefs[i] = fieldRefsInFamily
- }
- return fieldRefs, nil
+func (s *streamSchema) CreateTagRef(tags ...[]*Tag) ([][]*TagRef, error) {
+ return s.common.CreateRef(tags...)
}
-// Proj creates a projection view from the present schema
+// Proj creates a projection view from the present streamSchema
// with a given list of projections
-func (s *schema) Proj(refs ...[]*FieldRef) Schema {
+func (s *streamSchema) Proj(refs ...[]*TagRef) Schema {
if len(refs) == 0 {
return nil
}
- newSchema := &schema{
- stream: s.stream,
- indexRules: s.indexRules,
- fieldMap: make(map[string]*tagSpec),
- entityList: s.entityList,
+ newSchema := &streamSchema{
+ stream: s.stream,
+ common: s.common.Proj(refs...),
}
- for projFamilyIdx, refInFamily := range refs {
- for projIdx, ref := range refInFamily {
- newSchema.fieldMap[ref.tag.GetTagName()] = &tagSpec{
- TagFamilyIdx: projFamilyIdx,
- TagIdx: projIdx,
- spec: ref.Spec.spec,
- }
+ return newSchema
+}
+
+func (s *streamSchema) ShardNumber() uint32 {
+ return s.common.ShardNumber()
+}
+
+func (s *streamSchema) Scope() tsdb.Entry {
+ return tsdb.Entry(s.stream.Metadata.Name)
+}
+
+var _ Schema = (*measureSchema)(nil)
+
+type fieldSpec struct {
+ FieldIdx int
+ spec *databasev1.FieldSpec
+}
+
+type measureSchema struct {
+ measure *databasev1.Measure
+ fieldMap map[string]*fieldSpec
+ common *commonSchema
+}
+
+func (m *measureSchema) Scope() tsdb.Entry {
+ return tsdb.Entry(m.measure.Metadata.Name)
+}
+
+func (m *measureSchema) EntityList() []string {
+ return m.common.EntityList()
+}
+
+func (m *measureSchema) IndexDefined(tag *Tag) (bool, *databasev1.IndexRule) {
+ return m.common.IndexDefined(tag)
+}
+
+func (m *measureSchema) IndexRuleDefined(indexRuleName string) (bool, *databasev1.IndexRule) {
+ return m.common.IndexRuleDefined(indexRuleName)
+}
+
+func (m *measureSchema) TagDefined(name string) bool {
+ return m.common.TagDefined(name)
+}
+
+func (m *measureSchema) CreateTagRef(tags ...[]*Tag) ([][]*TagRef, error) {
+ return m.common.CreateRef(tags...)
+}
+
+func (m *measureSchema) CreateFieldRef(fields ...*Field) ([]*FieldRef, error) {
+ fieldRefs := make([]*FieldRef, len(fields))
+ for idx, field := range fields {
+ if fs, ok := m.fieldMap[field.name]; ok {
+ fieldRefs[idx] = &FieldRef{field, fs}
+ } else {
+ return nil, errors.Wrap(ErrFieldNotDefined, field.name)
}
}
+ return fieldRefs, nil
+}
+
+func (m *measureSchema) Proj(refs ...[]*TagRef) Schema {
+ if len(refs) == 0 {
+ return nil
+ }
+ newSchema := &measureSchema{
+ measure: m.measure,
+ common: m.common.Proj(refs...),
+ fieldMap: m.fieldMap,
+ }
return newSchema
}
-func (s *schema) ShardNumber() uint32 {
- return s.group.ResourceOpts.ShardNum
+func (m *measureSchema) Equal(s2 Schema) bool {
+ if other, ok := s2.(*measureSchema); ok {
+ // TODO: add more equality checks
+ return cmp.Equal(other.common.tagMap, m.common.tagMap)
+ }
+ return false
}
-func (s *schema) Scope() tsdb.Entry {
- return tsdb.Entry(s.stream.Metadata.Name)
+func (m *measureSchema) ShardNumber() uint32 {
+ return m.common.ShardNumber()
+}
+
+// registerTag registers the tag spec with given tagFamilyIdx and tagIdx.
+func (m *measureSchema) registerTag(tagFamilyIdx, tagIdx int, spec *databasev1.TagSpec) {
+ m.common.registerTag(tagFamilyIdx, tagIdx, spec)
+}
+
+// registerField registers the field spec with given index.
+func (m *measureSchema) registerField(fieldIdx int, spec *databasev1.FieldSpec) {
+ m.fieldMap[spec.GetName()] = &fieldSpec{
+ FieldIdx: fieldIdx,
+ spec: spec,
+ }
+}
+
+func (m *measureSchema) TraceIDFieldName() string {
+ // We don't have traceID for measure
+ panic("implement me")
}
diff --git a/pkg/query/logical/analyzer.go b/pkg/query/logical/stream_analyzer.go
similarity index 80%
rename from pkg/query/logical/analyzer.go
rename to pkg/query/logical/stream_analyzer.go
index e9ce0b9..2a637fd 100644
--- a/pkg/query/logical/analyzer.go
+++ b/pkg/query/logical/stream_analyzer.go
@@ -20,8 +20,6 @@ package logical
import (
"context"
- "github.com/pkg/errors"
-
commonv1 "github.com/apache/skywalking-banyandb/api/proto/banyandb/common/v1"
modelv1 "github.com/apache/skywalking-banyandb/api/proto/banyandb/model/v1"
streamv1 "github.com/apache/skywalking-banyandb/api/proto/banyandb/stream/v1"
@@ -31,14 +29,6 @@ import (
)
var (
- ErrFieldNotDefined = errors.New("field is not defined")
- ErrInvalidConditionType = errors.New("invalid pair type")
- ErrIncompatibleQueryCondition = errors.New("incompatible query condition type")
- ErrIndexNotDefined = errors.New("index is not define for the field")
- ErrMultipleGlobalIndexes = errors.New("multiple global indexes are not supported")
-)
-
-var (
DefaultLimit uint32 = 100
)
@@ -75,17 +65,17 @@ func (t *Tag) GetFamilyName() string {
return t.familyName
}
-type Analyzer struct {
+type StreamAnalyzer struct {
metadataRepoImpl metadata.Repo
}
-func CreateAnalyzerFromMetaService(metaSvc metadata.Service) (*Analyzer, error) {
- return &Analyzer{
+func CreateStreamAnalyzerFromMetaService(metaSvc metadata.Service) (*StreamAnalyzer, error) {
+ return &StreamAnalyzer{
metaSvc,
}, nil
}
-func (a *Analyzer) BuildStreamSchema(ctx context.Context, metadata *commonv1.Metadata) (Schema, error) {
+func (a *StreamAnalyzer) BuildStreamSchema(ctx context.Context, metadata *commonv1.Metadata) (Schema, error) {
group, err := a.metadataRepoImpl.GroupRegistry().GetGroup(ctx, metadata.GetGroup())
if err != nil {
return nil, err
@@ -102,27 +92,29 @@ func (a *Analyzer) BuildStreamSchema(ctx context.Context, metadata *commonv1.Met
return nil, err
}
- s := &schema{
- group: group,
- stream: stream,
- indexRules: indexRules,
- fieldMap: make(map[string]*tagSpec),
- entityList: stream.GetEntity().GetTagNames(),
+ s := &streamSchema{
+ common: &commonSchema{
+ group: group,
+ indexRules: indexRules,
+ tagMap: make(map[string]*tagSpec),
+ entityList: stream.GetEntity().GetTagNames(),
+ },
+ stream: stream,
}
- // generate the schema of the fields for the traceSeries
+ // generate the streamSchema of the fields for the traceSeries
for tagFamilyIdx, tagFamily := range stream.GetTagFamilies() {
for tagIdx, spec := range tagFamily.GetTags() {
- s.registerField(spec.GetName(), tagFamilyIdx, tagIdx, spec)
+ s.registerTag(tagFamilyIdx, tagIdx, spec)
}
}
return s, nil
}
-func (a *Analyzer) Analyze(_ context.Context, criteria *streamv1.QueryRequest, metadata *commonv1.Metadata, s Schema) (Plan, error) {
+func (a *StreamAnalyzer) Analyze(_ context.Context, criteria *streamv1.QueryRequest, metadata *commonv1.Metadata, s Schema) (Plan, error) {
// parse fields
- plan, err := parseFields(criteria, metadata, s)
+ plan, err := parseStreamFields(criteria, metadata, s)
if err != nil {
return nil, err
}
@@ -130,7 +122,7 @@ func (a *Analyzer) Analyze(_ context.Context, criteria *streamv1.QueryRequest, m
// parse orderBy
queryOrder := criteria.GetOrderBy()
if queryOrder != nil {
- if v, ok := plan.(*unresolvedIndexScan); ok {
+ if v, ok := plan.(*unresolvedStreamIndexScan); ok {
v.unresolvedOrderBy = OrderBy(queryOrder.GetIndexRuleName(), queryOrder.GetSort())
}
}
@@ -152,9 +144,9 @@ func (a *Analyzer) Analyze(_ context.Context, criteria *streamv1.QueryRequest, m
// Basically,
// 1 - If no criteria is given, we can only scan all shards
// 2 - If criteria is given, but all of those fields exist in the "entity" definition,
-// i.e. they are top-level sharding keys. For example, for the current skywalking's schema,
+// i.e. they are top-level sharding keys. For example, for the current skywalking's streamSchema,
// we use service_id + service_instance_id + state as the compound sharding keys.
-func parseFields(criteria *streamv1.QueryRequest, metadata *commonv1.Metadata, s Schema) (UnresolvedPlan, error) {
+func parseStreamFields(criteria *streamv1.QueryRequest, metadata *commonv1.Metadata, s Schema) (UnresolvedPlan, error) {
timeRange := criteria.GetTimeRange()
projTags := make([][]*Tag, len(criteria.GetProjection().GetTagFamilies()))
diff --git a/pkg/query/logical/analyzer_test.go b/pkg/query/logical/stream_analyzer_test.go
similarity index 81%
rename from pkg/query/logical/analyzer_test.go
rename to pkg/query/logical/stream_analyzer_test.go
index dd976a8..45f6929 100644
--- a/pkg/query/logical/analyzer_test.go
+++ b/pkg/query/logical/stream_analyzer_test.go
@@ -34,9 +34,9 @@ import (
teststream "github.com/apache/skywalking-banyandb/pkg/test/stream"
)
-// setUpAnalyzer creates a default analyzer for testing.
+// setUpStreamAnalyzer creates a default analyzer for testing.
// You have to close the underlying metadata after teststream
-func setUpAnalyzer() (*logical.Analyzer, func(), error) {
+func setUpStreamAnalyzer() (*logical.StreamAnalyzer, func(), error) {
metadataService, err := metadata.NewService(context.TODO())
if err != nil {
return nil, func() {
@@ -63,7 +63,7 @@ func setUpAnalyzer() (*logical.Analyzer, func(), error) {
}, err
}
- ana, err := logical.CreateAnalyzerFromMetaService(metadataService)
+ ana, err := logical.CreateStreamAnalyzerFromMetaService(metadataService)
if err != nil {
return nil, func() {
}, err
@@ -74,17 +74,17 @@ func setUpAnalyzer() (*logical.Analyzer, func(), error) {
}, nil
}
-func TestAnalyzer_SimpleTimeScan(t *testing.T) {
+func TestStreamAnalyzer_SimpleTimeScan(t *testing.T) {
assert := require.New(t)
- ana, stopFunc, err := setUpAnalyzer()
+ ana, stopFunc, err := setUpStreamAnalyzer()
assert.NoError(err)
assert.NotNil(ana)
defer stopFunc()
sT, eT := time.Now().Add(-3*time.Hour), time.Now()
- criteria := pb.NewQueryRequestBuilder().
+ criteria := pb.NewStreamQueryRequestBuilder().
Limit(20).
Offset(0).
Metadata("default", "sw").
@@ -110,23 +110,23 @@ func TestAnalyzer_SimpleTimeScan(t *testing.T) {
assert.True(cmp.Equal(plan, correctPlan), "plan is not equal to correct plan")
}
-func TestAnalyzer_ComplexQuery(t *testing.T) {
+func TestStreamAnalyzer_ComplexQuery(t *testing.T) {
assert := require.New(t)
- ana, stopFunc, err := setUpAnalyzer()
+ ana, stopFunc, err := setUpStreamAnalyzer()
assert.NoError(err)
assert.NotNil(ana)
defer stopFunc()
sT, eT := time.Now().Add(-3*time.Hour), time.Now()
- criteria := pb.NewQueryRequestBuilder().
+ criteria := pb.NewStreamQueryRequestBuilder().
Limit(5).
Offset(10).
OrderBy("duration", modelv1.Sort_SORT_DESC).
Metadata("default", "sw").
Projection("searchable", "http.method", "service_id", "duration").
- FieldsInTagFamily("searchable", "service_id", "=", "my_app", "http.method", "=", "GET", "mq.topic", "=", "event_topic").
+ TagsInTagFamily("searchable", "service_id", "=", "my_app", "http.method", "=", "GET", "mq.topic", "=", "event_topic").
TimeRange(sT, eT).
Build()
@@ -156,19 +156,19 @@ func TestAnalyzer_ComplexQuery(t *testing.T) {
assert.True(cmp.Equal(plan, correctPlan), "plan is not equal to correct plan")
}
-func TestAnalyzer_TraceIDQuery(t *testing.T) {
+func TestStreamAnalyzer_TraceIDQuery(t *testing.T) {
assert := require.New(t)
- ana, stopFunc, err := setUpAnalyzer()
+ ana, stopFunc, err := setUpStreamAnalyzer()
assert.NoError(err)
assert.NotNil(ana)
defer stopFunc()
- criteria := pb.NewQueryRequestBuilder().
+ criteria := pb.NewStreamQueryRequestBuilder().
Limit(100).
Offset(0).
Metadata("default", "sw").
- FieldsInTagFamily("searchable", "trace_id", "=", "123").
+ TagsInTagFamily("searchable", "trace_id", "=", "123").
Build()
metadata := criteria.GetMetadata()
@@ -190,21 +190,21 @@ func TestAnalyzer_TraceIDQuery(t *testing.T) {
assert.True(cmp.Equal(plan, correctPlan), "plan is not equal to correct plan")
}
-func TestAnalyzer_OrderBy_IndexNotDefined(t *testing.T) {
+func TestStreamAnalyzer_OrderBy_IndexNotDefined(t *testing.T) {
assert := require.New(t)
- ana, stopFunc, err := setUpAnalyzer()
+ ana, stopFunc, err := setUpStreamAnalyzer()
assert.NoError(err)
assert.NotNil(ana)
defer stopFunc()
- criteria := pb.NewQueryRequestBuilder().
+ criteria := pb.NewStreamQueryRequestBuilder().
Limit(5).
Offset(10).
OrderBy("service_instance_id", modelv1.Sort_SORT_DESC).
Metadata("default", "sw").
Projection("searchable", "trace_id", "service_id").
- FieldsInTagFamily("searchable", "duration", ">", 500).
+ TagsInTagFamily("searchable", "duration", ">", 500).
TimeRange(time.Now().Add(-3*time.Hour), time.Now()).
Build()
@@ -217,15 +217,15 @@ func TestAnalyzer_OrderBy_IndexNotDefined(t *testing.T) {
assert.ErrorIs(err, logical.ErrIndexNotDefined)
}
-func TestAnalyzer_OrderBy_FieldNotDefined(t *testing.T) {
+func TestStreamAnalyzer_OrderBy_FieldNotDefined(t *testing.T) {
assert := require.New(t)
- ana, stopFunc, err := setUpAnalyzer()
+ ana, stopFunc, err := setUpStreamAnalyzer()
assert.NoError(err)
assert.NotNil(ana)
defer stopFunc()
- criteria := pb.NewQueryRequestBuilder().
+ criteria := pb.NewStreamQueryRequestBuilder().
Limit(5).
Offset(10).
OrderBy("duration2", modelv1.Sort_SORT_DESC).
@@ -243,15 +243,15 @@ func TestAnalyzer_OrderBy_FieldNotDefined(t *testing.T) {
assert.ErrorIs(err, logical.ErrIndexNotDefined)
}
-func TestAnalyzer_Projection_FieldNotDefined(t *testing.T) {
+func TestStreamAnalyzer_Projection_FieldNotDefined(t *testing.T) {
assert := require.New(t)
- ana, stopFunc, err := setUpAnalyzer()
+ ana, stopFunc, err := setUpStreamAnalyzer()
assert.NoError(err)
assert.NotNil(ana)
defer stopFunc()
- criteria := pb.NewQueryRequestBuilder().
+ criteria := pb.NewStreamQueryRequestBuilder().
Limit(5).
Offset(10).
OrderBy("duration", modelv1.Sort_SORT_DESC).
@@ -266,24 +266,24 @@ func TestAnalyzer_Projection_FieldNotDefined(t *testing.T) {
assert.NoError(err)
_, err = ana.Analyze(context.TODO(), criteria, metadata, schema)
- assert.ErrorIs(err, logical.ErrFieldNotDefined)
+ assert.ErrorIs(err, logical.ErrTagNotDefined)
}
-func TestAnalyzer_Fields_IndexNotDefined(t *testing.T) {
+func TestStreamAnalyzer_Fields_IndexNotDefined(t *testing.T) {
assert := require.New(t)
- ana, stopFunc, err := setUpAnalyzer()
+ ana, stopFunc, err := setUpStreamAnalyzer()
assert.NoError(err)
assert.NotNil(ana)
defer stopFunc()
- criteria := pb.NewQueryRequestBuilder().
+ criteria := pb.NewStreamQueryRequestBuilder().
Limit(5).
Offset(10).
Metadata("default", "sw").
Projection("duration", "service_id").
TimeRange(time.Now().Add(-3*time.Hour), time.Now()).
- FieldsInTagFamily("searchable", "start_time", ">", 10000).
+ TagsInTagFamily("searchable", "start_time", ">", 10000).
Build()
metadata := criteria.GetMetadata()
diff --git a/pkg/query/logical/plan.go b/pkg/query/logical/stream_plan.go
similarity index 90%
rename from pkg/query/logical/plan.go
rename to pkg/query/logical/stream_plan.go
index 33f40d6..9b0daaf 100644
--- a/pkg/query/logical/plan.go
+++ b/pkg/query/logical/stream_plan.go
@@ -37,8 +37,8 @@ type limit struct {
limitNum uint32
}
-func (l *limit) Execute(ec executor.ExecutionContext) ([]*streamv1.Element, error) {
- entities, err := l.parent.input.Execute(ec)
+func (l *limit) Execute(ec executor.StreamExecutionContext) ([]*streamv1.Element, error) {
+ entities, err := l.parent.input.(executor.StreamExecutable).Execute(ec)
if err != nil {
return nil, err
}
@@ -103,8 +103,8 @@ type offset struct {
offsetNum uint32
}
-func (l *offset) Execute(ec executor.ExecutionContext) ([]*streamv1.Element, error) {
- elements, err := l.parent.input.Execute(ec)
+func (l *offset) Execute(ec executor.StreamExecutionContext) ([]*streamv1.Element, error) {
+ elements, err := l.parent.input.(executor.StreamExecutable).Execute(ec)
if err != nil {
return nil, err
}
diff --git a/pkg/query/logical/plan_execution_test.go b/pkg/query/logical/stream_plan_execution_test.go
similarity index 92%
rename from pkg/query/logical/plan_execution_test.go
rename to pkg/query/logical/stream_plan_execution_test.go
index debd715..c88a2f8 100644
--- a/pkg/query/logical/plan_execution_test.go
+++ b/pkg/query/logical/stream_plan_execution_test.go
@@ -27,6 +27,7 @@ import (
commonv1 "github.com/apache/skywalking-banyandb/api/proto/banyandb/common/v1"
modelv1 "github.com/apache/skywalking-banyandb/api/proto/banyandb/model/v1"
"github.com/apache/skywalking-banyandb/banyand/tsdb"
+ "github.com/apache/skywalking-banyandb/pkg/query/executor"
"github.com/apache/skywalking-banyandb/pkg/query/logical"
)
@@ -43,7 +44,7 @@ func TestPlanExecution_TableScan_Limit(t *testing.T) {
sT, eT := baseTs, baseTs.Add(1*time.Hour)
- analyzer, err := logical.CreateAnalyzerFromMetaService(metaService)
+ analyzer, err := logical.CreateStreamAnalyzerFromMetaService(metaService)
tester.NoError(err)
tester.NotNil(analyzer)
@@ -79,7 +80,7 @@ func TestPlanExecution_TableScan_Limit(t *testing.T) {
tester.NoError(err)
tester.NotNil(plan)
- entities, err := plan.Execute(streamSvc)
+ entities, err := plan.(executor.StreamExecutable).Execute(streamSvc)
tester.NoError(err)
tester.Len(entities, tt.wantLength)
tester.True(logical.SortedByTimestamp(entities, modelv1.Sort_SORT_ASC))
@@ -100,7 +101,7 @@ func TestPlanExecution_Offset(t *testing.T) {
sT, eT := baseTs, baseTs.Add(1*time.Hour)
- analyzer, err := logical.CreateAnalyzerFromMetaService(metaService)
+ analyzer, err := logical.CreateStreamAnalyzerFromMetaService(metaService)
tester.NoError(err)
tester.NotNil(analyzer)
@@ -136,7 +137,7 @@ func TestPlanExecution_Offset(t *testing.T) {
tester.NoError(err)
tester.NotNil(plan)
- entities, err := plan.Execute(streamSvc)
+ entities, err := plan.(executor.StreamExecutable).Execute(streamSvc)
tester.NoError(err)
tester.Len(entities, tt.wantLength)
})
@@ -154,7 +155,7 @@ func TestPlanExecution_TraceIDFetch(t *testing.T) {
Group: "default",
}
- analyzer, err := logical.CreateAnalyzerFromMetaService(metaService)
+ analyzer, err := logical.CreateStreamAnalyzerFromMetaService(metaService)
tester.NoError(err)
tester.NotNil(analyzer)
@@ -191,7 +192,7 @@ func TestPlanExecution_TraceIDFetch(t *testing.T) {
}, logical.NewTags("searchable", "trace_id")).Analyze(s)
tester.NoError(err)
tester.NotNil(p)
- entities, err := p.Execute(streamSvc)
+ entities, err := p.(executor.StreamExecutable).Execute(streamSvc)
tester.NoError(err)
for _, entity := range entities {
tester.Len(entity.GetTagFamilies(), 1)
@@ -216,7 +217,7 @@ func TestPlanExecution_IndexScan(t *testing.T) {
sT, eT := baseTs, baseTs.Add(1*time.Hour)
- analyzer, err := logical.CreateAnalyzerFromMetaService(metaService)
+ analyzer, err := logical.CreateStreamAnalyzerFromMetaService(metaService)
tester.NoError(err)
tester.NotNil(analyzer)
@@ -289,7 +290,7 @@ func TestPlanExecution_IndexScan(t *testing.T) {
tester.NoError(err)
tester.NotNil(plan)
- entities, err := plan.Execute(streamSvc)
+ entities, err := plan.(executor.StreamExecutable).Execute(streamSvc)
tester.NoError(err)
tester.Len(entities, tt.wantLength)
})
@@ -309,7 +310,7 @@ func TestPlanExecution_OrderBy(t *testing.T) {
sT, eT := baseTs, baseTs.Add(1*time.Hour)
- analyzer, err := logical.CreateAnalyzerFromMetaService(metaService)
+ analyzer, err := logical.CreateStreamAnalyzerFromMetaService(metaService)
tester.NoError(err)
tester.NotNil(analyzer)
@@ -361,7 +362,7 @@ func TestPlanExecution_OrderBy(t *testing.T) {
tester.NoError(err)
tester.NotNil(p)
- entities, err := p.Execute(streamSvc)
+ entities, err := p.(executor.StreamExecutable).Execute(streamSvc)
tester.NoError(err)
tester.NotNil(entities)
@@ -373,7 +374,7 @@ func TestPlanExecution_OrderBy(t *testing.T) {
tester.NoError(err)
tester.NotNil(p)
- entities, err := p.Execute(streamSvc)
+ entities, err := p.(executor.StreamExecutable).Execute(streamSvc)
tester.NoError(err)
tester.NotNil(entities)
diff --git a/pkg/query/logical/plan_indexscan_global.go b/pkg/query/logical/stream_plan_indexscan_global.go
similarity index 94%
rename from pkg/query/logical/plan_indexscan_global.go
rename to pkg/query/logical/stream_plan_indexscan_global.go
index fb9e4a8..76a37ab 100644
--- a/pkg/query/logical/plan_indexscan_global.go
+++ b/pkg/query/logical/stream_plan_indexscan_global.go
@@ -41,7 +41,7 @@ type globalIndexScan struct {
metadata *commonv1.Metadata
globalIndexRule *databasev1.IndexRule
expr Expr
- projectionFieldRefs [][]*FieldRef
+ projectionFieldRefs [][]*TagRef
}
func (t *globalIndexScan) String() string {
@@ -79,7 +79,7 @@ func (t *globalIndexScan) Equal(plan Plan) bool {
cmp.Equal(t.expr, other.expr)
}
-func (t *globalIndexScan) Execute(ec executor.ExecutionContext) ([]*streamv1.Element, error) {
+func (t *globalIndexScan) Execute(ec executor.StreamExecutionContext) ([]*streamv1.Element, error) {
shards, err := ec.Shards(nil)
if err != nil {
return nil, err
@@ -95,7 +95,7 @@ func (t *globalIndexScan) Execute(ec executor.ExecutionContext) ([]*streamv1.Ele
return elements, nil
}
-func (t *globalIndexScan) executeForShard(ec executor.ExecutionContext, shard tsdb.Shard) ([]*streamv1.Element, error) {
+func (t *globalIndexScan) executeForShard(ec executor.StreamExecutionContext, shard tsdb.Shard) ([]*streamv1.Element, error) {
var elementsInShard []*streamv1.Element
itemIDs, err := shard.Index().Seek(index.Field{
Key: index.FieldKey{
diff --git a/pkg/query/logical/plan_indexscan_local.go b/pkg/query/logical/stream_plan_indexscan_local.go
similarity index 91%
rename from pkg/query/logical/plan_indexscan_local.go
rename to pkg/query/logical/stream_plan_indexscan_local.go
index 7e42d23..c795f64 100644
--- a/pkg/query/logical/plan_indexscan_local.go
+++ b/pkg/query/logical/stream_plan_indexscan_local.go
@@ -36,9 +36,9 @@ import (
"github.com/apache/skywalking-banyandb/pkg/timestamp"
)
-var _ UnresolvedPlan = (*unresolvedIndexScan)(nil)
+var _ UnresolvedPlan = (*unresolvedStreamIndexScan)(nil)
-type unresolvedIndexScan struct {
+type unresolvedStreamIndexScan struct {
unresolvedOrderBy *UnresolvedOrderBy
startTime time.Time
endTime time.Time
@@ -48,7 +48,7 @@ type unresolvedIndexScan struct {
entity tsdb.Entity
}
-func (uis *unresolvedIndexScan) Analyze(s Schema) (Plan, error) {
+func (uis *unresolvedStreamIndexScan) Analyze(s Schema) (Plan, error) {
localConditionMap := make(map[*databasev1.IndexRule][]Expr)
globalConditions := make([]interface{}, 0)
for _, cond := range uis.conditions {
@@ -59,7 +59,7 @@ func (uis *unresolvedIndexScan) Analyze(s Schema) (Plan, error) {
}
if bCond, ok := cond.(*binaryExpr); ok {
- tag := bCond.l.(*FieldRef).tag
+ tag := bCond.l.(*TagRef).tag
if defined, indexObj := s.IndexDefined(tag); defined {
if indexObj.GetLocation() == databasev1.IndexRule_LOCATION_SERIES {
if v, exist := localConditionMap[indexObj]; exist {
@@ -78,10 +78,10 @@ func (uis *unresolvedIndexScan) Analyze(s Schema) (Plan, error) {
}
}
- var projFieldsRefs [][]*FieldRef
- if uis.projectionFields != nil && len(uis.projectionFields) > 0 {
+ var projFieldsRefs [][]*TagRef
+ if len(uis.projectionFields) > 0 {
var err error
- projFieldsRefs, err = s.CreateRef(uis.projectionFields...)
+ projFieldsRefs, err = s.CreateTagRef(uis.projectionFields...)
if err != nil {
return nil, err
}
@@ -100,7 +100,7 @@ func (uis *unresolvedIndexScan) Analyze(s Schema) (Plan, error) {
}, nil
}
- // resolve sub-plan with the projected view of schema
+ // resolve sub-plan with the projected view of streamSchema
orderBySubPlan, err := uis.unresolvedOrderBy.analyze(s.Proj(projFieldsRefs...))
if err != nil {
@@ -126,11 +126,11 @@ type localIndexScan struct {
schema Schema
metadata *commonv1.Metadata
conditionMap map[*databasev1.IndexRule][]Expr
- projectionFieldRefs [][]*FieldRef
+ projectionFieldRefs [][]*TagRef
entity tsdb.Entity
}
-func (i *localIndexScan) Execute(ec executor.ExecutionContext) ([]*streamv1.Element, error) {
+func (i *localIndexScan) Execute(ec executor.StreamExecutionContext) ([]*streamv1.Element, error) {
shards, err := ec.Shards(i.entity)
if err != nil {
return nil, err
@@ -249,6 +249,7 @@ func (i *localIndexScan) Equal(plan Plan) bool {
i.metadata.GetName() == other.metadata.GetName() &&
i.timeRange.Start.UnixNano() == other.timeRange.Start.UnixNano() &&
i.timeRange.End.UnixNano() == other.timeRange.End.UnixNano() &&
+ len(i.entity) == len(other.entity) &&
bytes.Equal(i.entity.Marshal(), other.entity.Marshal()) &&
cmp.Equal(i.projectionFieldRefs, other.projectionFieldRefs) &&
cmp.Equal(i.schema, other.schema) &&
@@ -258,7 +259,7 @@ func (i *localIndexScan) Equal(plan Plan) bool {
func IndexScan(startTime, endTime time.Time, metadata *commonv1.Metadata, conditions []Expr, entity tsdb.Entity,
orderBy *UnresolvedOrderBy, projection ...[]*Tag) UnresolvedPlan {
- return &unresolvedIndexScan{
+ return &unresolvedStreamIndexScan{
unresolvedOrderBy: orderBy,
startTime: startTime,
endTime: endTime,
@@ -269,9 +270,9 @@ func IndexScan(startTime, endTime time.Time, metadata *commonv1.Metadata, condit
}
}
-// GlobalIndexScan is a short-hand method for composing a globalIndexScan plan
+// GlobalIndexScan is a short-handed method for composing a globalIndexScan plan
func GlobalIndexScan(metadata *commonv1.Metadata, conditions []Expr, projection ...[]*Tag) UnresolvedPlan {
- return &unresolvedIndexScan{
+ return &unresolvedStreamIndexScan{
metadata: metadata,
conditions: conditions,
projectionFields: projection,
@@ -282,7 +283,7 @@ func exprToCondition(exprs []Expr) tsdb.Condition {
cond := make(map[string][]index.ConditionValue)
for _, expr := range exprs {
bExpr := expr.(*binaryExpr)
- l := bExpr.l.(*FieldRef)
+ l := bExpr.l.(*TagRef)
r := bExpr.r.(LiteralExpr)
if existingList, ok := cond[l.tag.GetTagName()]; ok {
existingList = append(existingList, index.ConditionValue{
diff --git a/pkg/query/logical/testdata/measure_query_data.json b/pkg/query/logical/testdata/measure_query_data.json
new file mode 100644
index 0000000..4eb3e7e
--- /dev/null
+++ b/pkg/query/logical/testdata/measure_query_data.json
@@ -0,0 +1,107 @@
+[
+ {
+ "tag_families": [
+ {
+ "tags": [
+ {
+ "str": {
+ "value": "1"
+ }
+ },
+ {
+ "str": {
+ "value": "minute"
+ }
+ }
+ ]
+ }
+ ],
+ "fields": [
+ {
+ "int": {
+ "value": 100
+ }
+ },
+ {
+ "int": {
+ "value": 100
+ }
+ },
+ {
+ "int": {
+ "value": 1
+ }
+ }
+ ]
+ },
+ {
+ "tag_families": [
+ {
+ "tags": [
+ {
+ "str": {
+ "value": "1"
+ }
+ },
+ {
+ "str": {
+ "value": "minute"
+ }
+ }
+ ]
+ }
+ ],
+ "fields": [
+ {
+ "int": {
+ "value": 200
+ }
+ },
+ {
+ "int": {
+ "value": 50
+ }
+ },
+ {
+ "int": {
+ "value": 4
+ }
+ }
+ ]
+ },
+ {
+ "tag_families": [
+ {
+ "tags": [
+ {
+ "str": {
+ "value": "1"
+ }
+ },
+ {
+ "str": {
+ "value": "minute"
+ }
+ }
+ ]
+ }
+ ],
+ "fields": [
+ {
+ "int": {
+ "value": 150
+ }
+ },
+ {
+ "int": {
+ "value": 300
+ }
+ },
+ {
+ "int": {
+ "value": 5
+ }
+ }
+ ]
+ }
+]
\ No newline at end of file
diff --git a/pkg/test/measure/testdata/index_rule_binding.json b/pkg/test/measure/testdata/index_rule_binding.json
index 544e27f..89894d5 100644
--- a/pkg/test/measure/testdata/index_rule_binding.json
+++ b/pkg/test/measure/testdata/index_rule_binding.json
@@ -4,7 +4,7 @@
"group": "default"
},
"rules": [
- "entity_id"
+ "scope"
],
"subject":{
"catalog": "CATALOG_MEASURE",
diff --git a/pkg/test/measure/testdata/index_rules/entity_id.json b/pkg/test/measure/testdata/index_rules/scope.json
similarity index 81%
rename from pkg/test/measure/testdata/index_rules/entity_id.json
rename to pkg/test/measure/testdata/index_rules/scope.json
index bc8fbbe..50edf39 100644
--- a/pkg/test/measure/testdata/index_rules/entity_id.json
+++ b/pkg/test/measure/testdata/index_rules/scope.json
@@ -1,11 +1,11 @@
{
"metadata": {
"id": 1,
- "name": "entity_id",
+ "name": "scope",
"group": "default"
},
"tags": [
- "entity_id"
+ "scope"
],
"type": "TYPE_INVERTED",
"location": "LOCATION_SERIES",
diff --git a/pkg/test/measure/testdata/measure.json b/pkg/test/measure/testdata/measure.json
index 47e341a..1560419 100644
--- a/pkg/test/measure/testdata/measure.json
+++ b/pkg/test/measure/testdata/measure.json
@@ -14,6 +14,10 @@
{
"name": "scope",
"type": "TAG_TYPE_STRING"
+ },
+ {
+ "name": "unindexed-tag",
+ "type": "TAG_TYPE_INT"
}
]
}
diff --git a/scripts/build/base.mk b/scripts/build/base.mk
index 324a9c4..7f62f24 100644
--- a/scripts/build/base.mk
+++ b/scripts/build/base.mk
@@ -24,7 +24,7 @@ tool_include := "$(root_dir)/include"
uname_os := $(shell uname -s)
uname_arch := $(shell uname -m)
-buf_version ?= v1.0.0-rc10
+buf_version ?= v1.0.0
## Tools
BUF := $(tool_bin)/buf
@@ -36,7 +36,7 @@ $(BUF):
@rm -f $(tool_bin)/protoc-gen-buf-breaking
@rm -f $(tool_bin)/protoc-gen-buf-lint
@GOBIN=$(tool_bin) go install google.golang.org/protobuf/cmd/protoc-gen-go@v1.27.1
- @GOBIN=$(tool_bin) go install google.golang.org/grpc/cmd/protoc-gen-go-grpc@v1.1
+ @GOBIN=$(tool_bin) go install google.golang.org/grpc/cmd/protoc-gen-go-grpc@v1.2.0
@GOBIN=$(tool_bin) go install github.com/bufbuild/buf/cmd/buf@$(buf_version)
@GOBIN=$(tool_bin) go install github.com/bufbuild/buf/cmd/protoc-gen-buf-breaking@$(buf_version)
@GOBIN=$(tool_bin) go install github.com/bufbuild/buf/cmd/protoc-gen-buf-lint@$(buf_version)
@@ -57,7 +57,7 @@ PROTOC_GEN_GO_GRPC := $(tool_bin)/protoc-gen-go-grpc
$(PROTOC_GEN_GO_GRPC):
@echo "Install protoc gen go grpc..."
@mkdir -p $(tool_bin)
- @GOBIN=$(tool_bin) go install google.golang.org/grpc/cmd/protoc-gen-go-grpc@v1.1
+ @GOBIN=$(tool_bin) go install google.golang.org/grpc/cmd/protoc-gen-go-grpc@v1.2.0
.PHONY: clean
clean: