[#35] policy: remove netmap/v2 dependency

Also, fix tests.

Signed-off-by: Evgenii Stratonikov <evgeniy@nspcc.ru>
This commit is contained in:
Evgenii Stratonikov 2021-09-13 11:04:51 +03:00 committed by Alex Vanin
parent 880f3a61e5
commit 6e3836cb1d
3 changed files with 144 additions and 165 deletions

View file

@ -5,7 +5,7 @@ import (
"fmt" "fmt"
"strings" "strings"
"github.com/nspcc-dev/neofs-api-go/v2/netmap" "github.com/nspcc-dev/neofs-api-go/pkg/netmap"
) )
type ( type (
@ -38,17 +38,17 @@ type (
// ToJSON converts placement policy to JSON. // ToJSON converts placement policy to JSON.
func ToJSON(np *netmap.PlacementPolicy) ([]byte, error) { func ToJSON(np *netmap.PlacementPolicy) ([]byte, error) {
p := new(placement) p := new(placement)
p.CBF = np.GetContainerBackupFactor() p.CBF = np.ContainerBackupFactor()
p.Filters = make([]filter, len(np.GetFilters())) p.Filters = make([]filter, len(np.Filters()))
for i, f := range np.GetFilters() { for i, f := range np.Filters() {
p.Filters[i].fromNetmap(f) p.Filters[i].fromNetmap(f)
} }
p.Selectors = make([]selector, len(np.GetSelectors())) p.Selectors = make([]selector, len(np.Selectors()))
for i, s := range np.GetSelectors() { for i, s := range np.Selectors() {
p.Selectors[i].fromNetmap(s) p.Selectors[i].fromNetmap(s)
} }
p.Replicas = make([]replica, len(np.GetReplicas())) p.Replicas = make([]replica, len(np.Replicas()))
for i, r := range np.GetReplicas() { for i, r := range np.Replicas() {
p.Replicas[i].fromNetmap(r) p.Replicas[i].fromNetmap(r)
} }
return json.Marshal(p) return json.Marshal(p)
@ -91,10 +91,10 @@ func FromJSON(data []byte) (*netmap.PlacementPolicy, error) {
} }
pp := new(netmap.PlacementPolicy) pp := new(netmap.PlacementPolicy)
pp.SetReplicas(rs) pp.SetReplicas(rs...)
pp.SetContainerBackupFactor(p.CBF) pp.SetContainerBackupFactor(p.CBF)
pp.SetFilters(fs) pp.SetFilters(fs...)
pp.SetSelectors(ss) pp.SetSelectors(ss...)
return pp, nil return pp, nil
} }
@ -106,31 +106,30 @@ func (r *replica) toNetmap() *netmap.Replica {
} }
func (r *replica) fromNetmap(nr *netmap.Replica) { func (r *replica) fromNetmap(nr *netmap.Replica) {
r.Count = nr.GetCount() r.Count = nr.Count()
r.Selector = nr.GetSelector() r.Selector = nr.Selector()
} }
func (f *filter) toNetmap() (*netmap.Filter, error) { func (f *filter) toNetmap() (*netmap.Filter, error) {
var op netmap.Operation var op netmap.Operation
switch strings.ToUpper(f.Op) { switch strings.ToUpper(f.Op) {
case "EQ": case "EQ":
op = netmap.EQ op = netmap.OpEQ
case "NE": case "NE":
op = netmap.NE op = netmap.OpNE
case "GT": case "GT":
op = netmap.GT op = netmap.OpGT
case "GE": case "GE":
op = netmap.GE op = netmap.OpGE
case "LT": case "LT":
op = netmap.LT op = netmap.OpLT
case "LE": case "LE":
op = netmap.LE op = netmap.OpLE
case "AND": case "AND":
op = netmap.AND op = netmap.OpAND
case "OR": case "OR":
op = netmap.OR op = netmap.OpOR
case "": case "":
op = netmap.UnspecifiedOperation
default: default:
return nil, fmt.Errorf("%w: '%s'", ErrUnknownOp, f.Op) return nil, fmt.Errorf("%w: '%s'", ErrUnknownOp, f.Op)
} }
@ -148,8 +147,8 @@ func (f *filter) toNetmap() (*netmap.Filter, error) {
} }
nf := new(netmap.Filter) nf := new(netmap.Filter)
nf.SetFilters(fs) nf.SetInnerFilters(fs...)
nf.SetOp(op) nf.SetOperation(op)
nf.SetName(f.Name) nf.SetName(f.Name)
nf.SetValue(f.Value) nf.SetValue(f.Value)
nf.SetKey(f.Key) nf.SetKey(f.Key)
@ -157,32 +156,32 @@ func (f *filter) toNetmap() (*netmap.Filter, error) {
} }
func (f *filter) fromNetmap(nf *netmap.Filter) { func (f *filter) fromNetmap(nf *netmap.Filter) {
f.Name = nf.GetName() f.Name = nf.Name()
f.Key = nf.GetKey() f.Key = nf.Key()
f.Value = nf.GetValue() f.Value = nf.Value()
switch nf.GetOp() { switch nf.Operation() {
case netmap.EQ: case netmap.OpEQ:
f.Op = "EQ" f.Op = "EQ"
case netmap.NE: case netmap.OpNE:
f.Op = "NE" f.Op = "NE"
case netmap.GT: case netmap.OpGT:
f.Op = "GT" f.Op = "GT"
case netmap.GE: case netmap.OpGE:
f.Op = "GE" f.Op = "GE"
case netmap.LT: case netmap.OpLT:
f.Op = "LT" f.Op = "LT"
case netmap.LE: case netmap.OpLE:
f.Op = "LE" f.Op = "LE"
case netmap.AND: case netmap.OpAND:
f.Op = "AND" f.Op = "AND"
case netmap.OR: case netmap.OpOR:
f.Op = "OR" f.Op = "OR"
default: default:
// do nothing // do nothing
} }
if nf.GetFilters() != nil { if nf.InnerFilters() != nil {
f.Filters = make([]filter, len(nf.GetFilters())) f.Filters = make([]filter, len(nf.InnerFilters()))
for i, sf := range nf.GetFilters() { for i, sf := range nf.InnerFilters() {
f.Filters[i].fromNetmap(sf) f.Filters[i].fromNetmap(sf)
} }
} }
@ -192,9 +191,9 @@ func (s *selector) toNetmap() (*netmap.Selector, error) {
var c netmap.Clause var c netmap.Clause
switch strings.ToUpper(s.Clause) { switch strings.ToUpper(s.Clause) {
case "SAME": case "SAME":
c = netmap.Same c = netmap.ClauseSame
case "DISTINCT": case "DISTINCT":
c = netmap.Distinct c = netmap.ClauseDistinct
case "": case "":
default: default:
return nil, fmt.Errorf("%w: '%s'", ErrUnknownClause, s.Clause) return nil, fmt.Errorf("%w: '%s'", ErrUnknownClause, s.Clause)
@ -209,17 +208,17 @@ func (s *selector) toNetmap() (*netmap.Selector, error) {
} }
func (s *selector) fromNetmap(ns *netmap.Selector) { func (s *selector) fromNetmap(ns *netmap.Selector) {
s.Name = ns.GetName() s.Name = ns.Name()
s.Filter = ns.GetFilter() s.Filter = ns.Filter()
s.Count = ns.GetCount() s.Count = ns.Count()
s.Attribute = ns.GetAttribute() s.Attribute = ns.Attribute()
switch ns.GetClause() { switch ns.Clause() {
case netmap.Same: case netmap.ClauseSame:
s.Clause = "same" s.Clause = "same"
case netmap.Distinct: case netmap.ClauseDistinct:
s.Clause = "distinct" s.Clause = "distinct"
default: default:
// do nothing // do nothing
} }
s.Name = ns.GetName() s.Name = ns.Name()
} }

View file

@ -3,7 +3,7 @@ package policy
import ( import (
"testing" "testing"
"github.com/nspcc-dev/neofs-api-go/v2/netmap" "github.com/nspcc-dev/neofs-api-go/pkg/netmap"
"github.com/stretchr/testify/require" "github.com/stretchr/testify/require"
) )
@ -19,22 +19,21 @@ func TestToJSON(t *testing.T) {
} }
t.Run("SimpleREP", func(t *testing.T) { t.Run("SimpleREP", func(t *testing.T) {
p := new(netmap.PlacementPolicy) p := new(netmap.PlacementPolicy)
p.SetReplicas([]*netmap.Replica{newReplica("", 3)}) p.SetReplicas(newReplica("", 3))
check(t, p, `{"replicas":[{"count":3}]}`) check(t, p, `{"replicas":[{"count":3}]}`)
}) })
t.Run("REPWithCBF", func(t *testing.T) { t.Run("REPWithCBF", func(t *testing.T) {
p := new(netmap.PlacementPolicy) p := new(netmap.PlacementPolicy)
p.SetReplicas([]*netmap.Replica{newReplica("", 3)}) p.SetReplicas(newReplica("", 3))
p.SetContainerBackupFactor(3) p.SetContainerBackupFactor(3)
check(t, p, `{"replicas":[{"count":3}],"container_backup_factor":3}`) check(t, p, `{"replicas":[{"count":3}],"container_backup_factor":3}`)
}) })
t.Run("REPFromSelector", func(t *testing.T) { t.Run("REPFromSelector", func(t *testing.T) {
p := new(netmap.PlacementPolicy) p := new(netmap.PlacementPolicy)
p.SetReplicas([]*netmap.Replica{newReplica("Nodes", 3)}) p.SetReplicas(newReplica("Nodes", 3))
p.SetContainerBackupFactor(3) p.SetContainerBackupFactor(3)
p.SetSelectors([]*netmap.Selector{ p.SetSelectors(
newSelector(1, netmap.Distinct, "City", "", "Nodes"), newSelector(1, netmap.ClauseDistinct, "City", "", "Nodes"))
})
check(t, p, `{ check(t, p, `{
"replicas":[{"count":3,"selector":"Nodes"}], "replicas":[{"count":3,"selector":"Nodes"}],
"container_backup_factor":3, "container_backup_factor":3,
@ -47,22 +46,21 @@ func TestToJSON(t *testing.T) {
}) })
t.Run("FilterOps", func(t *testing.T) { t.Run("FilterOps", func(t *testing.T) {
p := new(netmap.PlacementPolicy) p := new(netmap.PlacementPolicy)
p.SetReplicas([]*netmap.Replica{newReplica("Nodes", 3)}) p.SetReplicas(newReplica("Nodes", 3))
p.SetContainerBackupFactor(3) p.SetContainerBackupFactor(3)
p.SetSelectors([]*netmap.Selector{ p.SetSelectors(
newSelector(1, netmap.Same, "City", "Good", "Nodes"), newSelector(1, netmap.ClauseSame, "City", "Good", "Nodes"))
}) p.SetFilters(
p.SetFilters([]*netmap.Filter{ newFilter("GoodRating", "Rating", "5", netmap.OpGE),
newFilter("GoodRating", "Rating", "5", netmap.GE), newFilter("Good", "", "", netmap.OpOR,
newFilter("Good", "", "", netmap.OR, newFilter("GoodRating", "", "", 0),
newFilter("GoodRating", "", "", netmap.UnspecifiedOperation), newFilter("", "Attr1", "Val1", netmap.OpEQ),
newFilter("", "Attr1", "Val1", netmap.EQ), newFilter("", "Attr2", "Val2", netmap.OpNE),
newFilter("", "Attr2", "Val2", netmap.NE), newFilter("", "", "", netmap.OpAND,
newFilter("", "", "", netmap.AND, newFilter("", "Attr4", "2", netmap.OpLT),
newFilter("", "Attr4", "2", netmap.LT), newFilter("", "Attr5", "3", netmap.OpLE)),
newFilter("", "Attr5", "3", netmap.LE)), newFilter("", "Attr3", "1", netmap.OpGT)),
newFilter("", "Attr3", "1", netmap.GT)), )
})
check(t, p, `{ check(t, p, `{
"replicas":[{"count":3,"selector":"Nodes"}], "replicas":[{"count":3,"selector":"Nodes"}],
"container_backup_factor":3, "container_backup_factor":3,

View file

@ -6,16 +6,16 @@ import (
"math" "math"
"testing" "testing"
"github.com/nspcc-dev/neofs-api-go/v2/netmap" "github.com/nspcc-dev/neofs-api-go/pkg/netmap"
"github.com/stretchr/testify/require" "github.com/stretchr/testify/require"
) )
func TestSimple(t *testing.T) { func TestSimple(t *testing.T) {
q := `REP 3` q := `REP 3`
expected := new(netmap.PlacementPolicy) expected := new(netmap.PlacementPolicy)
expected.SetFilters([]*netmap.Filter{}) expected.SetFilters([]*netmap.Filter{}...)
expected.SetSelectors([]*netmap.Selector{}) expected.SetSelectors([]*netmap.Selector{}...)
expected.SetReplicas([]*netmap.Replica{newReplica("", 3)}) expected.SetReplicas(newReplica("", 3))
r, err := Parse(q) r, err := Parse(q)
require.NoError(t, err) require.NoError(t, err)
@ -25,9 +25,9 @@ func TestSimple(t *testing.T) {
func TestSimpleWithHRWB(t *testing.T) { func TestSimpleWithHRWB(t *testing.T) {
q := `REP 3 CBF 4` q := `REP 3 CBF 4`
expected := new(netmap.PlacementPolicy) expected := new(netmap.PlacementPolicy)
expected.SetFilters([]*netmap.Filter{}) expected.SetFilters([]*netmap.Filter{}...)
expected.SetSelectors([]*netmap.Selector{}) expected.SetSelectors([]*netmap.Selector{}...)
expected.SetReplicas([]*netmap.Replica{newReplica("", 3)}) expected.SetReplicas(newReplica("", 3))
expected.SetContainerBackupFactor(4) expected.SetContainerBackupFactor(4)
r, err := Parse(q) r, err := Parse(q)
@ -39,11 +39,9 @@ func TestFromSelect(t *testing.T) {
q := `REP 1 IN SPB q := `REP 1 IN SPB
SELECT 1 IN City FROM * AS SPB` SELECT 1 IN City FROM * AS SPB`
expected := new(netmap.PlacementPolicy) expected := new(netmap.PlacementPolicy)
expected.SetFilters([]*netmap.Filter{}) expected.SetFilters([]*netmap.Filter{}...)
expected.SetSelectors([]*netmap.Selector{ expected.SetSelectors(newSelector(1, netmap.ClauseUnspecified, "City", "*", "SPB"))
newSelector(1, netmap.UnspecifiedClause, "City", "*", "SPB"), expected.SetReplicas(newReplica("SPB", 1))
})
expected.SetReplicas([]*netmap.Replica{newReplica("SPB", 1)})
r, err := Parse(q) r, err := Parse(q)
require.NoError(t, err) require.NoError(t, err)
@ -57,9 +55,9 @@ func TestFromSelectNoAttribute(t *testing.T) {
SELECT 6 FROM *` SELECT 6 FROM *`
expected := new(netmap.PlacementPolicy) expected := new(netmap.PlacementPolicy)
expected.SetFilters([]*netmap.Filter{}) expected.SetFilters([]*netmap.Filter{}...)
expected.SetSelectors([]*netmap.Selector{newSelector(6, netmap.UnspecifiedClause, "", "*", "")}) expected.SetSelectors(newSelector(6, netmap.ClauseUnspecified, "", "*", ""))
expected.SetReplicas([]*netmap.Replica{newReplica("", 2)}) expected.SetReplicas(newReplica("", 2))
r, err := Parse(q) r, err := Parse(q)
require.NoError(t, err) require.NoError(t, err)
@ -72,9 +70,9 @@ func TestFromSelectNoAttribute(t *testing.T) {
FILTER StorageType EQ SSD AS F` FILTER StorageType EQ SSD AS F`
expected := new(netmap.PlacementPolicy) expected := new(netmap.PlacementPolicy)
expected.SetFilters([]*netmap.Filter{newFilter("F", "StorageType", "SSD", netmap.EQ)}) expected.SetFilters(newFilter("F", "StorageType", "SSD", netmap.OpEQ))
expected.SetSelectors([]*netmap.Selector{newSelector(6, netmap.UnspecifiedClause, "", "F", "")}) expected.SetSelectors(newSelector(6, netmap.ClauseUnspecified, "", "F", ""))
expected.SetReplicas([]*netmap.Replica{newReplica("", 2)}) expected.SetReplicas(newReplica("", 2))
r, err := Parse(q) r, err := Parse(q)
require.NoError(t, err) require.NoError(t, err)
@ -100,9 +98,9 @@ FILTER Property EQ %s AND Something NE 7 AS Filt`
r, err := Parse(q) r, err := Parse(q)
require.NoError(t, err) require.NoError(t, err)
expected := newFilter("Filt", "", "", netmap.AND, expected := newFilter("Filt", "", "", netmap.OpAND,
newFilter("", "Property", s[1:len(s)-1], netmap.EQ), newFilter("", "Property", s[1:len(s)-1], netmap.OpEQ),
newFilter("", "Something", "7", netmap.NE)) newFilter("", "Something", "7", netmap.OpNE))
require.EqualValues(t, []*netmap.Filter{expected}, r.Filters()) require.EqualValues(t, []*netmap.Filter{expected}, r.Filters())
}) })
} }
@ -114,13 +112,12 @@ SELECT 3 IN Country FROM *
SELECT 2 IN SAME City FROM * SELECT 2 IN SAME City FROM *
SELECT 1 IN DISTINCT Continent FROM *` SELECT 1 IN DISTINCT Continent FROM *`
expected := new(netmap.PlacementPolicy) expected := new(netmap.PlacementPolicy)
expected.SetFilters([]*netmap.Filter{}) expected.SetFilters([]*netmap.Filter{}...)
expected.SetSelectors([]*netmap.Selector{ expected.SetSelectors(
newSelector(3, netmap.UnspecifiedClause, "Country", "*", ""), newSelector(3, netmap.ClauseUnspecified, "Country", "*", ""),
newSelector(2, netmap.Same, "City", "*", ""), newSelector(2, netmap.ClauseSame, "City", "*", ""),
newSelector(1, netmap.Distinct, "Continent", "*", ""), newSelector(1, netmap.ClauseDistinct, "Continent", "*", ""))
}) expected.SetReplicas(newReplica("", 4))
expected.SetReplicas([]*netmap.Replica{newReplica("", 4)})
r, err := Parse(q) r, err := Parse(q)
require.NoError(t, err) require.NoError(t, err)
@ -132,13 +129,10 @@ func TestSimpleFilter(t *testing.T) {
SELECT 1 IN City FROM Good SELECT 1 IN City FROM Good
FILTER Rating GT 7 AS Good` FILTER Rating GT 7 AS Good`
expected := new(netmap.PlacementPolicy) expected := new(netmap.PlacementPolicy)
expected.SetReplicas([]*netmap.Replica{newReplica("", 1)}) expected.SetReplicas(newReplica("", 1))
expected.SetSelectors([]*netmap.Selector{ expected.SetSelectors(
newSelector(1, netmap.UnspecifiedClause, "City", "Good", ""), newSelector(1, netmap.ClauseUnspecified, "City", "Good", ""))
}) expected.SetFilters(newFilter("Good", "Rating", "7", netmap.OpGT))
expected.SetFilters([]*netmap.Filter{
newFilter("Good", "Rating", "7", netmap.GT),
})
r, err := Parse(q) r, err := Parse(q)
require.NoError(t, err) require.NoError(t, err)
@ -151,16 +145,15 @@ SELECT 2 IN City FROM Good
FILTER Country EQ "RU" AS FromRU FILTER Country EQ "RU" AS FromRU
FILTER @FromRU AND Rating GT 7 AS Good` FILTER @FromRU AND Rating GT 7 AS Good`
expected := new(netmap.PlacementPolicy) expected := new(netmap.PlacementPolicy)
expected.SetReplicas([]*netmap.Replica{newReplica("", 1)}) expected.SetReplicas(newReplica("", 1))
expected.SetSelectors([]*netmap.Selector{ expected.SetSelectors(
newSelector(2, netmap.UnspecifiedClause, "City", "Good", ""), newSelector(2, netmap.ClauseUnspecified, "City", "Good", ""))
}) expected.SetFilters(
expected.SetFilters([]*netmap.Filter{ newFilter("FromRU", "Country", "RU", netmap.OpEQ),
newFilter("FromRU", "Country", "RU", netmap.EQ), newFilter("Good", "", "", netmap.OpAND,
newFilter("Good", "", "", netmap.AND, newFilter("FromRU", "", "", 0),
newFilter("FromRU", "", "", netmap.UnspecifiedOperation), newFilter("", "Rating", "7", netmap.OpGT)),
newFilter("", "Rating", "7", netmap.GT)), )
})
r, err := Parse(q) r, err := Parse(q)
require.NoError(t, err) require.NoError(t, err)
@ -173,19 +166,16 @@ SELECT 2 IN City FROM Good
FILTER A GT 1 AND B GE 2 AND C LT 3 AND D LE 4 FILTER A GT 1 AND B GE 2 AND C LT 3 AND D LE 4
AND E EQ 5 AND F NE 6 AS Good` AND E EQ 5 AND F NE 6 AS Good`
expected := new(netmap.PlacementPolicy) expected := new(netmap.PlacementPolicy)
expected.SetReplicas([]*netmap.Replica{newReplica("", 1)}) expected.SetReplicas(newReplica("", 1))
expected.SetSelectors([]*netmap.Selector{ expected.SetSelectors(
newSelector(2, netmap.UnspecifiedClause, "City", "Good", ""), newSelector(2, netmap.ClauseUnspecified, "City", "Good", ""))
}) expected.SetFilters(newFilter("Good", "", "", netmap.OpAND,
expected.SetFilters([]*netmap.Filter{ newFilter("", "A", "1", netmap.OpGT),
newFilter("Good", "", "", netmap.AND, newFilter("", "B", "2", netmap.OpGE),
newFilter("", "A", "1", netmap.GT), newFilter("", "C", "3", netmap.OpLT),
newFilter("", "B", "2", netmap.GE), newFilter("", "D", "4", netmap.OpLE),
newFilter("", "C", "3", netmap.LT), newFilter("", "E", "5", netmap.OpEQ),
newFilter("", "D", "4", netmap.LE), newFilter("", "F", "6", netmap.OpNE)))
newFilter("", "E", "5", netmap.EQ),
newFilter("", "F", "6", netmap.NE)),
})
r, err := Parse(q) r, err := Parse(q)
require.NoError(t, err) require.NoError(t, err)
@ -197,19 +187,17 @@ func TestWithFilterPrecedence(t *testing.T) {
SELECT 1 IN City FROM SPBSSD AS SPB SELECT 1 IN City FROM SPBSSD AS SPB
FILTER City EQ "SPB" AND SSD EQ true OR City EQ "SPB" AND Rating GE 5 AS SPBSSD` FILTER City EQ "SPB" AND SSD EQ true OR City EQ "SPB" AND Rating GE 5 AS SPBSSD`
expected := new(netmap.PlacementPolicy) expected := new(netmap.PlacementPolicy)
expected.SetReplicas([]*netmap.Replica{newReplica("SPB", 7)}) expected.SetReplicas(newReplica("SPB", 7))
expected.SetSelectors([]*netmap.Selector{ expected.SetSelectors(
newSelector(1, netmap.UnspecifiedClause, "City", "SPBSSD", "SPB"), newSelector(1, netmap.ClauseUnspecified, "City", "SPBSSD", "SPB"))
}) expected.SetFilters(
expected.SetFilters([]*netmap.Filter{ newFilter("SPBSSD", "", "", netmap.OpOR,
newFilter("SPBSSD", "", "", netmap.OR, newFilter("", "", "", netmap.OpAND,
newFilter("", "", "", netmap.AND, newFilter("", "City", "SPB", netmap.OpEQ),
newFilter("", "City", "SPB", netmap.EQ), newFilter("", "SSD", "true", netmap.OpEQ)),
newFilter("", "SSD", "true", netmap.EQ)), newFilter("", "", "", netmap.OpAND,
newFilter("", "", "", netmap.AND, newFilter("", "City", "SPB", netmap.OpEQ),
newFilter("", "City", "SPB", netmap.EQ), newFilter("", "Rating", "5", netmap.OpGE))))
newFilter("", "Rating", "5", netmap.GE))),
})
r, err := Parse(q) r, err := Parse(q)
require.NoError(t, err) require.NoError(t, err)
@ -222,18 +210,17 @@ SELECT 1 IN City FROM SPBSSD AS SPB
FILTER ( City EQ "SPB" OR SSD EQ true ) AND (City EQ "SPB" OR Rating GE 5) AS SPBSSD` FILTER ( City EQ "SPB" OR SSD EQ true ) AND (City EQ "SPB" OR Rating GE 5) AS SPBSSD`
expected := new(netmap.PlacementPolicy) expected := new(netmap.PlacementPolicy)
expected.SetReplicas([]*netmap.Replica{newReplica("SPB", 7)}) expected.SetReplicas(newReplica("SPB", 7))
expected.SetSelectors([]*netmap.Selector{ expected.SetSelectors(
newSelector(1, netmap.UnspecifiedClause, "City", "SPBSSD", "SPB"), newSelector(1, netmap.ClauseUnspecified, "City", "SPBSSD", "SPB"))
}) expected.SetFilters(
expected.SetFilters([]*netmap.Filter{ newFilter("SPBSSD", "", "", netmap.OpAND,
newFilter("SPBSSD", "", "", netmap.AND, newFilter("", "", "", netmap.OpOR,
newFilter("", "", "", netmap.OR, newFilter("", "City", "SPB", netmap.OpEQ),
newFilter("", "City", "SPB", netmap.EQ), newFilter("", "SSD", "true", netmap.OpEQ)),
newFilter("", "SSD", "true", netmap.EQ)), newFilter("", "", "", netmap.OpOR,
newFilter("", "", "", netmap.OR, newFilter("", "City", "SPB", netmap.OpEQ),
newFilter("", "City", "SPB", netmap.EQ), newFilter("", "Rating", "5", netmap.OpGE))))
newFilter("", "Rating", "5", netmap.GE)))})
r, err := Parse(q) r, err := Parse(q)
require.NoError(t, err) require.NoError(t, err)
@ -302,15 +289,10 @@ SELECT 1 FROM F AS S
FILTER "UN-LOCODE" EQ "RU LED" AS F` FILTER "UN-LOCODE" EQ "RU LED" AS F`
expected := new(netmap.PlacementPolicy) expected := new(netmap.PlacementPolicy)
expected.SetReplicas([]*netmap.Replica{ expected.SetReplicas(newReplica("S", 1))
newReplica("S", 1), expected.SetSelectors(
}) newSelector(1, netmap.ClauseUnspecified, "", "F", "S"))
expected.SetSelectors([]*netmap.Selector{ expected.SetFilters(newFilter("F", "UN-LOCODE", "RU LED", netmap.OpEQ))
newSelector(1, netmap.UnspecifiedClause, "", "F", "S"),
})
expected.SetFilters([]*netmap.Filter{
newFilter("F", "UN-LOCODE", "RU LED", netmap.EQ),
})
r, err := Parse(q) r, err := Parse(q)
require.NoError(t, err) require.NoError(t, err)
@ -322,8 +304,8 @@ func newFilter(name, key, value string, op netmap.Operation, sub ...*netmap.Filt
f.SetName(name) f.SetName(name)
f.SetKey(key) f.SetKey(key)
f.SetValue(value) f.SetValue(value)
f.SetOp(op) f.SetOperation(op)
f.SetFilters(sub) f.SetInnerFilters(sub...)
return f return f
} }