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 03:44:36 UTC
[skywalking-banyandb] 01/01: Fix invalid query
This is an automated email from the ASF dual-hosted git repository.
hanahmily pushed a commit to branch 0.2.0-oap
in repository https://gitbox.apache.org/repos/asf/skywalking-banyandb.git
commit 747ddb6627f22b50548e9ea11216a783526ffae4
Author: Gao Hongtao <ha...@gmail.com>
AuthorDate: Mon Oct 31 03:44:02 2022 +0000
Fix invalid query
Signed-off-by: Gao Hongtao <ha...@gmail.com>
---
pkg/query/logical/index_filter.go | 12 ++++++++--
test/cases/measure/data/input/err_invalid_le.yaml | 29 +++++++++++++++++++++++
test/cases/measure/measure.go | 1 +
3 files changed, 40 insertions(+), 2 deletions(-)
diff --git a/pkg/query/logical/index_filter.go b/pkg/query/logical/index_filter.go
index c92ecf8..850a3d4 100644
--- a/pkg/query/logical/index_filter.go
+++ b/pkg/query/logical/index_filter.go
@@ -32,11 +32,13 @@ import (
"github.com/apache/skywalking-banyandb/pkg/convert"
"github.com/apache/skywalking-banyandb/pkg/index"
"github.com/apache/skywalking-banyandb/pkg/index/posting"
+ "github.com/apache/skywalking-banyandb/pkg/index/posting/roaring"
)
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 +74,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
@@ -260,6 +265,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 roaring.EmptyPostingList, nil
+ }
var result posting.List
for _, sn := range n.SubNodes {
r, err := sn.Execute(searcher, seriesID)
diff --git a/test/cases/measure/data/input/err_invalid_le.yaml b/test/cases/measure/data/input/err_invalid_le.yaml
new file mode 100644
index 0000000..85fff59
--- /dev/null
+++ b/test/cases/measure/data/input/err_invalid_le.yaml
@@ -0,0 +1,29 @@
+# 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.
+
+metadata:
+ name: "service_cpm_minute"
+ group: "sw_metric"
+tagProjection:
+ tagFamilies:
+ - name: "default"
+ tags: ["id", "entity_id"]
+fieldProjection:
+ names: ["total", "value"]
+criteria:
+ le:
+ op: "LOGICAL_OP_AND"
diff --git a/test/cases/measure/measure.go b/test/cases/measure/measure.go
index 2dbc9c2..f7ff0f5 100644
--- a/test/cases/measure/measure.go
+++ b/test/cases/measure/measure.go
@@ -53,4 +53,5 @@ var _ = g.DescribeTable("Scanning Measures", verify,
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("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}),
)