ftmq.Query
See the query guide for a narrative introduction.
A filter over FtM entities, built from composable M / P / G nodes.
Examples:
from ftmq import Query, M, P, G
q = Query().where(M(schema="Person"), P(name__ilike="jane%"))
q = q.where(G(countries="de") | G(countries="at"))
q = q.order_by("name")[:10]
Source code in ftmq/query/main.py
103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 | |
context
property
The current context filters (the C family, e.g. origin)
countries
property
The current filtered countries
dataset_names
property
The names of the current filtered datasets
datasets
property
The current dataset filters
groups
property
The current property groups lookup filters
ids
property
The current id filters
limit
property
The current limit (inferred from a slice)
offset
property
The current offset (inferred from a slice)
A start-less slice (q[:10]) reports offset 0, so it serializes and
round-trips identically to q[0:10].
properties
property
The current property lookup filters
schemata
property
The current schema filters
schemata_names
property
The names of the current filtered schemas
Exact schema leaves contribute their name; schemata (is-a) leaves
expand to the schema plus its non-abstract descendants.
sql
property
__bool__()
Detect if any filter, ordering or slicing is defined
Examples:
__getitem__(value)
Implement list-like slicing. No negative values allowed.
Examples:
Returns:
| Type | Description |
|---|---|
Self
|
The updated |
Source code in ftmq/query/main.py
__hash__()
Generate a unique key of the current state, useful for caching.
Like any Python object this is a within-process hash (not stable
across processes); hash_data normalizes ordering so equal queries
hash equal.
Source code in ftmq/query/main.py
aggregate(*nodes)
Add aggregation projections to the query.
Example
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
*nodes
|
A
|
|
()
|
Returns:
| Type | Description |
|---|---|
Self
|
The updated |
Source code in ftmq/query/main.py
apply(entity)
apply_iter(entities)
Apply the current Query instance to a generator of entities and return
a generator of filtered entities
Example
Yields:
| Type | Description |
|---|---|
EntityProxies
|
A generator of |
Source code in ftmq/query/main.py
compile(source=None)
Compile this query to a SQLAlchemy Select of statements against a
SqlSource (a store's table descriptor).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
source
|
'SqlSource | None'
|
The SQL source to compile against (default: the base nomenklatura statement table). |
None
|
Returns:
| Type | Description |
|---|---|
'Select[Any]'
|
The statements |
Source code in ftmq/query/main.py
from_dict(data)
classmethod
Rebuild a Query from its to_dict output.
Source code in ftmq/query/main.py
from_params(args)
classmethod
Build a Query from an Aleph-style param dict / MultiDict.
Source code in ftmq/query/main.py
from_rql(value)
classmethod
Build a Query from an RQL string.
Unlike the flat Aleph grammar, RQL expresses arbitrary & | ~ nesting,
e.g. and(eq(schema,Person),or(eq(properties.name,jane),eq(countries,de))),
and carries aggregations via its sum / aggregate(...) operators.
Source code in ftmq/query/main.py
from_string(value)
classmethod
get_aggregator()
Build an in-memory Aggregator from the query's aggregation specs.
Returns:
| Type | Description |
|---|---|
Aggregator
|
A fresh accumulator over this query's aggregations. |
order_by(*values, ascending=True)
Add or update the current sorting.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
*values
|
str
|
Fields to order by |
()
|
ascending
|
bool | None
|
Ascending or descending |
True
|
Returns:
| Type | Description |
|---|---|
Self
|
The updated |
Source code in ftmq/query/main.py
to_dict()
Lossless nested-tree representation of the current object.
Example
Source code in ftmq/query/main.py
to_params()
Project to an Aleph-style filter param dict (filter: / exclude: /
empty: keys, metric: / facet aggregation keys, plus sort /
limit / offset).
Raises QueryError for queries outside the flat Aleph-expressible
subset (cross-field OR, negated groups).
Source code in ftmq/query/main.py
to_rql()
Serialize the filter tree and aggregations to an RQL string.
RQL is the only string surface that preserves arbitrary & | ~ nesting
(unlike the flat Aleph params) and carries aggregations losslessly, so it
is the way to hand a full query to another HTTP-like connector. Raises
QueryError for a comparator with no RQL equivalent (null,
startswith, endswith, ...).
Source code in ftmq/query/main.py
to_string()
Project to an Aleph URL query string, e.g.
filter:properties.name=Jane&filter:schemata=LegalEntity.
where(*nodes)
AND another set of M / P / G nodes into the current Query.
Example
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
*nodes
|
Expr
|
|
()
|
Returns:
| Type | Description |
|---|---|
Self
|
The updated |
Source code in ftmq/query/main.py
Query nodes
The composable filter-node constructors: M (meta), P (property), G (property-type group) and C (context). A is the aggregation-projection node (see Aggregations below).
Bases: _FamilyExpr
Meta-field conditions: dataset, schema, schemata, origin, id, ...
Source code in ftmq/query/nodes.py
Bases: _FamilyExpr
Specific-property conditions, e.g. P(name="Jane", amountEur__gte=1000).
Source code in ftmq/query/nodes.py
Bases: _FamilyExpr
Property-type group conditions, e.g. G(countries="de"), G(entities=id).
Source code in ftmq/query/nodes.py
Bases: _FamilyExpr
Context / storage-column conditions, e.g. C(origin="crawl"),
C(first_seen__gte="2024-01").
Source code in ftmq/query/nodes.py
An aggregation projection node: A(sum="amountEur", by="beneficiary").
Each keyword is an aggregation function (min, max, sum, avg,
count) whose value is the property (or properties) to aggregate; by=
groups by one or more properties / fields. Unlike the M/P/G/C
filter nodes, A is not a boolean leaf - it does not compose with
& | ~; pass it to Query.aggregate.
Examples:
Source code in ftmq/query/aggregations.py
Expression tree
A boolean node: a connector (AND/OR), an optional negation, and a
list of children (nested Expr nodes and/or Leaf conditions).
Source code in ftmq/query/nodes.py
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 | |
apply(entity)
Evaluate the boolean expression against an entity.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
entity
|
EntityProxy
|
The entity to test. |
required |
Returns:
| Type | Description |
|---|---|
bool
|
|
bool
|
negated) tree of conditions. |
Source code in ftmq/query/nodes.py
from_dict(data)
classmethod
Rebuild a tree from its to_dict form.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
dict[str, Any]
|
The nested mapping to deserialize. |
required |
Returns:
| Type | Description |
|---|---|
'Expr'
|
The reconstructed expression. |
Source code in ftmq/query/nodes.py
iter_leaves(cls=None)
Walk the tree and yield its leaf conditions.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
cls
|
type | None
|
Optionally restrict to leaves of this class. |
None
|
Yields:
| Type | Description |
|---|---|
Leaf
|
Each matching leaf, depth-first. |
Source code in ftmq/query/nodes.py
to_dict()
Serialize the tree to a nested, canonically-ordered dict.
Nested nodes that share the connector and are not negated are flattened
(associativity) and children are sorted, so structurally-equivalent
trees (e.g. built by different where() orderings) serialize
identically and hash equal.
Returns:
| Type | Description |
|---|---|
dict[str, Any]
|
A |
dict[str, Any]
|
Source code in ftmq/query/nodes.py
Combine a series of nodes with a single connector, skipping empties.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
*nodes
|
Expr
|
The |
()
|
connector
|
str
|
|
AND
|
Returns:
| Type | Description |
|---|---|
Expr | None
|
The combined expression, or |
Source code in ftmq/query/nodes.py
Leaves
Leaf conditions for the ftmq query language, split by the statement-table column they target:
- meta leaves (
M):dataset,schema(exact),schemata(is-a),id/entity_id/canonical_id. - the property leaf (
P): a specific FtM property (thepropcolumn). - the group leaf (
G): a followthemoney property-type group (theprop_typecolumn, keyed byregistry.groups:names,dates,countries,entities, ...). - the context leaf (
C): a provenance / storage column such asorigin,fragmentorfirst_seen(read fromentity.contextin-memory).
Lookup / BaseFilter handle comparator matching and value casting; the
Leaf subclasses add the per-family entity access plus correct null
(present/absent) semantics.
BaseFilter
Comparator + cast value; the shared base for all query Leaf classes.
The comparator is validated upstream by
parse_lookup; here it is a plain string.
Source code in ftmq/query/leaves.py
CanonicalIdLeaf
ContextLeaf
Bases: Leaf
A context field (the C family).
In-memory it reads entity.context[key] (always treated as multi-valued);
in SQL it maps to the same-named statement-table column. This is the general
form of provenance / storage fields - origin, and extra columns such as
fragment, first_seen, bucket - that are not followthemoney properties.
An entity without the key (or without a context) simply does not match.
Source code in ftmq/query/leaves.py
DatasetLeaf
EntityIdLeaf
GroupLeaf
Bases: Leaf
A property-type group (the prop_type column). entities is the
reverse-lookup group.
Source code in ftmq/query/leaves.py
IdLeaf
Leaf
Bases: BaseFilter
A single condition. Subclasses set family and implement values()
(the entity values to test) or override apply().
Source code in ftmq/query/leaves.py
apply(entity)
Test whether the entity matches this condition.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
entity
|
EntityProxy
|
The entity to test. |
required |
Returns:
| Type | Description |
|---|---|
bool
|
|
bool
|
for the |
Source code in ftmq/query/leaves.py
field_dict()
Serialize this leaf to a family-tagged mapping.
Returns:
| Type | Description |
|---|---|
LeafDict
|
The |
LeafDict
|
the query-tree serialization. |
Source code in ftmq/query/leaves.py
values(entity)
Yield the entity values this leaf tests against.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
entity
|
EntityProxy
|
The entity to read values from. |
required |
Yields:
| Type | Description |
|---|---|
str
|
The relevant string values (property values, schema name, ...). |
Source code in ftmq/query/leaves.py
LeafDict
Bases: TypedDict
Serialized form of a single Leaf condition.
Source code in ftmq/query/leaves.py
Lookup
Applies a single comparator to values (the in-memory match logic).
The comparator is a plain string, already validated by
parse_lookup.
Source code in ftmq/query/leaves.py
PropertyLeaf
Bases: Leaf
Matches a specific FtM property value (the prop column).
Source code in ftmq/query/leaves.py
SchemaLeaf
Bases: Leaf
Exact schema match.
Source code in ftmq/query/leaves.py
SchemataLeaf
Bases: Leaf
is-a match: the entity's schema (or one of its ancestors) is the
queried schema, i.e. model[X] in entity.schema.schemata.
Source code in ftmq/query/leaves.py
leaf_from_dict(data)
Reconstruct a leaf from its serialized LeafDict.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
LeafDict
|
The |
required |
Returns:
| Type | Description |
|---|---|
Leaf
|
The reconstructed leaf. |
Source code in ftmq/query/leaves.py
make_context_leaf(key, value)
Build a context leaf (the C family) from a lookup.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
key
|
str
|
A context / column key, e.g. |
required |
value
|
Any
|
The lookup value. |
required |
Returns:
| Type | Description |
|---|---|
Leaf
|
The resolved context leaf. |
Source code in ftmq/query/leaves.py
make_group_leaf(key, value)
Build a property-type group leaf (the G family) from a lookup.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
key
|
str
|
A group lookup key, e.g. |
required |
value
|
Any
|
The lookup value. |
required |
Returns:
| Type | Description |
|---|---|
Leaf
|
The resolved group leaf. |
Raises:
| Type | Description |
|---|---|
QueryError
|
If the group is not a valid |
Source code in ftmq/query/leaves.py
make_meta_leaf(key, value)
Build a meta leaf (the M family) from a lookup.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
key
|
str
|
A meta lookup key, e.g. |
required |
value
|
Any
|
The lookup value. |
required |
Returns:
| Type | Description |
|---|---|
Leaf
|
The resolved meta leaf. |
Raises:
| Type | Description |
|---|---|
QueryError
|
If the field is not a known meta field. |
Source code in ftmq/query/leaves.py
make_property_leaf(key, value)
Build a property leaf (the P family) from a lookup.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
key
|
str
|
A property lookup key, e.g. |
required |
value
|
Any
|
The lookup value. |
required |
Returns:
| Type | Description |
|---|---|
Leaf
|
The resolved property leaf. |
Raises:
| Type | Description |
|---|---|
QueryError
|
If the property is not a valid FtM property. |
Source code in ftmq/query/leaves.py
parse_lookup(key)
Split a field__comparator lookup key into its parts.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
key
|
str
|
A lookup key such as |
required |
Returns:
| Type | Description |
|---|---|
tuple[str, str]
|
A |
Raises:
| Type | Description |
|---|---|
QueryError
|
If the comparator suffix is not a valid comparator. |
Source code in ftmq/query/leaves.py
Aleph bridge
The filter half of the Aleph URL-param grammar. Query.to_params / from_params and to_string / from_string wrap these.
The Aleph / OpenAleph URL-param grammar: a bidirectional bridge between a
Query filter tree and the filter: / exclude: / empty: param convention
used by openaleph_search.SearchQueryParser.
The filter half (the mapping between the boolean tree and the param keys)
lives here, plus the aggregation half (metric:<func>=<prop> and
facet=<field>, matching openaleph's metric aggregations). sort / limit /
offset are query-level concerns handled by Query.to_params /
Query.from_params.
The param model is flat (AND across keys, OR within a key, exclude: and
empty: for negation / absence), so:
params_to_expris total and always yields a flat AND-of-leaves.expr_to_paramsis defined on that flat subset and raisesQueryErrorfor a cross-field OR or a negated group.
aggregations_to_params(aggs)
Project aggregation specs to openaleph metric / facet params.
Each spec becomes a metric:<func>=<prop> entry (the convention
openaleph_search.SearchQueryParser reads as
metrics = {func: {props}}); grouped fields become facet=<field>
values. openaleph nests every metric inside every facet bucket, so groups
apply across all metrics - a per-metric grouping that differs between
metrics collapses to their union here.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
aggs
|
set[Agg]
|
The query's aggregation specs. |
required |
Returns:
| Type | Description |
|---|---|
dict[str, list[str]]
|
The |
Source code in ftmq/query/aleph.py
expr_to_params(expr)
Project a filter tree to Aleph filter: / exclude: / empty: params.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
expr
|
Expr | None
|
The filter tree (or |
required |
Returns:
| Type | Description |
|---|---|
dict[str, list[str]]
|
The Aleph param mapping. |
Raises:
| Type | Description |
|---|---|
QueryError
|
If the tree is not Aleph-expressible (a cross-field |
Source code in ftmq/query/aleph.py
normalize_multidict(args)
Coerce params into a plain dict[str, list[str]].
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
args
|
Any
|
A werkzeug |
required |
Returns:
| Type | Description |
|---|---|
dict[str, list[str]]
|
A mapping of each key to its list of string values. |
Source code in ftmq/query/aleph.py
params_to_aggregations(items)
Rebuild aggregation specs from openaleph metric: / facet params.
The inverse of aggregations_to_params:
every facet field groups every metric:<func>=<prop> (matching how
openaleph computes a metric within each facet bucket).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
items
|
dict[str, list[str]]
|
A normalized param mapping. |
required |
Returns:
| Type | Description |
|---|---|
set[Agg]
|
The reconstructed aggregation specs (empty if there are no |
set[Agg]
|
params). |
Source code in ftmq/query/aleph.py
params_to_expr(items)
Build a filter tree from Aleph params (non-filter keys are ignored).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
items
|
dict[str, list[str]]
|
A normalized param mapping (see
|
required |
Returns:
| Type | Description |
|---|---|
Expr | None
|
The flat AND-of-leaves filter tree, or |
Source code in ftmq/query/aleph.py
params_to_string(params)
Render an Aleph param mapping as a URL query string.
Keys are sorted for deterministic output; value order within a key is
preserved (multi-field sort priority must not be reordered).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
params
|
dict[str, list[str]]
|
The param mapping. |
required |
Returns:
| Type | Description |
|---|---|
str
|
A |
Source code in ftmq/query/aleph.py
string_to_params(value)
Parse an Aleph URL query string into a param mapping.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
value
|
str
|
A |
required |
Returns:
| Type | Description |
|---|---|
dict[str, list[str]]
|
A mapping of each key to its list of url-decoded values. |
Source code in ftmq/query/aleph.py
RQL bridge
RQL support for nested filter trees, used by Query.from_rql.
RQL (Resource Query Language) bridge.
RQL is a URL-friendly query language of nestable named operators - e.g.
and(eq(schema,Person),or(eq(properties.name,jane),eq(countries,de))) - which
maps directly onto the ftmq Expr tree (and/or/not + comparison leaves).
Unlike the flat Aleph param grammar, RQL expresses arbitrary nesting, so this is
the way to carry a full M & (P | G) tree through a single string. It also
carries aggregations: RQL's native sum / min / max / mean / count and
aggregate(...) operators map onto ftmq A nodes, side by side with the filter
under a top-level and.
Field names follow the Aleph convention (schema, dataset, properties.<name>,
a registry.groups name, or origin); a bare name that matches none of those is
treated as an FtM property.
expr_to_rql(expr)
Convert an Expr tree to an RQL AST ({"name": ..., "args": [...]}).
Source code in ftmq/query/rql.py
parse_rql(value)
Parse an RQL query string into a filter Expr and aggregation specs.
Filter operators (and / or / not + comparisons) build the tree; the
aggregate operators (sum / min / max / mean / count / aggregate)
build the aggregations. At the top level they sit side by side under and.
Raises:
| Type | Description |
|---|---|
QueryError
|
If the RQL uses an unsupported operator or field. |
Source code in ftmq/query/rql.py
rql_to_expr(data)
Convert a parsed RQL AST ({"name": ..., "args": [...]}) to an Expr.
Source code in ftmq/query/rql.py
to_rql(expr, aggs=())
Serialize a filter tree and aggregation specs to an RQL query string.
Filters and aggregations sit side by side under a top-level and.
Raises:
| Type | Description |
|---|---|
QueryError
|
If a filter leaf uses a comparator with no RQL equivalent
( |
Source code in ftmq/query/rql.py
Aggregations
The A projection node, the immutable Agg spec and the in-memory Aggregator. See the aggregation guide.
Aggregations for the ftmq query language.
An aggregation is a projection over the matched entities (a SELECT-list /
GROUP BY concern), not a filter predicate: the A node does not compose with
the & | ~ boolean tree the M/P/G/C filter nodes build. It is declared
with Query.aggregate, parallel to where() and
order_by().
A(sum="amountEur", by="beneficiary") builds one immutable Agg
spec per func=prop pair. Aggregator is
the in-memory accumulator that runs those specs over a stream of entities; the
SQL backend reads the same specs (see [ftmq.query.sql][]).
A
An aggregation projection node: A(sum="amountEur", by="beneficiary").
Each keyword is an aggregation function (min, max, sum, avg,
count) whose value is the property (or properties) to aggregate; by=
groups by one or more properties / fields. Unlike the M/P/G/C
filter nodes, A is not a boolean leaf - it does not compose with
& | ~; pass it to Query.aggregate.
Examples:
Source code in ftmq/query/aggregations.py
Agg
dataclass
An immutable aggregation spec: a function over a property, optionally
grouped. Built via the A node or
Query.aggregate.
Source code in ftmq/query/aggregations.py
values(proxy, prop=None)
Yield the entity values for this spec's property (or a group prop).
Source code in ftmq/query/aggregations.py
Aggregator
In-memory accumulator: runs a set of Agg
specs over an entity stream.
A fresh instance per run holds all mutable state, so applying the same query twice never double-counts (the specs themselves are immutable).
Source code in ftmq/query/aggregations.py
result
property
The reduced result: {func: {prop: value}, "groups": {group: {func:
{prop: {group_value: value}}}}} (empties removed).
apply(proxies)
Collect every entity while passing the stream through unchanged.
collect(proxy)
Accumulate one entity's values into every spec.
Source code in ftmq/query/aggregations.py
aggregations_from_dict(data)
Rebuild aggregation specs from the output of
aggregations_to_dict,
restoring each spec's groups from the nested groups mapping.
Source code in ftmq/query/aggregations.py
aggregations_to_dict(aggs)
Serialize aggregation specs to the query to_dict shape:
{func: {props}, "groups": {group: {func: {props}}}}.
Source code in ftmq/query/aggregations.py
make_agg(func, prop, groups=())
Validate and build a single Agg spec.
Source code in ftmq/query/aggregations.py
reduce_values(func, values)
Reduce collected values with an aggregation function (None if empty).
Source code in ftmq/query/aggregations.py
SQL
The SQL translation. A store passes its SqlSource to Query.compile (or builds Sql(query, source) directly).
Describes the SQL statement source a Query compiles
against: the SQLAlchemy table (or view), the entity-identity column, and an
optional partition-pruning rule.
Stores own one and pass it to Sql /
Query.compile, replacing the old
query.table mutation. A downstream store with extra columns (a lake /
sharded table) supplies its own SqlSource so the same Query compiles
against it unchanged.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
table
|
Any
|
The SQLAlchemy |
required |
id_column
|
str
|
The entity-identity column name (default |
'canonical_id'
|
prune
|
dict[str, PruneFn] | None
|
Optional |
None
|
prune_column
|
str | None
|
The partition column the |
None
|
Source code in ftmq/query/sql.py
Source code in ftmq/query/sql.py
80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 | |