policy: Check for redundant selectors and filters #154
No reviewers
Labels
No labels
P0
P1
P2
P3
good first issue
pool
Infrastructure
blocked
bug
config
discussion
documentation
duplicate
enhancement
go
help wanted
internal
invalid
kludge
observability
perfomance
question
refactoring
wontfix
No milestone
No project
No assignees
4 participants
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference: TrueCloudLab/frostfs-sdk-go#154
Loading…
Reference in a new issue
No description provided.
Delete branch "acid-ant/frostfs-sdk-go:bugfix/150-check-redundant"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Close #150
Policy
REP 1 SELECT 4 FROM * AS X
will fail with errorpolicy: found redundant selector
.REP 1 IN X SELECT 4 FROM * AS X FILTER 'UN' EQ 'RU' AS F
- with errorpolicy: found redundant filter
Signed-off-by: Anton Nikiforov an.nikiforov@yadro.com
@ -553,2 +553,3 @@
if err := validatePolicy(*p); err != nil {
if err := validatePolicy(*parsed); err != nil {
//if err := validatePolicy(*p); err != nil {
What's this comment for?
Ooops, removed.
@ -864,0 +864,4 @@
seenSelectors := map[string]*netmap.Selector{}
for i := range p.selectors {
if p.selectors[i].GetName() == "" {
return fmt.Errorf("%w: use keyword AS to provide name for selector", errRedundantSelector)
It's is
errRedundantSelector
, but maybeerrUnnamedSelector
would be better? Likeunnamed selectors are useless, make sure to pair REP and SELECT clauses: "REP .. IN X" + "SELECT ... AS X"
Agree, sounds better. Updated.
@ -864,0 +866,4 @@
if p.selectors[i].GetName() == "" {
return fmt.Errorf("%w: use keyword AS to provide name for selector", errRedundantSelector)
}
if flt := p.selectors[i].GetFilter(); flt != mainFilterName {
What happens if
flt
be is an empty string here?Thought about this too earlier. In this case, we will have the different error:
policy: syntax error: line 1:68 mismatched input '<EOF>' expecting 'AS
Hm, this makes me think -- what if we just change the grammar for selectors too? I.e. make this obligatory https://git.frostfs.info/TrueCloudLab/frostfs-sdk-go/src/branch/master/netmap/parser/Query.g4#L21
For validation we could just check used/unused then.
@ -864,3 +885,2 @@
for i := range p.replicas {
if sel := p.replicas[i].GetSelector(); sel != "" && !seenSelectors[sel] {
return fmt.Errorf("%w: '%s'", errUnknownSelector, sel)
var sel *netmap.Selector
This variable is used once inside an
if
, maybe move it theresel :=
?Right, garbage from the previous implementation, updated.
@ -0,0 +42,4 @@
var p PlacementPolicy
for _, testCase := range testCases {
require.NoError(t, p.DecodeString(testCase), fmt.Sprintf("unable parse %s", testCase))
I believe
require
naturally supports format strings:require.NoError(..., "unable to parse %s", testCase)
Fixed.
0886d18d49
to9c0b33c6fa
9c0b33c6fa
tob5fe52d6bd