skywalking icon indicating copy to clipboard operation
skywalking copied to clipboard

[BanyanDB] Support "IN" and "NOT IN" binary operation in criteria

Open hanahmily opened this issue 3 years ago • 5 comments

Search before asking

  • [X] I had searched in the issues and found no similar feature requirement.

Description

The query module should implement "IN" and "NOT IN" defined by APIs.

BTW, the OAP server doesn't need this operation for now.

Use case

No response

Related issues

No response

Are you willing to submit a PR?

  • [ ] Yes I am willing to submit a PR!

Code of Conduct

hanahmily avatar Oct 10 '22 12:10 hanahmily

Hello, @hanahmily I would like to contribute. Can you please provide some more info on the task?

DevPJ9 avatar Oct 14 '22 05:10 DevPJ9

@DevPJ9 You could split this task into several parts:

Add operations to API specification

Add IN and NOT_IN at https://github.com/apache/skywalking-banyandb/blob/main/api/proto/banyandb/model/v1/query.proto#L54

Parse added operations in index_filter

If the tag referred to by the binary expression is indexed, the index_filter will handle it.

Parse them at https://github.com/apache/skywalking-banyandb/blob/main/pkg/query/logical/index_filter.go#L102. You might notice that HAVING uses and nodes to construct the filter. Correspondingly, IN could leverage or node like

case model_v1.Condition_BINARY_OP_OR:
		bb := expr.Bytes()
		and := newOr(len(bb))
		for _, b := range bb {
			and.append(newEq(indexRule, newBytesLiteral(b)))
		}
		return and, []tsdb.Entity{entity}, nil

Parse operations in tag_filter

We also need to parse them at https://github.com/apache/skywalking-banyandb/blob/main/pkg/query/logical/tag_filter.go#L86. You should create a new orTag struct with Match like

func (h *orTag) Match(tagFamilies []*model_v1.TagFamily) (bool, error) {
	expr, err := tagExpr(tagFamilies, h.Name)
	if err != nil {
		return false, err
	}
	return expr.BelongTo(h.Expr), nil
}

Add test cases

Add integration test cases to https://github.com/apache/skywalking-banyandb/blob/main/test/cases/measure/measure.go and https://github.com/apache/skywalking-banyandb/blob/main/test/cases/stream/stream.go to verify the behaviors.

hanahmily avatar Oct 14 '22 10:10 hanahmily

Thanks, @hanahmily. I will start with the changes and will let you know If I get stuck. :)

DevPJ9 avatar Oct 14 '22 12:10 DevPJ9

Hello @hanahmily I have understood the requirement and I will do the changes and raise a PR, However, I have not worked with "go" language so I might do the changes wrong. Kindly guide me through those mistakes.

DevPJ9 avatar Oct 14 '22 15:10 DevPJ9

Hello @hanahmily I have raised a PR: https://github.com/apache/skywalking-banyandb/pull/191. Can you please review and about the tag_filter changes, I am sorry but I don't know how to proceed further.

DevPJ9 avatar Oct 14 '22 15:10 DevPJ9

Fixed by https://github.com/apache/skywalking-banyandb/pull/191

hanahmily avatar Dec 18 '22 14:12 hanahmily