Select tables whose names start with some text.
tbl_starts_with(
text,
case_sensitive=False,
)
The table selectors choose the tables of a source that a Standard applies to, just as the column selectors (like starts_with()) choose the columns of a table that a validation step checks. tbl_starts_with() selects the tables whose names start with text=, which suits the common practice of naming tables by their layer or domain (e.g., stg_orders, stg_customers, and stg_payments for the staging tables).
The name tested is the table’s own name, without a schema (for a database) or a file extension (for a directory of files).
Parameters
text: str
-
The text that a table’s name must start with.
case_sensitive: bool = False
-
Whether the comparison is case-sensitive. The default is
False.
Returns
TableSelector
-
A table selector, for the
applies_to= argument of Standard or of Standard.apply(). It can be combined with other table selectors with & (and), | (or), - (difference), and ~ (not).
Examples
Let’s say that a source has four tables, two of them staging tables. A standard that applies to tables whose names start with "stg_" finds just those two:
import pointblank as pb
import polars as pl
tables = {
"stg_orders": pl.DataFrame({"id": [1, 2]}),
"stg_customers": pl.DataFrame({"id": [1, 2]}),
"orders": pl.DataFrame({"id": [1, 2]}),
"customers": pl.DataFrame({"id": [1, 2]}),
}
staging_standard = pb.Standard(
name="staging-keys",
steps=[pb.Step("rows_distinct")],
applies_to=pb.tbl_starts_with("stg_"),
)
staging_standard.find_tables(tables)
['stg_orders', 'stg_customers']
find_tables() lists the tables that apply() would validate, without reading any of them.