httk.store.query¶
Define backend-agnostic query protocols and portable query capabilities.
The httk.store.query.optimade_filters module contains OPTIMADE filter-translation
machinery for serving layers and is intentionally not lifted here.
Submodules¶
Attributes¶
The backend field name used for the served entry identifier. |
Exceptions¶
Report that a store cannot provide an exact query count. |
|
Report that a result-set |
|
Report that a result-set |
|
Report that a continuation cursor is malformed, expired, or belongs to another result plan. |
|
Report that a valid query operation is outside a store's supported profile. |
Classes¶
Describe the query operations guaranteed by one property definition. |
|
A searcher plus its private, backend-internal raw query surface. |
|
Carry an opaque URL-safe continuation value. |
|
Order a continuation page by one named scalar result projection. |
|
Expose optional continuation-page capability on a frozen result set. |
|
Represent an immutable continuation-page result. |
|
Represent one named result row by position, name, or attribute. |
|
Require named access to one result row. |
|
Require the common operations of a materialized result set. |
|
Require composable backend search expressions. |
|
Expose a queryable field of a search variable. |
|
Bind a query variable to a target type whose attributes yield fields. |
|
Build one query; consume it through |
|
Require a store that can create a query searcher. |
|
A pandas-style indexing view over one record class in a store. |
|
One field of a |
|
A boolean predicate over a |
|
The records of a |
Functions¶
|
Derive the portable operation subset for |
|
Return the ordered portable query fields described by |
Package Contents¶
- class httk.store.query.PortableQueryCapabilities[source]¶
Describe the query operations guaranteed by one property definition.
query-supportexpresses a cross-provider guarantee, not a particular server’s implementation detail.all optionalis deliberately fail-closed here: it gives a portable client no operation it can rely on. A server may offer more, but that is not represented by the definition.- Parameters:
query_support – The normalized declared query-support level.
operations – The portable operation families guaranteed by the definition.
- httk.store.query.portable_query_capabilities(definition)[source]¶
Derive the portable operation subset for
definition.The operation names are
"equality","ordering","stringmatching", and"set". They intentionally describe the query-language operation families rather than storage implementation.IS [NOT] KNOWNis part of the equality family because it is the NULL spelling of equality/inequality in the OPTIMADE filter language.- Parameters:
definition (httk.core.PropertyDefinition) – The OPTIMADE property definition to inspect.
- Returns:
The guaranteed portable query capabilities.
- Return type:
- httk.store.query.portable_query_fields(entry_type, *, include=(), exclude=())[source]¶
Return the ordered portable query fields described by
entry_type.By default, this selects scalar fields and flat lists with at least one operation guaranteed by their definition.
includeis an explicit binding override for named existing properties; it is appended as a second ordered group after the derived fields, in entry-definition order among the included names, but does not manufacture query capabilities absent from that definition.excludealways wins. Both arguments reject unknown or duplicate names so binding mistakes cannot silently broaden a profile.- Parameters:
entry_type (httk.core.EntryTypeDefinition) – The entry definition whose properties are inspected.
include (collections.abc.Iterable[str]) – Existing property names to append to the derived selection.
exclude (collections.abc.Iterable[str]) – Existing property names to remove from the selection.
- Returns:
Derived property names followed by explicitly included names.
- Raises:
ValueError – If
includeorexcludecontains an unknown or duplicate property name.- Return type:
- httk.store.query.ID_FIELD: Final = '__id'[source]¶
The backend field name used for the served entry identifier.
- class httk.store.query.BackendSearcher[source]¶
Bases:
Searcher,ProtocolA searcher plus its private, backend-internal raw query surface.
Result sets, the federated store, stored-property streaming and entry providers build a query and consume its matches through the raw path below; user code consumes a query through
Searcher.results()instead.
- class httk.store.query.ContinuationToken[source]¶
Bases:
strCarry an opaque URL-safe continuation value.
It is a
strsubclass so normal JSON serializers preserve it as a scalar value. Applications should pass a token returned by a page back unchanged; data backends validate its version, structure, and result-plan fingerprint before using any decoded value as a bound parameter.- Parameters:
value – The opaque continuation value.
Bases:
RuntimeErrorReport that a store cannot provide an exact query count.
- exception httk.store.query.MultipleResultsError[source]¶
Bases:
LookupErrorReport that a result-set
one()operation found multiple results.
- exception httk.store.query.NoResultError[source]¶
Bases:
LookupErrorReport that a result-set
one()operation found no matching result.
- class httk.store.query.PageOrder[source]¶
Order a continuation page by one named scalar result projection.
nameidentifies the name supplied toresults(), never a backend column object. The result-set implementation validates that it is a root scalar projection before it generates SQL.- Parameters:
name – The declared scalar output name used for ordering.
descending – Whether to order this field in descending order.
nulls – Whether null values sort first or last.
- nulls: Literal['first', 'last'] = 'last'¶
- class httk.store.query.PageableResultSetLike[source]¶
Bases:
ProtocolExpose optional continuation-page capability on a frozen result set.
This deliberately extends neither
ResultSetLikenorSearcher: stores that do not support seek pagination remain fully conforming to the required portable contracts.
- exception httk.store.query.PaginationCursorError[source]¶
Bases:
ValueErrorReport that a continuation cursor is malformed, expired, or belongs to another result plan.
- class httk.store.query.ResultPage[source]¶
Represent an immutable continuation-page result.
rowsis always a tuple. Returned rows are ordinary persistent result rows, not the expiring proxies produced bySqlResultSet.cursor().totalis populated only when the caller explicitly asks for it.- Parameters:
rows – The persistent rows returned by the page.
next – The token for the next page, if one exists.
previous – The token for the previous page, if one exists.
total – The exact result count when requested, otherwise
None.
- rows: tuple[ResultRowLike, ...]¶
- next: ContinuationToken | None¶
- previous: ContinuationToken | None¶
- class httk.store.query.ResultRow(values, names, resolver=None, guard=None)[source]¶
Represent one named result row by position, name, or attribute.
- Parameters:
- class httk.store.query.ResultRowLike[source]¶
Bases:
ProtocolRequire named access to one result row.
- class httk.store.query.ResultSetLike[source]¶
Bases:
ProtocolRequire the common operations of a materialized result set.
- class httk.store.query.SearchExpression[source]¶
Bases:
ProtocolRequire composable backend search expressions.
- class httk.store.query.SearchField[source]¶
Bases:
ProtocolExpose a queryable field of a search variable.
In addition to the methods below, fields support the rich comparison operators (
==,!=,<,<=,>,>=), returningSearchExpression. The handlers invoke those viagetattr(field, '__eq__')(value)since the comparison dunders cannot be typed as expression-returning.The three string-matching methods take literal text: no wildcard or pattern syntax whatsoever crosses this contract, so
%and_(and any other metacharacter) match themselves. A backend is therefore free to implement them with SQLLIKEover an escaped pattern, with a regular expression, or with a full-text index — the choice is invisible here.- is_in(*values)[source]¶
Match a root scalar field whose value is one of
values.Noneis an explicit member: it matches a null field value, and its negation excludes nulls rather than inheriting SQL’s three-valuedNOT IN (..., NULL)behavior.Backends define the corresponding semantics for child or set fields; for example, a backend may use the existing
has_only-style all-values reading for a child field.
- class httk.store.query.SearchVariable[source]¶
Bases:
ProtocolBind a query variable to a target type whose attributes yield fields.
always_true/always_falseare reserved names: they are real methods of the variable, never stored fields resolved through__getattr__. They exist so a translation layer can express a constant truth value without inventing a probe field. Afield == fieldprobe is NULL-unsound, since it yields NULL (not true) for a NULL field.links.<name>is a reserved relationship namespace: usable as a predicate root (v.links.p == other, field chaining, set operations) and, on its own, as a set-valued output declared throughSearcher.results().
- class httk.store.query.Searcher[source]¶
Bases:
ProtocolBuild one query; consume it through
Searcher.results().The expressions received by
addare always ones produced by this same backend’s search variables, so implementations may type them as their own expression class; a backend that needs a second (post-filter) evaluation position decides that from the expression itself, not from the caller.
- class httk.store.query.Store[source]¶
Bases:
ProtocolRequire a store that can create a query searcher.
Implementations predating the
as_ofkeyword may omit it and remain usable for current-state queries, but cannot honor historic queries.
- exception httk.store.query.UnsupportedQueryError[source]¶
Bases:
ValueErrorReport that a valid query operation is outside a store’s supported profile.
- class httk.store.query.Slicer(make_searcher, target)[source]¶
A pandas-style indexing view over one record class in a store.
Index it with a field-name string to iterate that field’s values, or with a boolean
SlicerMaskto iterate the matching records. Iterating the slicer itself yields every record;len()counts them. Each operation runs against its own fresh searcher, so operations never share filter state.- Parameters:
make_searcher (collections.abc.Callable[[], Any]) – A zero-argument callable returning a fresh searcher.
target (Any) – The stored record class this slicer indexes.
- class httk.store.query.SlicerColumn(slicer, path, ast=None)[source]¶
One field of a
Slicer, iterable and comparable.Iterating yields the field’s decoded scalar values, across every record of the slicer or, when reached through a
SlicerSelection, across only its matching records. Comparisons and theisin/isna/notna/betweenhelpers, plus the.strliteral matchers, build aSlicerMaskfor use as a slicer index key.- Parameters:
- isin(values)[source]¶
Match records whose field value is one of
values.- Parameters:
values (collections.abc.Iterable[Any]) – The membership set.
- Returns:
A mask matching records in the set.
- Return type:
- isna()[source]¶
Match records whose field value is null.
- Returns:
A mask matching null field values.
- Return type:
- notna()[source]¶
Match records whose field value is not null.
- Returns:
A mask matching non-null field values.
- Return type:
- class httk.store.query.SlicerMask(slicer, ast)[source]¶
A boolean predicate over a
Slicer, combinable with& | ^ ~.A mask is not iterable and has no comparison operators; it is used only as a slicer index key or combined with another mask from the same slicer.
- Parameters:
slicer (Slicer) – The owning slicer.
ast (_Node) – The op tree the mask describes.
- class httk.store.query.SlicerSelection(slicer, ast)[source]¶
The records of a
Slicermatching aSlicerMask.Iterating yields the reconstructed records;
len()counts them. Each runs against its own fresh searcher.- Parameters:
slicer (Slicer) – The owning slicer.
ast (_Node) – The op tree selecting the records.