Safe Haskell | Safe-Inferred |
---|---|
Language | Haskell2010 |
Ganeti.Query.Filter
Description
Implementation of the Ganeti Query2 filterning.
The filtering of results should be done in two phases.
In the first phase, before contacting any remote nodes for runtime
data, the filtering should be executed with Nothing
for the runtime
context. This will make all non-runtime filters filter correctly,
whereas all runtime filters will respond successfully. As described in
the Python version too, this makes for example Or filters very
inefficient if they contain runtime fields.
Once this first filtering phase has been done, we hopefully eliminated
some remote nodes out of the list of candidates, we run the remote
data gathering, and we evaluate the filter again, this time with a
Just
runtime context. This will make all filters work correctly.
Note that the second run will re-evaluate the config/simple fields, without caching; this is not perfect, but we consider config accesses very cheap (and the configuration snapshot we have won't change between the two runs, hence we will not get inconsistent results).
Synopsis
- compileFilter :: FieldMap a b -> Filter FilterField -> ErrorResult (Filter (FieldGetter a b, QffMode))
- evaluateQueryFilter :: ConfigData -> Maybe b -> a -> Filter (FieldGetter a b, QffMode) -> ErrorResult Bool
- evaluateFilterM :: (Monad m, Applicative m) => (forall val. FilterOp field val -> field -> val -> m Bool) -> Filter field -> m Bool
- evaluateFilterJSON :: Filter JSValue -> ErrorResult Bool
- requestedNames :: FilterField -> Filter FilterField -> Maybe [FilterValue]
- makeSimpleFilter :: String -> [Either String Integer] -> Filter FilterField
- type Comparator = forall a. (Eq a, Ord a) => a -> a -> Bool
- data Comparison
- toCompFun :: Comparison -> Comparator
- data FilterOp field val where
- Truth :: FilterOp field ()
- Comp :: Comparison -> FilterOp field FilterValue
- Regex :: FilterOp field FilterRegex
- Contains :: FilterOp field FilterValue
Documentation
compileFilter :: FieldMap a b -> Filter FilterField -> ErrorResult (Filter (FieldGetter a b, QffMode)) #
Compiles a filter based on field names to one based on getters.
evaluateQueryFilter :: ConfigData -> Maybe b -> a -> Filter (FieldGetter a b, QffMode) -> ErrorResult Bool #
Verifies if a given item passes a filter. The runtime context might be missing, in which case most of the filters will consider this as passing the filter.
evaluateFilterM :: (Monad m, Applicative m) => (forall val. FilterOp field val -> field -> val -> m Bool) -> Filter field -> m Bool #
Checks if a filter matches.
The leaves of the filter are evaluated against an object using the passed
opFun
; that is why the object need not be passed in.
The field
type describes the "accessors" that are used to query
values from the object; those values are to be matched against the
val
type in the filter leaves.
Useful monads m
for this are ErrorResult
and Maybe
.
evaluateFilterJSON :: Filter JSValue -> ErrorResult Bool #
Evaluates a Filter
on a JSON object.
requestedNames :: FilterField -> Filter FilterField -> Maybe [FilterValue] #
Computes the requested names, if only names were requested (and
with equality). Otherwise returns Nothing
.
makeSimpleFilter :: String -> [Either String Integer] -> Filter FilterField #
Builds a simple filter from a list of names.
type Comparator = forall a. (Eq a, Ord a) => a -> a -> Bool #
A type synonim for a rank-2 comparator function. This is used so
that we can pass the usual <=
, >
, ==
functions to binOpFilter
and for them to be used in multiple contexts.
data Comparison #
Ways we can compare things in the filter language.
Instances
Show Comparison # | |
Defined in Ganeti.Query.Filter Methods showsPrec :: Int -> Comparison -> ShowS show :: Comparison -> String showList :: [Comparison] -> ShowS | |
Eq Comparison # | |
Defined in Ganeti.Query.Filter | |
Ord Comparison # | |
Defined in Ganeti.Query.Filter Methods compare :: Comparison -> Comparison -> Ordering (<) :: Comparison -> Comparison -> Bool (<=) :: Comparison -> Comparison -> Bool (>) :: Comparison -> Comparison -> Bool (>=) :: Comparison -> Comparison -> Bool max :: Comparison -> Comparison -> Comparison min :: Comparison -> Comparison -> Comparison |
toCompFun :: Comparison -> Comparator #
Turns a comparison into the corresponding Haskell function.
data FilterOp field val where #
Operations in the leaves of the Ganeti filter language.
Constructors
Truth :: FilterOp field () | |
Comp :: Comparison -> FilterOp field FilterValue | |
Regex :: FilterOp field FilterRegex | |
Contains :: FilterOp field FilterValue |