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/10/31 07:43:45 UTC
[skywalking-banyandb] branch main updated: Fix panic with single entity-related condition (#200)
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 6b34492 Fix panic with single entity-related condition (#200)
6b34492 is described below
commit 6b344929519dfd90203076e471fbf1136bde2262
Author: Gao Hongtao <ha...@gmail.com>
AuthorDate: Mon Oct 31 15:43:39 2022 +0800
Fix panic with single entity-related condition (#200)
* Fix invalid query
Signed-off-by: Gao Hongtao <ha...@gmail.com>
Co-authored-by: Jiajing LU <lu...@gmail.com>
---
pkg/query/logical/index_filter.go | 14 ++++++++++++--
test/cases/measure/data/input/entity.yaml | 10 +---------
.../data/input/{entity.yaml => entity_service.yaml} | 0
.../data/input/{entity.yaml => err_invalid_le.yaml} | 21 ++++-----------------
test/cases/measure/measure.go | 2 ++
5 files changed, 19 insertions(+), 28 deletions(-)
diff --git a/pkg/query/logical/index_filter.go b/pkg/query/logical/index_filter.go
index c92ecf8..a0194b3 100644
--- a/pkg/query/logical/index_filter.go
+++ b/pkg/query/logical/index_filter.go
@@ -35,8 +35,9 @@ import (
)
var (
- ErrNotRangeOperation = errors.New("this is not an range operation")
- ErrEmptyTree = errors.New("tree is empty")
+ ErrNotRangeOperation = errors.New("this is not an range operation")
+ ErrEmptyTree = errors.New("tree is empty")
+ ErrInvalidLogicalExpression = errors.New("invalid logical expression")
)
type GlobalIndexError struct {
@@ -72,6 +73,9 @@ func BuildLocalFilter(criteria *model_v1.Criteria, schema Schema, entityDict map
return eNode, []tsdb.Entity{entity}, nil
case *model_v1.Criteria_Le:
le := criteria.GetLe()
+ if le.GetLeft() == nil && le.GetRight() == nil {
+ return nil, nil, errors.WithMessagef(ErrInvalidLogicalExpression, "both sides(left and right) of [%v] are empty", criteria)
+ }
left, leftEntities, err := BuildLocalFilter(le.Left, schema, entityDict, entity)
if err != nil {
return nil, nil, err
@@ -84,6 +88,9 @@ func BuildLocalFilter(criteria *model_v1.Criteria, schema Schema, entityDict map
if entities == nil {
return nil, nil, nil
}
+ if left == nil && right == nil {
+ return nil, entities, nil
+ }
switch le.Op {
case model_v1.LogicalExpression_LOGICAL_OP_AND:
and := newAnd(2)
@@ -260,6 +267,9 @@ func (n *node) append(sub index.Filter) *node {
}
func execute(searcher index.GetSearcher, seriesID common.SeriesID, n *node, lp logicalOP) (posting.List, error) {
+ if len(n.SubNodes) < 1 {
+ return bList, nil
+ }
var result posting.List
for _, sn := range n.SubNodes {
r, err := sn.Execute(searcher, seriesID)
diff --git a/test/cases/measure/data/input/entity.yaml b/test/cases/measure/data/input/entity.yaml
index 9828d42..8a16c65 100644
--- a/test/cases/measure/data/input/entity.yaml
+++ b/test/cases/measure/data/input/entity.yaml
@@ -25,18 +25,10 @@ tagProjection:
criteria:
le:
op: "LOGICAL_OP_AND"
- right:
+ left:
condition:
name: "id"
op: "BINARY_OP_EQ"
value:
str:
value: "1"
- left:
- condition:
- name: "service_id"
- op: "BINARY_OP_EQ"
- value:
- str:
- value: "service_1"
-
diff --git a/test/cases/measure/data/input/entity.yaml b/test/cases/measure/data/input/entity_service.yaml
similarity index 100%
copy from test/cases/measure/data/input/entity.yaml
copy to test/cases/measure/data/input/entity_service.yaml
diff --git a/test/cases/measure/data/input/entity.yaml b/test/cases/measure/data/input/err_invalid_le.yaml
similarity index 73%
copy from test/cases/measure/data/input/entity.yaml
copy to test/cases/measure/data/input/err_invalid_le.yaml
index 9828d42..85fff59 100644
--- a/test/cases/measure/data/input/entity.yaml
+++ b/test/cases/measure/data/input/err_invalid_le.yaml
@@ -16,27 +16,14 @@
# under the License.
metadata:
- name: "service_traffic"
+ name: "service_cpm_minute"
group: "sw_metric"
tagProjection:
tagFamilies:
- name: "default"
- tags: ["id", "service_id"]
+ tags: ["id", "entity_id"]
+fieldProjection:
+ names: ["total", "value"]
criteria:
le:
op: "LOGICAL_OP_AND"
- right:
- condition:
- name: "id"
- op: "BINARY_OP_EQ"
- value:
- str:
- value: "1"
- left:
- condition:
- name: "service_id"
- op: "BINARY_OP_EQ"
- value:
- str:
- value: "service_1"
-
diff --git a/test/cases/measure/measure.go b/test/cases/measure/measure.go
index 2dbc9c2..6d0959c 100644
--- a/test/cases/measure/measure.go
+++ b/test/cases/measure/measure.go
@@ -52,5 +52,7 @@ var _ = g.DescribeTable("Scanning Measures", verify,
g.Entry("match a node", helpers.Args{Input: "match_node", Duration: 25 * time.Minute, Offset: -20 * time.Minute}),
g.Entry("match nodes", helpers.Args{Input: "match_nodes", Duration: 25 * time.Minute, Offset: -20 * time.Minute}),
g.Entry("filter by entity id", helpers.Args{Input: "entity", Duration: 25 * time.Minute, Offset: -20 * time.Minute}),
+ g.Entry("filter by entity id and service id", helpers.Args{Input: "entity_service", Want: "entity", Duration: 25 * time.Minute, Offset: -20 * time.Minute}),
g.Entry("without field", helpers.Args{Input: "no_field", Duration: 25 * time.Minute, Offset: -20 * time.Minute}),
+ g.Entry("invalid logical expression", helpers.Args{Input: "err_invalid_le", Duration: 25 * time.Minute, Offset: -20 * time.Minute, WantErr: true}),
)