httk.store.federated_store

Frozen query planning and sequential execution for a federated store.

Federated expressions are deliberately represented by a private, backend-neutral AST. Child searcher expressions are used only while validating that each participating source accepts an operation; every execution replays that AST into fresh child searchers.

Exceptions

FederatedStoreError

Report that a federation-level store operation failed.

FederatedSourceError

Report that a named source rejected or failed a federated operation.

Classes

FederatedResultColumn

Expose one scalar projection lazily from a federated result set.

FederatedResultSet

Represent a frozen, lazy, re-iterable federated result plan.

FederatedTarget

Bind one logical target to exact concrete targets for named sources.

FederatedStore

Fan out read-only queries over an ordered collection of borrowed stores.

FederatedVariable

Represent the one root variable supported by a federated query.

FederatedField

Represent a backend-neutral path from a federated root variable.

FederatedExpression

Represent a federated expression backed by the neutral private AST.

FederatedSearcher

Build and validate one portable, single-root federated query.

Module Contents

exception httk.store.federated_store.FederatedStoreError[source]

Bases: RuntimeError

Report that a federation-level store operation failed.

exception httk.store.federated_store.FederatedSourceError(source, operation)[source]

Bases: FederatedStoreError

Report that a named source rejected or failed a federated operation.

Parameters:
  • source (str) – The source name that failed.

  • operation (str) – The federation operation being performed.

source[source]
operation[source]
class httk.store.federated_store.FederatedResultColumn(result, index)[source]

Expose one scalar projection lazily from a federated result set.

Parameters:
  • result (FederatedResultSet) – The result set supplying rows.

  • index (int) – The zero-based projection index.

name[source]
class httk.store.federated_store.FederatedResultSet(store, plan)[source]

Represent a frozen, lazy, re-iterable federated result plan.

Results execute source-major in federation source order, preserve duplicate rows, and remain read-only views over the borrowed stores.

Parameters:
  • store (FederatedStore) – The federation whose sources execute the plan.

  • plan (object) – The validated frozen federation plan.

property names: tuple[str, Ellipsis][source]

Return the declared projection names.

Returns:

The result projection names in declaration order.

Return type:

tuple[str, Ellipsis]

first()[source]

Return the first result row, or None when no row matches.

Returns:

The first matching row, or None.

Return type:

httk.store.query.ResultRow | None

one()[source]

Return the only result row.

Returns:

The sole matching result row.

Raises:
Return type:

httk.store.query.ResultRow

scalars(name=None)[source]

Iterate over one named projection.

Parameters:

name (str | None) – The projection name, required when more than one output exists.

Returns:

An iterator over the selected projection values.

Raises:
  • ValueError – If no name is supplied for multiple outputs.

  • KeyError – If name is not a declared output.

Return type:

collections.abc.Iterator[object]

column(name)[source]

Return a lazy scalar column by projection name.

Parameters:

name (str) – The scalar projection name.

Returns:

A lazy column view over the projection.

Raises:
  • KeyError – If name is not a declared output.

  • TypeError – If name identifies an object output.

Return type:

FederatedResultColumn

abstractmethod cursor()[source]

Reject cursor access because federation cursors are unsupported.

Returns:

Never returns.

Raises:

NotImplementedError – Always, because federated cursors are not implemented.

Return type:

collections.abc.Iterator[httk.store.query.ResultRow]

class httk.store.federated_store.FederatedTarget[source]

Bind one logical target to exact concrete targets for named sources.

Parameters:
  • name – The nonempty logical target name.

  • targets – Concrete targets keyed by federation source name.

  • _owner – The federation that owns this target binding.

Raises:
  • TypeError – If targets is not a mapping or _owner is not a federation.

  • ValueError – If the name, source set, or source names are invalid.

name: str[source]
targets: collections.abc.Mapping[str, object][source]
class httk.store.federated_store.FederatedStore(sources)[source]

Fan out read-only queries over an ordered collection of borrowed stores.

The union is source-major, lazy, and non-deduplicating. Queries require the strict common query surface accepted by every participating source, and counts are exact sums of the unpaged source counts. This live borrowed-store view is distinct from the persisted registry in httk.store.db.stored_federation.

Parameters:

sources (collections.abc.Mapping[str, httk.store.query.Store]) – Child stores keyed by stable federation source name.

Raises:
  • TypeError – If sources is not a mapping.

  • ValueError – If fewer than two sources or an invalid source name is supplied.

property source_names: tuple[str, Ellipsis][source]

Return the immutable source names in constructor iteration order.

Returns:

The source names in constructor order.

Return type:

tuple[str, Ellipsis]

