Skip to main content

Standard.find_tables()

List the tables of a source that the standard applies to.

Usage

Source

Standard.find_tables(
    source,
    applies_to=None,
)

This method finds the tables of a source and selects those that apply() would validate, without reading or validating any of them. Use it to check a selector before applying a standard to a large source, or to see which tables a standard covers now (such as tables that were added since it was last applied).

Parameters

source: Any

The tables: a dictionary of names to tables, an Ibis connection or a connection string, a directory, a glob pattern, or a list of files (see the Sources of Tables section of Standard).

applies_to: TableSelector | None = None
A table selector that’s used instead of the standard’s applies_to=.

Returns

list[str]
The names of the selected tables, in the order of the source (sorted by name for the files of a directory or a glob pattern).

Examples

Here’s a directory with three files, two of them extracts of customer data.

import pointblank as pb
import polars as pl
import tempfile
from pathlib import Path

landing = Path(tempfile.mkdtemp())

pl.DataFrame({"id": [1, 2]}).write_csv(landing / "customers_eu.csv")
pl.DataFrame({"id": [3, 4]}).write_csv(landing / "customers_us.csv")
pl.DataFrame({"sku": ["A"]}).write_parquet(landing / "products.parquet")

customer_standard = pb.Standard(
    name="customer-extracts",
    steps=[pb.Step("rows_distinct")],
    applies_to=pb.tbl_starts_with("customers_"),
)

customer_standard.find_tables(landing)
['customers_eu', 'customers_us']

The tables are named by their files, without the extensions. With applies_to=, the same standard can be pointed at a different selection:

customer_standard.find_tables(landing, applies_to=pb.tbl_everything())
['customers_eu', 'customers_us', 'products']

All three files are tables of the directory.