Skip to main content

tbl_contains()

Select tables whose names contain some text.

Usage

Source

tbl_contains(
    text,
    case_sensitive=False,
)

tbl_contains() selects the tables whose names contain text= anywhere, which is useful when a word identifies a group of tables wherever it appears in their names (e.g., all tables about customers: customers, stg_customer_events, and customer_addresses). Like the other table selectors, it’s used in the applies_to= argument of a Standard or of Standard.apply(). The name tested is the table’s own name, without a schema or a file extension.

Parameters

text: str

The text that a table’s name must contain.

case_sensitive: bool = False
Whether the comparison is case-sensitive. The default is False.

Returns

TableSelector
A table selector, which can be combined with other table selectors with & (and), | (or), - (difference), and ~ (not).

Examples

A standard for every table about customers, except the temporary ones, combines tbl_contains() with a negated tbl_ends_with():

import pointblank as pb
import polars as pl

tables = {
    "customers": pl.DataFrame({"id": [1]}),
    "stg_customer_events": pl.DataFrame({"id": [1]}),
    "customer_addresses_tmp": pl.DataFrame({"id": [1]}),
    "orders": pl.DataFrame({"id": [1]}),
}

customer_standard = pb.Standard(
    name="customer-tables",
    steps=[pb.Step("col_vals_not_null", columns="id")],
    applies_to=pb.tbl_contains("customer") & ~pb.tbl_ends_with("_tmp"),
)

customer_standard.find_tables(tables)
['customers', 'stg_customer_events']

The temporary table is excluded by the second selector, and orders doesn’t contain the word at all.