You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@skywalking.apache.org by "zesiar0 (via GitHub)" <gi...@apache.org> on 2023/10/16 18:20:42 UTC
[PR] re: Unify topn&query plan [skywalking-banyandb]
zesiar0 opened a new pull request, #343:
URL: https://github.com/apache/skywalking-banyandb/pull/343
related issue https://github.com/apache/skywalking/issues/10562.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@skywalking.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] re: Unify topn&query plan [skywalking-banyandb]
Posted by "lujiajing1126 (via GitHub)" <gi...@apache.org>.
lujiajing1126 commented on code in PR #343:
URL: https://github.com/apache/skywalking-banyandb/pull/343#discussion_r1373165162
##########
pkg/query/logical/measure/topn_analyzer.go:
##########
@@ -0,0 +1,95 @@
+// 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 measure implements execution operations for querying measure data.
+package measure
+
+import (
+ "context"
+
+ 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"
+ "github.com/apache/skywalking-banyandb/pkg/query/logical"
+)
+
+// BuildTopNSchema returns Schema loaded from the metadata repository.
+func BuildTopNSchema(md *databasev1.Measure, entityList []string) (logical.Schema, error) {
+ md.GetEntity()
+
+ ms := &schema{
+ common: &logical.CommonSchema{
+ TagSpecMap: make(map[string]*logical.TagSpec),
+ EntityList: entityList,
+ },
+ measure: md,
+ fieldMap: make(map[string]*logical.FieldSpec),
+ }
+
+ ms.common.RegisterTagFamilies(md.GetTagFamilies())
+
+ for fieldIdx, spec := range md.GetFields() {
+ ms.registerField(fieldIdx, spec)
+ }
+
+ return ms, nil
+}
+
+// TopNAnalyze converts logical expressions to executable operation tree represented by Plan.
+func TopNAnalyze(_ context.Context, criteria *measurev1.TopNRequest, schema *databasev1.Measure,
+ topNAggregation *databasev1.TopNAggregation, s logical.Schema,
+) (logical.Plan, error) {
+ groupByProjectionTags := schema.GetEntity().GetTagNames()
+ groupByTags := make([][]*logical.Tag, len(schema.GetTagFamilies()))
+ for i, tagFamily := range schema.GetTagFamilies() {
Review Comment:
This is strange, why we need to assemble groupByTags for all tag families?
```go
groupByTags[0] = logical.NewTags(tagFamily.GetName(), groupByProjectionTags...)
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@skywalking.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] re: Unify topn&query plan [skywalking-banyandb]
Posted by "lujiajing1126 (via GitHub)" <gi...@apache.org>.
lujiajing1126 commented on code in PR #343:
URL: https://github.com/apache/skywalking-banyandb/pull/343#discussion_r1373141844
##########
banyand/measure/metadata.go:
##########
@@ -217,6 +217,7 @@ func createOrUpdateTopNMeasure(ctx context.Context, measureSchemaRegistry schema
},
},
Fields: []*databasev1.FieldSpec{TopNValueFieldSpec},
+ Entity: sourceMeasureSchema.GetEntity(),
Review Comment:
Source measure entity has a offset of 3
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@skywalking.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] re: Unify topn&query plan [skywalking-banyandb]
Posted by "lujiajing1126 (via GitHub)" <gi...@apache.org>.
lujiajing1126 commented on code in PR #343:
URL: https://github.com/apache/skywalking-banyandb/pull/343#discussion_r1373141844
##########
banyand/measure/metadata.go:
##########
@@ -217,6 +217,7 @@ func createOrUpdateTopNMeasure(ctx context.Context, measureSchemaRegistry schema
},
},
Fields: []*databasev1.FieldSpec{TopNValueFieldSpec},
+ Entity: sourceMeasureSchema.GetEntity(),
Review Comment:
Source measure entity has a offset of 3 (with a companion prefix) or 2 (wo/ prefix)
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@skywalking.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] re: Unify topn&query plan [skywalking-banyandb]
Posted by "lujiajing1126 (via GitHub)" <gi...@apache.org>.
lujiajing1126 commented on code in PR #343:
URL: https://github.com/apache/skywalking-banyandb/pull/343#discussion_r1373141844
##########
banyand/measure/metadata.go:
##########
@@ -217,6 +217,7 @@ func createOrUpdateTopNMeasure(ctx context.Context, measureSchemaRegistry schema
},
},
Fields: []*databasev1.FieldSpec{TopNValueFieldSpec},
+ Entity: sourceMeasureSchema.GetEntity(),
Review Comment:
Source measure entity has a offset of 3 (with a companion prefix) or 2 (wo/ prefix)
What about
```go
Entity: append([]string{"__sort_direction__", "__rank__"}, sourceMeasureSchema.GetEntity()...)
```
Then we may convert sort (uint64) into a kind of criteria in the query.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@skywalking.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] re: Unify topn&query plan [skywalking-banyandb]
Posted by "lujiajing1126 (via GitHub)" <gi...@apache.org>.
lujiajing1126 commented on code in PR #343:
URL: https://github.com/apache/skywalking-banyandb/pull/343#discussion_r1368665642
##########
banyand/measure/measure_query.go:
##########
@@ -54,10 +54,25 @@ type Measure interface {
GetSchema() *databasev1.Measure
GetIndexRules() []*databasev1.IndexRule
GetInterval() time.Duration
+ BuildSchema(other Measure) *databasev1.Measure
}
var _ Measure = (*measure)(nil)
+func (s *measure) BuildSchema(other Measure) *databasev1.Measure {
Review Comment:
According to our last discussion, we should build topN schema with entity names,
https://github.com/apache/skywalking-banyandb/blob/d722db6bcd52554ef429961600d617d28d561ae5/banyand/measure/metadata.go#L204-L220
The actual entity names written for the TopN data point can be found,
https://github.com/apache/skywalking-banyandb/blob/d722db6bcd52554ef429961600d617d28d561ae5/banyand/measure/measure_topn.go#L233-L247
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@skywalking.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] re: Unify topn&query plan [skywalking-banyandb]
Posted by "lujiajing1126 (via GitHub)" <gi...@apache.org>.
lujiajing1126 commented on code in PR #343:
URL: https://github.com/apache/skywalking-banyandb/pull/343#discussion_r1373141844
##########
banyand/measure/metadata.go:
##########
@@ -217,6 +217,7 @@ func createOrUpdateTopNMeasure(ctx context.Context, measureSchemaRegistry schema
},
},
Fields: []*databasev1.FieldSpec{TopNValueFieldSpec},
+ Entity: sourceMeasureSchema.GetEntity(),
Review Comment:
Source measure entity has a offset of 3 (with a companion prefix) or 2 (wo/ prefix)
What about
```go
Entity: append([]string{"sort", "rank"}, sourceMeasureSchema.GetEntity()...)
```
Then
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@skywalking.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] re: Unify topn&query plan [skywalking-banyandb]
Posted by "codecov-commenter (via GitHub)" <gi...@apache.org>.
codecov-commenter commented on PR #343:
URL: https://github.com/apache/skywalking-banyandb/pull/343#issuecomment-1767907168
## [Codecov](https://app.codecov.io/gh/apache/skywalking-banyandb/pull/343?src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) Report
> Merging [#343](https://app.codecov.io/gh/apache/skywalking-banyandb/pull/343?src=pr&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) (afa38f9) into [main](https://app.codecov.io/gh/apache/skywalking-banyandb/commit/d043b3af6e228c583c043c6dcccf5025db022378?el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) (d043b3a) will **decrease** coverage by `0.65%`.
> Report is 2 commits behind head on main.
> The diff coverage is `0.00%`.
```diff
@@ Coverage Diff @@
## main #343 +/- ##
==========================================
- Coverage 39.32% 38.67% -0.65%
==========================================
Files 112 114 +2
Lines 12329 12535 +206
==========================================
Hits 4848 4848
- Misses 7003 7209 +206
Partials 478 478
```
| [Files](https://app.codecov.io/gh/apache/skywalking-banyandb/pull/343?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | Coverage Δ | |
|---|---|---|
| [banyand/measure/measure\_query.go](https://app.codecov.io/gh/apache/skywalking-banyandb/pull/343?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache#diff-YmFueWFuZC9tZWFzdXJlL21lYXN1cmVfcXVlcnkuZ28=) | `0.00% <0.00%> (ø)` | |
| [pkg/query/logical/measure/topn\_analyzer.go](https://app.codecov.io/gh/apache/skywalking-banyandb/pull/343?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache#diff-cGtnL3F1ZXJ5L2xvZ2ljYWwvbWVhc3VyZS90b3BuX2FuYWx5emVyLmdv) | `0.00% <0.00%> (ø)` | |
| [pkg/query/logical/measure/topn\_plan\_localscan.go](https://app.codecov.io/gh/apache/skywalking-banyandb/pull/343?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache#diff-cGtnL3F1ZXJ5L2xvZ2ljYWwvbWVhc3VyZS90b3BuX3BsYW5fbG9jYWxzY2FuLmdv) | `0.00% <0.00%> (ø)` | |
:mega: We’re building smart automated test selection to slash your CI/CD build times. [Learn more](https://about.codecov.io/iterative-testing/?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache)
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@skywalking.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] re: Unify topn&query plan [skywalking-banyandb]
Posted by "lujiajing1126 (via GitHub)" <gi...@apache.org>.
lujiajing1126 commented on code in PR #343:
URL: https://github.com/apache/skywalking-banyandb/pull/343#discussion_r1373141844
##########
banyand/measure/metadata.go:
##########
@@ -217,6 +217,7 @@ func createOrUpdateTopNMeasure(ctx context.Context, measureSchemaRegistry schema
},
},
Fields: []*databasev1.FieldSpec{TopNValueFieldSpec},
+ Entity: sourceMeasureSchema.GetEntity(),
Review Comment:
Source measure entity has a offset of 3 (with a companion prefix) or 2 (wo/ prefix)
What about
```go
Entity: append([]string{"__sort_direction__", "__rank__"}, sourceMeasureSchema.GetEntity()...)
```
Then we may convert sort (uint64) into a kind of criteria in the query. This may make the query scan more consistent.
##########
banyand/measure/metadata.go:
##########
@@ -217,6 +217,7 @@ func createOrUpdateTopNMeasure(ctx context.Context, measureSchemaRegistry schema
},
},
Fields: []*databasev1.FieldSpec{TopNValueFieldSpec},
+ Entity: sourceMeasureSchema.GetEntity(),
Review Comment:
Source measure entity has a offset of 3 (with a companion prefix) or 2 (wo/ prefix)
What about
```go
Entity: append([]string{"__sort_direction__", "__rank__"}, sourceMeasureSchema.GetEntity()...)
```
Then we may convert sort (uint64) into a kind of criteria in the query. This could make the query scan more consistent.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@skywalking.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] re: Unify topn&query plan [skywalking-banyandb]
Posted by "lujiajing1126 (via GitHub)" <gi...@apache.org>.
lujiajing1126 merged PR #343:
URL: https://github.com/apache/skywalking-banyandb/pull/343
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@skywalking.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] re: Unify topn&query plan [skywalking-banyandb]
Posted by "lujiajing1126 (via GitHub)" <gi...@apache.org>.
lujiajing1126 commented on code in PR #343:
URL: https://github.com/apache/skywalking-banyandb/pull/343#discussion_r1373183858
##########
pkg/query/logical/measure/topn_plan_localscan.go:
##########
@@ -0,0 +1,254 @@
+// 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 measure implements execution operations for querying measure data.
+package measure
+
+import (
+ "context"
+ "fmt"
+ "io"
+ "time"
+
+ "github.com/pkg/errors"
+ "go.uber.org/multierr"
+
+ 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"
+ "github.com/apache/skywalking-banyandb/banyand/measure"
+ "github.com/apache/skywalking-banyandb/banyand/tsdb"
+ "github.com/apache/skywalking-banyandb/pkg/convert"
+ "github.com/apache/skywalking-banyandb/pkg/iter/sort"
+ "github.com/apache/skywalking-banyandb/pkg/logger"
+ "github.com/apache/skywalking-banyandb/pkg/query/executor"
+ "github.com/apache/skywalking-banyandb/pkg/query/logical"
+ "github.com/apache/skywalking-banyandb/pkg/timestamp"
+)
+
+var _ logical.UnresolvedPlan = (*unresolvedLocalScan)(nil)
+
+type unresolvedLocalScan struct {
+ startTime time.Time
+ endTime time.Time
+ metadata *commonv1.Metadata
+ conditions []*modelv1.Condition
+ projectionTags [][]*logical.Tag
+ projectionFields []*logical.Field
+ sort modelv1.Sort
+}
+
+func (uls *unresolvedLocalScan) Analyze(s logical.Schema) (logical.Plan, error) {
+ var projTagsRefs [][]*logical.TagRef
+ if len(uls.projectionTags) > 0 {
+ var err error
+ projTagsRefs, err = s.CreateTagRef(uls.projectionTags...)
+ if err != nil {
+ return nil, err
+ }
+ }
+
+ var projFieldRefs []*logical.FieldRef
+ if len(uls.projectionFields) > 0 {
+ var err error
+ projFieldRefs, err = s.CreateFieldRef(uls.projectionFields...)
+ if err != nil {
+ return nil, err
+ }
+ }
+
+ entity, err := uls.locateEntity(s.EntityList())
+ if err != nil {
+ return nil, err
+ }
+
+ return &localScan{
+ timeRange: timestamp.NewInclusiveTimeRange(uls.startTime, uls.endTime),
+ schema: s,
+ projectionTagsRefs: projTagsRefs,
+ projectionFieldsRefs: projFieldRefs,
+ metadata: uls.metadata,
+ entity: entity,
+ l: logger.GetLogger("topn", "measure", uls.metadata.Group, uls.metadata.Name, "local-index"),
+ }, nil
+}
+
+func (uls *unresolvedLocalScan) locateEntity(entityList []string) (tsdb.Entity, error) {
+ entityMap := make(map[string]int)
+ entity := make([]tsdb.Entry, 1+1+len(entityList))
Review Comment:
Then (continued...)
```go
entity := make([]tsdb.Entry, len(entityList))
for idx, tagName := range entityList {
if tagName == "rank" {}
else if tagName == "sort" {}
else {
entityMap[tagName] = idx
// allow to make fuzzy search with partial conditions
entity[idx] = tsdb.AnyEntry
}
}
```
##########
pkg/query/logical/measure/topn_analyzer.go:
##########
@@ -0,0 +1,95 @@
+// 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 measure implements execution operations for querying measure data.
+package measure
+
+import (
+ "context"
+
+ 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"
+ "github.com/apache/skywalking-banyandb/pkg/query/logical"
+)
+
+// BuildTopNSchema returns Schema loaded from the metadata repository.
+func BuildTopNSchema(md *databasev1.Measure, entityList []string) (logical.Schema, error) {
+ md.GetEntity()
+
+ ms := &schema{
+ common: &logical.CommonSchema{
+ TagSpecMap: make(map[string]*logical.TagSpec),
+ EntityList: entityList,
+ },
+ measure: md,
+ fieldMap: make(map[string]*logical.FieldSpec),
+ }
+
+ ms.common.RegisterTagFamilies(md.GetTagFamilies())
+
+ for fieldIdx, spec := range md.GetFields() {
+ ms.registerField(fieldIdx, spec)
+ }
+
+ return ms, nil
+}
+
+// TopNAnalyze converts logical expressions to executable operation tree represented by Plan.
+func TopNAnalyze(_ context.Context, criteria *measurev1.TopNRequest, schema *databasev1.Measure,
+ topNAggregation *databasev1.TopNAggregation, s logical.Schema,
+) (logical.Plan, error) {
+ groupByProjectionTags := schema.GetEntity().GetTagNames()
+ groupByTags := make([][]*logical.Tag, len(schema.GetTagFamilies()))
+ for i, tagFamily := range schema.GetTagFamilies() {
Review Comment:
This is strange, why we need to assemble groupByTags for all tag families?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@skywalking.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org