hanahmily commented on code in PR #821:
URL: 
https://github.com/apache/skywalking-banyandb/pull/821#discussion_r2453935174


##########
test/cases/topn/data/data.go:
##########
@@ -94,3 +108,86 @@ var VerifyFn = func(innerGm gm.Gomega, sharedContext 
helpers.SharedContext, args
        innerGm.Expect(resp.Trace).NotTo(gm.BeNil())
        innerGm.Expect(resp.Trace.GetSpans()).NotTo(gm.BeEmpty())
 }
+
+// verifyQLWithRequest verifies that the QL file produces an equivalent 
QueryRequest to the YAML.
+func verifyQLWithRequest(ctx context.Context, innerGm gm.Gomega, args 
helpers.Args, yamlQuery *measurev1.TopNRequest, conn *grpclib.ClientConn) {
+       qlContent, err := qlFS.ReadFile("input/" + args.Input + ".ql")
+       innerGm.Expect(err).NotTo(gm.HaveOccurred())
+       var qlQueryStr string
+       for _, line := range strings.Split(string(qlContent), "\n") {
+               trimmed := strings.TrimSpace(line)
+               if trimmed != "" && !strings.HasPrefix(trimmed, "#") {
+                       if qlQueryStr != "" {
+                               qlQueryStr += " "
+                       }
+                       qlQueryStr += trimmed
+               }
+       }
+
+       // Auto-inject stages clause if args.Stages is not empty
+       if len(args.Stages) > 0 {
+               stageClause := " ON " + strings.Join(args.Stages, ", ") + " 
STAGES"
+               // Use regex to find and replace IN clause with groups
+               // Pattern: IN followed by groups (with or without parentheses)
+               re := 
regexp.MustCompile(`(?i)\s+IN\s+(\([^)]+\)|[a-zA-Z0-9_-]+(?:\s*,\s*[a-zA-Z0-9_-]+)*)`)
+               qlQueryStr = re.ReplaceAllString(qlQueryStr, " IN 
$1"+stageClause)
+       }
+
+       // generate mock metadata repo
+       ctrl := gomock.NewController(g.GinkgoT())
+       defer ctrl.Finish()
+       mockRepo := metadata.NewMockRepo(ctrl)
+       measure := schema.NewMockMeasure(ctrl)
+       measure.EXPECT().GetMeasure(gomock.Any(), 
gomock.Any()).DoAndReturn(func(ctx context.Context, meatadata 
*commonv1.Metadata) (*databasev1.Measure, error) {
+               client := databasev1.NewMeasureRegistryServiceClient(conn)
+               resp, getErr := client.Get(ctx, 
&databasev1.MeasureRegistryServiceGetRequest{Metadata: meatadata})
+               if getErr != nil {
+                       return nil, getErr
+               }
+               return resp.Measure, nil
+       }).AnyTimes()
+       topn := schema.NewMockTopNAggregation(ctrl)
+       topn.EXPECT().GetTopNAggregation(gomock.Any(), 
gomock.Any()).DoAndReturn(func(ctx context.Context, meatadata 
*commonv1.Metadata) (*databasev1.TopNAggregation, error) {
+               client := 
databasev1.NewTopNAggregationRegistryServiceClient(conn)
+               resp, getErr := client.Get(ctx, 
&databasev1.TopNAggregationRegistryServiceGetRequest{Metadata: meatadata})

Review Comment:
   @mrproliu fix them



-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to