httk.optimade.backend.handlers¶
Re-exports of the generic OPTIMADE filter handlers.
The handler tables and generic handlers are implemented in
httk.data.optimade_query and exposed here under the
httk.optimade.backend.handlers namespace.
The handlers raise
FilterTranslationError (which carries a
neutral failure category instead of HTTP semantics);
translate_filter() wraps it into
TranslatorError with the appropriate
HTTP status. simple_property_handlers() takes a
plain property-name -> fulltype mapping as its third argument. A 'HAS'
handler is called as
handler(property, ops, values, search_variable, has_type) and returns a
plain SearchExpression; the caller applies NOT as
~, and the backend determines whether the resulting expression also needs
post-filter evaluation.
Attributes¶
Per-property translation callables, keyed by property name. |
|
Functions¶
Fold |
|
|
|
Fold |
|
|
A constant-false expression over |
|
|
|
|
|
Translate one HAS family node over the list-valued field |
|
Build a filter handler table for an entry type from a property-key map. |
|
|
|
Translate |
|
|
|
A constant-true expression over |
|
|
|
|
|
Module Contents¶
- type httk.optimade.backend.handlers.HandlerTable = Mapping[str, Mapping[str, Callable[..., Any]]][source]¶
Per-property translation callables, keyed by property name.
The inner mapping’s keys name the filter-operation families:
'comparison'(=,!=,<,<=,>,>=),'stringmatching'(CONTAINS/STARTS/ENDS),'HAS'(the set operations),'length'(LENGTH), and'unknown'(IS KNOWN/IS UNKNOWN). A'HAS'handler is called ashandler(property, ops, values, search_variable, has_type)and returns a plainSearchExpression. The caller appliesNOTas~; handlers do not receive negation state or report post-filter placement. Dotted'<type>.id'entries provide relationship-id filtering (seerelationship_id_handler()).
- httk.optimade.backend.handlers.constant_comparison_handler(val1: Any, op: str, val2: Any, search_variable: httk.data.query.SearchVariable) httk.data.query.SearchExpression[source]¶
Fold
val1 <op> val2(both constants) to a constant expression.val1is the value being compared andval2the filter constant, the same left-to-right convention asconstant_set_handler();translate_filter_ast()has already invertedopfor constant-on-the-left filters, so this ordering is the filter’s own.
- httk.optimade.backend.handlers.constant_set_handler(val1: Any, ops: Any, val2: Any, has_type: str, search_variable: httk.data.query.SearchVariable) httk.data.query.SearchExpression[source]¶
- httk.optimade.backend.handlers.constant_stringmatching_handler(val1: Any, val2: Any, stringmatching_type: str, search_variable: httk.data.query.SearchVariable) httk.data.query.SearchExpression[source]¶
Fold
val1 <CONTAINS|STARTS|ENDS> val2(both constants) to a constant expression.val1is the value being matched andval2the filter text, the same left-to-right convention asconstant_set_handler().
- httk.optimade.backend.handlers.false_handler(search_variable: httk.data.query.SearchVariable) httk.data.query.SearchExpression[source]¶
A constant-false expression over
search_variable.
- httk.optimade.backend.handlers.known_unknown_handler(entry: str, search_variable: httk.data.query.SearchVariable, unknown_type: str) httk.data.query.SearchExpression[source]¶
- httk.optimade.backend.handlers.number_handler(entry: str, op: str, value: Any, search_variable: httk.data.query.SearchVariable) httk.data.query.SearchExpression[source]¶
- httk.optimade.backend.handlers.set_handler(entry: str, ops: Any, values: Any, has_type: str, search_variable: httk.data.query.SearchVariable) httk.data.query.SearchExpression[source]¶
Translate one HAS family node over the list-valued field
entry.HAS ALLbecomes a conjunction of one-valuehas_anycalls (each constraining an independently joined child row);HAS ANYandHAS ONLYmap straight ontohas_any/has_only. Negation is not the handler’s business: a surroundingNOTinverts the returned expression, and the backend’s~knows how to negate a set predicate.
- httk.optimade.backend.handlers.simple_property_handlers(entry_type: str, property_keys: collections.abc.Mapping[str, str], property_fulltypes: collections.abc.Mapping[str, str]) dict[str, collections.abc.Mapping[str, collections.abc.Callable[Ellipsis, Any]]][source]¶
Build a filter handler table for an entry type from a property-key map.
Always provides the standard
id(matched against the__idfield) andtype(a constant equal toentry_type) handlers. For every property named inproperty_keys(which maps property names to backend field names), handlers are generated from the property’s fulltype inproperty_fulltypes(default"string"): string properties get comparison and stringmatching handlers; integer and float properties get a numeric comparison handler;list of ...properties get a HAS (set membership) handler. Every generated property also gets aknownunknown handler.
- httk.optimade.backend.handlers.string_handler(entry: str, op: str, value: Any, search_variable: httk.data.query.SearchVariable) httk.data.query.SearchExpression[source]¶
- httk.optimade.backend.handlers.stringmatching_handler(entry: str, value: str, stringmatching_type: str, search_variable: httk.data.query.SearchVariable) httk.data.query.SearchExpression[source]¶
Translate
CONTAINS/STARTS/ENDSonto the field’s literal matchers.The filter constant is passed through unescaped: the search-field protocol’s
contains/startswith/endswithtake literal text, so%and_match themselves (as OPTIMADE requires). Any escaping a backend’s pattern language needs is that backend’s own business.
- httk.optimade.backend.handlers.timestamp_handler(entry: str, op: str, value: Any, search_variable: httk.data.query.SearchVariable) httk.data.query.SearchExpression[source]¶
- httk.optimade.backend.handlers.true_handler(search_variable: httk.data.query.SearchVariable) httk.data.query.SearchExpression[source]¶
A constant-true expression over
search_variable.
- httk.optimade.backend.handlers.unknown_comparison_handler(entry: str, ops: Any, values: Any, search_variable: httk.data.query.SearchVariable) httk.data.query.SearchExpression[source]¶
- httk.optimade.backend.handlers.unknown_has_handler(entry: str, op: Any, value: Any, search_variable: httk.data.query.SearchVariable, has_type: str) httk.data.query.SearchExpression[source]¶
- httk.optimade.backend.handlers.unknown_length_handler(entry: str, op: str, value: Any, search_variable: httk.data.query.SearchVariable) httk.data.query.SearchExpression[source]¶
- httk.optimade.backend.handlers.unknown_stringmatching_handler(entry: str, values: Any, stringmatching_type: str, search_variable: httk.data.query.SearchVariable) httk.data.query.SearchExpression[source]¶
- httk.optimade.backend.handlers.unknown_unknown_handler(entry: str, search_variable: httk.data.query.SearchVariable, unknown_type: str) httk.data.query.SearchExpression[source]¶