From 28ab9021ff2904ffcde892dca4aa786a512b3e05 Mon Sep 17 00:00:00 2001 From: Eric Promislow Date: Fri, 25 Apr 2025 10:50:45 -0700 Subject: [PATCH] Finish parsing indirect statements: update the returned requirement. --- .../sqlpartition/listprocessor/processor.go | 11 +++++--- .../listprocessor/processor_test.go | 27 +++++++++++++++++++ 2 files changed, 34 insertions(+), 4 deletions(-) diff --git a/pkg/stores/sqlpartition/listprocessor/processor.go b/pkg/stores/sqlpartition/listprocessor/processor.go index 7afd54e1..1e6813a3 100644 --- a/pkg/stores/sqlpartition/listprocessor/processor.go +++ b/pkg/stores/sqlpartition/listprocessor/processor.go @@ -73,11 +73,14 @@ func k8sRequirementToOrFilter(requirement queryparser.Requirement) (sqltypes.Fil values := requirement.Values() queryFields := splitQuery(requirement.Key()) op, usePartialMatch, err := k8sOpToRancherOp(requirement.Operator()) + isIndirect, indirectFields := requirement.IndirectInfo() return sqltypes.Filter{ - Field: queryFields, - Matches: values, - Op: op, - Partial: usePartialMatch, + Field: queryFields, + Matches: values, + Op: op, + Partial: usePartialMatch, + IsIndirect: isIndirect, + IndirectFields: indirectFields, }, err } diff --git a/pkg/stores/sqlpartition/listprocessor/processor_test.go b/pkg/stores/sqlpartition/listprocessor/processor_test.go index bc912cc1..92ba8af2 100644 --- a/pkg/stores/sqlpartition/listprocessor/processor_test.go +++ b/pkg/stores/sqlpartition/listprocessor/processor_test.go @@ -370,6 +370,33 @@ func TestParseQuery(t *testing.T) { }, }, }) + tests = append(tests, testCase{ + description: "ParseQuery() with an indirect labels filter param should create an indirect labels-specific filter.", + req: &types.APIRequest{ + Request: &http.Request{ + URL: &url.URL{RawQuery: "filter=metadata.labels[grover.example.com/fish]=>[_v1][Foods][foodCode][country]=japan"}, + }, + }, + expectedLO: sqltypes.ListOptions{ + ChunkSize: defaultLimit, + Filters: []sqltypes.OrFilter{ + { + Filters: []sqltypes.Filter{ + { + Field: []string{"metadata", "labels", "grover.example.com/fish"}, + Matches: []string{"japan"}, + Op: sqltypes.Eq, + IsIndirect: true, + IndirectFields: []string{"_v1", "Foods", "foodCode", "country"}, + }, + }, + }, + }, + Pagination: sqltypes.Pagination{ + Page: 1, + }, + }, + }) tests = append(tests, testCase{ description: "ParseQuery() with multiple filter params, should include multiple or filters.", req: &types.APIRequest{