target(name, targets)[source]

Create an immutable target mapping for an intentional source subset.

Parameters:
Returns:

The validated target binding.

Raises:
  • TypeError – If targets is not a mapping.

  • ValueError – If a target name or source name is invalid.

Return type:

FederatedTarget

searcher()[source]

Create an unbound federated searcher without touching child stores.

Returns:

A new mutable query builder.

Return type:

FederatedSearcher

class httk.store.federated_store.FederatedVariable(searcher, variables, targets)[source]

Represent the one root variable supported by a federated query.

Parameters:
always_true()[source]

Build an expression that matches every federated row.

Returns:

A federated expression matching every row.

Return type:

FederatedExpression

always_false()[source]

Build an expression that matches no federated row.

Returns:

A federated expression matching no row.

Return type:

FederatedExpression

class httk.store.federated_store.FederatedField(variable, path)[source]

Represent a backend-neutral path from a federated root variable.

Parameters:
  • variable (FederatedVariable) – The federated root variable owning the path.

  • path (tuple[str, Ellipsis]) – The field path relative to that variable.

contains(text)[source]

Match literal values containing text.

Parameters:

text (str) – The literal substring to find.

Returns:

The resulting federated expression.

Return type:

FederatedExpression

startswith(prefix)[source]

Match literal values beginning with prefix.

Parameters:

prefix (str) – The literal prefix to find.

Returns:

The resulting federated expression.

Return type:

FederatedExpression

endswith(suffix)[source]

Match literal values ending with suffix.

Parameters:

suffix (str) – The literal suffix to find.

Returns:

The resulting federated expression.

Return type:

FederatedExpression

has(value)[source]

Match a list field containing value.

Parameters:

value (object) – The list member to match.

Returns:

The resulting federated expression.

Return type:

FederatedExpression

has_any(*values)[source]

Match a list field containing any of values.

Parameters:

*values (object) – The list members to match.

Returns:

The resulting federated expression.

Return type:

FederatedExpression

has_only(*values)[source]

Match a list field containing no values outside values.

Parameters:

*values (object) – The complete allowed list-member set.

Returns:

The resulting federated expression.

Return type:

FederatedExpression

is_in(*values)[source]

Match a scalar field whose value is one of values.

Parameters:

*values (object) – The accepted field values.

Returns:

The resulting federated expression.

Return type:

FederatedExpression

class httk.store.federated_store.FederatedExpression(searcher, ast)[source]

Represent a federated expression backed by the neutral private AST.

Parameters:
  • searcher (FederatedSearcher) – The owning federated searcher.

  • ast (object) – The validated private expression tree.

class httk.store.federated_store.FederatedSearcher(store)[source]

Build and validate one portable, single-root federated query.

Parameters:

store (FederatedStore) – The federation whose child stores provide the query surface.

offset = 0[source]
origin[source]
variable(target)[source]

Bind one shared or explicit target against child searcher prototypes.

Parameters:

target (object) – A shared child target or a source-specific target binding.

Returns:

The federated root variable.

Raises:
Return type:

FederatedVariable

add(expression)[source]

Validate and retain a portable condition for the future frozen plan.

Parameters:

expression (object) – An expression produced by this searcher.

Returns:

None.

Raises:
Return type:

None

output(value, name)[source]

Declare a record, scalar field, or origin output for a future plan.

Parameters:
  • value (object) – The root variable, field, or origin sentinel to project.

  • name (str) – The nonempty output name.

Returns:

None.

Raises:
Return type:

None

add_sort(field, descending=False)[source]

Reject global sorting until a portable sort-semantics contract exists.

Parameters:
  • field (object) – The requested sort field.

  • descending (bool) – Whether the requested order is descending.

Raises:

httk.store.query.protocols.UnsupportedQueryError – Always, because global federation sorting has no portable contract.

count()[source]

Return the exact unpaged count of the current filtered union.

Returns:

The exact sum of matching rows across participating sources.

Raises:
Return type:

int

set_limit(limit)[source]

Set the global output limit; a negative value clears it.

Parameters:

limit (int) – The nonnegative limit, or a negative value to clear it.

Returns:

None.

Raises:

TypeError – If limit is not an integer.

Return type:

None

add_offset(offset)[source]

Add a global source-union offset.

Parameters:

offset (int) – The nonnegative number of union rows to skip.

Returns:

None.

Raises:
Return type:

None

results(**outputs)[source]

Freeze a projection plan into a lazy, re-iterable result set.

Parameters:

**outputs (object) – Optional output names mapped to root variables or fields.

Returns:

The lazy frozen result set.

Raises:
Return type:

FederatedResultSet