build_sql

function of dascore.io.index.query source

build_sql(
    query: dascore.io.index.query.Query | collections.abc.Sequence[Query, collections.abc.Sequence[Query]] ,
    attr_meta: DataFrame ,
    coord_meta: DataFrame ,
    count: bool = False,
    order_by = None,
    patch_ids = None,
    ids_only: bool = False,
)-> ‘tuple[str, list, list[tuple[str, re.Pattern]]]’

Build SQL for one or more AND-composed queries.

By default this projects the flat relation; with count=True the same WHERE is reused for a COUNT with no projection, coordinate pivot, or ordering; with ids_only=True only ordered patch ids are projected (the cheap realization slices/windows use). coord_meta must cover every coordinate the queries reference (it may be empty for attr-only queries). order_by overrides the default ordinal ordering (see _order_clause); patch_ids restricts rows to an id membership (one JSON parameter, so the SQLite bound-variable cap does not limit membership size).

Returns (sql, params, residuals), where residuals pairs attr names with regex patterns that must be re-applied to the resulting dataframe. For a count a non-empty residual means the count is not SQL-resolvable (regex must inspect rows) and the caller must fall back to a projected count.