Filter
from skipcheck_tm1 import Filter A $filter expression, built from ODataProperty comparisons and the
canonical functions TM1 supports:
numeric_q = Filter.and_(Filter.starts_with(Element.NAME, "Q"), Element.TYPE.eq(ODataLiterals.enum_member("ibm.tm1.api.v1.ElementType", "Numeric")))
# (startswith(Name,'Q') and (Type eq ibm.tm1.api.v1.ElementType'Numeric'))
has_region = Filter.any("Hierarchies", "h", lambda h: h.nav("Name").eq("Region"))
# Hierarchies/any(h:h/Name eq 'Region')
Every binary expression is parenthesized, so precedence never depends on how a filter
was composed. Values are written as OData literals (ODataLiterals.of); the
whole expression is percent-encoded once, when the query is rendered. raw
takes any expression as is, and is parenthesized when it's combined with others.
Note that TM1 compares names in $filter case- and space-sensitively, while
keyed access ignores both. To find one object by name, use its key rather than a
filter.
Members
__init__ constructor | |
raw static | An expression written by hand, used as is. |
and_ static | All of the given filters, at least one. |
or_ static | Any of the given filters, at least one. |
not_ static | not filter. |
starts_with static | startswith(property,'prefix'), for a string property. |
ends_with static | endswith(property,'suffix'), for a string property. |
contains static | contains(property,'text'), for a string property. |
any static | True if any member of a collection matches. |
all static | True if every member of a collection matches. |
in_ static | property in (a,b,c), with at least one value, each written as an OData literal. |
__init__
constructor__init__(expression: str, _raw: bool = False)raw
staticraw(expression: str) -> FilterAn expression written by hand, used as is. Combined with others by and_ or or_, it's put in parentheses, so it keeps its meaning whatever operators it uses.
and_
staticand_(*filters: Filter) -> FilterAll of the given filters, at least one: joined with and, or the filter itself if there's only one.
or_
staticor_(*filters: Filter) -> FilterAny of the given filters, at least one: joined with or, or the filter itself if there's only one.
not_
staticnot_(filter: Filter) -> Filternot filter.
starts_with
staticstarts_with(prop: str | ODataProperty, prefix: str) -> Filterstartswith(property,'prefix'), for a string property.
ends_with
staticends_with(prop: str | ODataProperty, suffix: str) -> Filterendswith(property,'suffix'), for a string property.
contains
staticcontains(prop: str | ODataProperty, text: str) -> Filtercontains(property,'text'), for a string property.
any
staticany(collection_path: str, variable: str, condition: Callable[[Variable], Filter]) -> Filtercollection/any(v:condition): true if any member of a collection matches. collection_path is used as is, such as Hierarchies; condition receives the range variable, from which to build paths (v.nav("Name")).
all
staticall(collection_path: str, variable: str, condition: Callable[[Variable], Filter]) -> Filtercollection/all(v:condition): true if every member of a collection matches. The arguments are as for any.
in_
staticin_(prop: str | ODataProperty, *values: Any) -> Filterproperty in (a,b,c), with at least one value, each written as an OData literal. Not every TM1 version supports in; or_ of eq comparisons always works.