You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@skywalking.apache.org by GitBox <gi...@apache.org> on 2021/07/30 02:51:31 UTC
[GitHub] [skywalking-banyandb] hanahmily commented on a change in pull request #18: Process query from liaison
hanahmily commented on a change in pull request #18:
URL: https://github.com/apache/skywalking-banyandb/pull/18#discussion_r679608510
##########
File path: pkg/query/logical/analyzer.go
##########
@@ -94,14 +95,17 @@ func (a *Analyzer) Analyze(_ context.Context, criteria *apiv1.QueryRequest, trac
useIndexScan := false
var fieldExprs []Expr
traceState := series.TraceStateDefault
+
for _, pairQuery := range criteria.GetFields() {
op := pairQuery.GetOp()
typedPair := pairQuery.GetCondition()
switch v := typedPair.GetTyped().(type) {
case *apiv1.TypedPair_StrPair:
+ // TODO: use metadata from Plugin?
Review comment:
Retrieving the key from https://github.com/apache/skywalking-banyandb/blob/main/banyand/series/schema/sw/trace_series.textproto#L75
##########
File path: banyand/query/processor.go
##########
@@ -0,0 +1,96 @@
+// 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 query
+
+import (
+ "context"
+ "time"
+
+ "github.com/apache/skywalking-banyandb/api/common"
+ "github.com/apache/skywalking-banyandb/api/event"
+ v1 "github.com/apache/skywalking-banyandb/api/proto/banyandb/v1"
+ apischema "github.com/apache/skywalking-banyandb/api/schema"
+ "github.com/apache/skywalking-banyandb/banyand/discovery"
+ "github.com/apache/skywalking-banyandb/banyand/index"
+ "github.com/apache/skywalking-banyandb/banyand/series"
+ "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"
+)
+
+const (
+ moduleName = "query-processor"
+)
+
+var (
+ _ Executor = (*queryProcessor)(nil)
+ _ bus.MessageListener = (*queryProcessor)(nil)
+ _ executor.ExecutionContext = (*queryProcessor)(nil)
+)
+
+type queryProcessor struct {
+ index.Repo
+ series.UniModel
+ schemaRepo series.SchemaRepo
+ log *logger.Logger
+ serviceRepo discovery.ServiceRepo
+}
+
+func (q *queryProcessor) Rev(message bus.Message) (resp bus.Message) {
+ queryCriteria, ok := message.Data().(*v1.QueryRequest)
+ if !ok {
+ q.log.Warn().Msg("invalid event data type")
+ return
+ }
+ q.log.Info().
+ Msg("received a query event")
+ analyzer := logical.DefaultAnalyzer()
+ metadata := &common.Metadata{
+ KindVersion: apischema.SeriesKindVersion,
+ Spec: queryCriteria.GetMetadata(),
+ }
+ s, err := analyzer.BuildTraceSchema(context.TODO(), *metadata)
+ if err != nil {
Review comment:
Do we have to log this error if we don't handle it under the hood?
##########
File path: pkg/query/logical/plan_indexscan.go
##########
@@ -107,31 +107,49 @@ type indexScan struct {
traceState series.TraceState
}
-func (i *indexScan) Execute(ec executor2.ExecutionContext) ([]data.Entity, error) {
- var chunkSet posting.List
- for _, exprs := range i.conditionMap {
- // TODO: Discuss which metadata should be used!
- // 1) traceSeries Metadata: indirect mapping
- // 2) indexRule Metadata: cannot uniquely determine traceSeries
- // TODO: should pass correct shardID
- chunks, err := ec.Search(*i.traceMetadata, 0, uint64(i.startTime), uint64(i.endTime), convertToConditions(exprs))
+func (i *indexScan) Execute(ec executor.ExecutionContext) ([]data.Entity, error) {
+ dataEntities := make([]data.Entity, 0)
+
+ // iterate over shards
+ for shardID := uint32(0); shardID < i.schema.ShardNumber(); shardID++ {
+ var chunkSet posting.List
+
+ // first collect all chunkIDs via indexes
+ for idxObj, exprs := range i.conditionMap {
+ // 1) traceSeries Metadata -> IndexObject
+ // 2) IndexObject -> Fields
+ chunks, err := ec.Search(*i.traceMetadata, uint(shardID), uint64(i.startTime), uint64(i.endTime), idxObj.GetName(), convertToConditions(exprs))
+ if err != nil {
+ return nil, err
+ }
+ if chunkSet == nil {
+ // chunkSet is nil before the first assignment
+ chunkSet = chunks
+ } else {
+ // afterwards, it must not be nil
+ _ = chunkSet.Intersect(chunks)
Review comment:
Once the result of the intersection is empty, you can stop the loop immediately.
##########
File path: pkg/query/logical/plan_indexscan.go
##########
@@ -107,31 +107,49 @@ type indexScan struct {
traceState series.TraceState
}
-func (i *indexScan) Execute(ec executor2.ExecutionContext) ([]data.Entity, error) {
- var chunkSet posting.List
- for _, exprs := range i.conditionMap {
- // TODO: Discuss which metadata should be used!
- // 1) traceSeries Metadata: indirect mapping
- // 2) indexRule Metadata: cannot uniquely determine traceSeries
- // TODO: should pass correct shardID
- chunks, err := ec.Search(*i.traceMetadata, 0, uint64(i.startTime), uint64(i.endTime), convertToConditions(exprs))
+func (i *indexScan) Execute(ec executor.ExecutionContext) ([]data.Entity, error) {
+ dataEntities := make([]data.Entity, 0)
+
+ // iterate over shards
+ for shardID := uint32(0); shardID < i.schema.ShardNumber(); shardID++ {
Review comment:
Can we stop scanning when the limitation of results is reached?
--
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