[#xx] Add support for SELECT-FILTER expressions
Signed-off-by: Alejandro Lopez <a.lopez@yadro.com>
This commit is contained in:
parent
b9afe7a2f9
commit
b91f9d8c79
8 changed files with 556 additions and 170 deletions
|
@ -158,6 +158,57 @@ func (m NetMap) PlacementVectors(vectors [][]NodeInfo, pivot []byte) ([][]NodeIn
|
|||
return result, nil
|
||||
}
|
||||
|
||||
// SelectFilterNodes returns a two-dimensional list of nodes as a result of applying the
|
||||
// given SelectFilterExpr to the NetMap.
|
||||
// If the SelectFilterExpr contains only filters, the result contains a single row with the
|
||||
// result of the last filter application.
|
||||
// If the SelectFilterExpr contains only selectors, the result contains the selection rows
|
||||
// of the last select application.
|
||||
func (m NetMap) SelectFilterNodes(expr *SelectFilterExpr) ([][]NodeInfo, error) {
|
||||
p := PlacementPolicy{
|
||||
filters: expr.filters,
|
||||
}
|
||||
|
||||
if expr.selector != nil {
|
||||
p.selectors = append(p.selectors, *expr.selector)
|
||||
}
|
||||
|
||||
c := newContext(m)
|
||||
c.setCBF(expr.cbf)
|
||||
|
||||
if err := c.processFilters(p); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if err := c.processSelectors(p); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if expr.selector == nil {
|
||||
var ret []NodeInfo
|
||||
lastFilter := expr.filters[len(expr.filters)-1]
|
||||
for _, ni := range m.nodes {
|
||||
if c.match(c.processedFilters[lastFilter.GetName()], ni) {
|
||||
ret = append(ret, ni)
|
||||
}
|
||||
}
|
||||
return [][]NodeInfo{ret}, nil
|
||||
}
|
||||
|
||||
sel, err := c.getSelection(*c.processedSelectors[expr.selector.GetName()])
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
var ret [][]NodeInfo
|
||||
for i, ns := range sel {
|
||||
ret = append(ret, []NodeInfo{})
|
||||
for _, n := range ns {
|
||||
ret[i] = append(ret[i], n)
|
||||
}
|
||||
}
|
||||
return ret, nil
|
||||
}
|
||||
|
||||
// ContainerNodes returns two-dimensional list of nodes as a result of applying
|
||||
// given PlacementPolicy to the NetMap. Each line of the list corresponds to a
|
||||
// replica descriptor. Line order corresponds to order of ReplicaDescriptor list
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue