httk.data.db.optimade¶
OPTIMADE-filter querying over stored dataclasses: sugar tying the SQL layer to the translator.
optimade_filter_searcher() builds a SqlSearcher
over a storable class directly from an OPTIMADE filter string, deriving the
recognized property names and their types from the class’s resolved
TableSchema — the same derivation
StoreEntryProvider uses to serve the
class (via the shared served_specs() /
auto_definition() helpers), so a filter
that works against the served API works against the store.
Filter property names are the served names: {prefix}{field} (default
_httk_<field>) for every servable stored field. Related storable classes
declared via related_classes can be filtered relationally —
references.id HAS "references-3" and depth-1 related-property filters like
references._httk_doi CONTAINS "10.1" — over the class’s reference or
child-of-storable fields.
Functions¶
|
Build a searcher over the stored rows of |
Module Contents¶
- httk.data.db.optimade.optimade_filter_searcher(store: httk.data.db.store.SqlStore, cls: type, filter_string: str | httk.core.FilterAst, *, prefix: str = '_httk_', definition: httk.core.EntryTypeDefinition | None = None, extra_handlers: collections.abc.Mapping[str, collections.abc.Mapping[str, collections.abc.Callable[Ellipsis, Any]]] | None = None, related_classes: collections.abc.Mapping[str, type] | None = None) httk.data.query.Searcher[source]¶
Build a searcher over the stored rows of
clsfrom an OPTIMADE filter.filter_stringis an OPTIMADE filter string or an already-parsedFilterAst. The returned searcher outputs the matching stored instances (item[0][0]per match).Property names. Every servable stored field of
cls(perserved_specs()) is filterable as{prefix}{field}, with its schema-derived fulltype driving constant conversion and handler dispatch (rational fields compare on their documented-approximate float query column). Unknown names carryingprefixraiseFilterTranslationError("unrecognized-property"); other unknown names match nothing, per the OPTIMADE specification. Unprefixed property names (beyondid/type) are recognized only when adefinitiondescribes them — and even then they translate only ifextra_handlerssupplies their handlers, since the store knows no column for them. The OPTIMADE coreidandtypeproperties are recognized but not supported withoutextra_handlersentries (a store row has no served id: ids are minted at serving time), so filtering on them raises"not-implemented".Relationships.
related_classesmaps relationship-type names to storable classes; each must be the target of exactly one reference or child-of-storable (list[Target]) field ofcls(anything else raisesValueError). For each such(rtype, rcls):<rtype>.id HAS "<rtype>-<sid>"filters over the field’s foreign-key (or child-element) column against default-minted"<entry type>-<sid>"ids, asStoreEntryProvidermints them; ids of any other format match nothing. Customid_ofminting is out of scope here — with a custom minting scheme, supply your own'<rtype>.id'entry viaextra_handlers.Depth-1 related-property filters (
<rtype>._httk_doi CONTAINS "10.1",<rtype>.id != "...",<rtype>._httk_year IS KNOWN, …) resolve by a two-phase semi-join: a nestedoptimade_filter_searcheroverrcls(with the sameprefix; no further relationship nesting) collects the matching related sids, which are then matched as<rtype>.id HAS ANY .... Each dotted filter node resolves independently — seetranslate_filter_ast().
extra_handlersentries are merged over the derived handler table last (so they can also override derived handlers); extra property names that are otherwise unknown are recognized with fulltype"unknown"(filter constants pass through unconverted).- Raises:
httk.data.optimade_query.FilterTranslationError – When the filter cannot be translated.
httk.core.ParserSyntaxError – When a filter string does not parse.
ValueError – When a
related_classesentry does not match exactly one reference or child-of-storable field ofcls.