Trino
Trino federation connector.
Trino-dialect SQL helpers.
Trino is the OSS query engine commonly paired with the open-source unitycatalog.io implementation when callers need live federation to a foreign RDBMS — OSS UC itself has no native federation primitive (see SU#519 / SU#521).
The first surface here is siege_utilities.trino.federation,
which generates CREATE VIEW statements that select through Trino’s
postgresql connector. This is the OSS analog of
siege_utilities.databricks.lakehouse_federation for the Databricks
Lakehouse Federation use case.
- siege_utilities.trino.build_trino_federation_view_sql(target_catalog, target_schema, target_view, postgres_catalog, source_schema, source_table=None)[source]
Build SQL for a Trino federation view over a PostgreSQL source.
Generates a
CREATE OR REPLACE VIEWstatement intarget_catalog.target_schema.target_viewthat selects every column from the PostgreSQL tablepostgres_catalog.source_schema.source_tablevia Trino’spostgresqlconnector.All identifier fields are validated against the SU identifier allow-list before interpolation. The output is double-quoted in Trino’s ANSI dialect (not backticks).
- Parameters:
target_catalog (str) – Trino catalog the view lives in (e.g.
"iceberg"for an OSS UC-backed Iceberg catalog).target_schema (str) – Schema within the target catalog (e.g.
"analytics").target_view (str) – View name (e.g.
"persons").postgres_catalog (str) – Trino catalog alias for the PostgreSQL connector (whatever the operator named the
etc/catalog/postgresql.propertiesfile, sans extension).source_schema (str) – PostgreSQL schema (e.g.
"public").source_table (str | None) – PostgreSQL table name. Defaults to
target_viewwhen omitted, which is the common case (same name on both sides).
- Returns:
A single SQL statement ending in
;.- Return type:
Example
>>> build_trino_federation_view_sql( ... target_catalog="iceberg", ... target_schema="analytics", ... target_view="persons", ... postgres_catalog="postgresql", ... source_schema="public", ... ) 'CREATE OR REPLACE VIEW "iceberg"."analytics"."persons" AS\nSELECT * FROM "postgresql"."public"."persons";'
- siege_utilities.trino.build_trino_schema_and_view_sync_sql(target_catalog, target_schema, postgres_catalog, source_schema, tables)[source]
Build
CREATE SCHEMA+ per-tableCREATE VIEWstatements.Convenience for syncing many PostgreSQL tables into a Trino catalog in one pass. The schema statement uses
IF NOT EXISTSso the list is safe to re-run. Each view statement isCREATE OR REPLACEso re-runs after upstream column additions stay correct.- Parameters:
target_catalog (str) – Trino catalog the schema + views live in.
target_schema (str) – Schema within
target_catalog.postgres_catalog (str) – Trino PostgreSQL connector alias.
source_schema (str) – PostgreSQL schema containing
tables.tables (Iterable[str]) – Iterable of PostgreSQL table names. Same names are used for the Trino views.
- Returns:
one
CREATE SCHEMAfollowed by oneCREATE OR REPLACE VIEWper table, in the order given.- Return type:
List of SQL statements
- siege_utilities.trino.quote_ident(value)[source]
Quote an identifier in Trino dialect.
Trino uses ANSI double quotes for identifiers (not backticks like Databricks). Internal double-quote characters are escaped by doubling. Callers must validate identifiers before passing them here (the higher-level federation builders call
validate_sql_identifierbeforequote_ident).
Submodules
Trino SQL helpers for federating to a foreign RDBMS via Trino connectors.
This is the OSS analog of
siege_utilities.databricks.lakehouse_federation for the open-source
unitycatalog.io (and any other catalog Trino can write a VIEW into).
OSS Unity Catalog does NOT support live query federation natively
(no CREATE FOREIGN TABLE/USING CONNECTION syntax — that is
Databricks-specific). The OSS path is to configure Trino with the
postgresql connector (catalog config file), then expose the
foreign table under a stable name in a different Trino catalog via
CREATE OR REPLACE VIEW. Readers query the view; Trino does the
federation transparently.
This module generates the view-creation SQL. Catalog configuration
(the etc/catalog/*.properties files Trino reads at startup) is
out of scope — that is operator territory.
See SU#521 (umbrella) and SU#519 (root context).
- siege_utilities.trino.federation.build_trino_federation_view_sql(target_catalog, target_schema, target_view, postgres_catalog, source_schema, source_table=None)[source]
Build SQL for a Trino federation view over a PostgreSQL source.
Generates a
CREATE OR REPLACE VIEWstatement intarget_catalog.target_schema.target_viewthat selects every column from the PostgreSQL tablepostgres_catalog.source_schema.source_tablevia Trino’spostgresqlconnector.All identifier fields are validated against the SU identifier allow-list before interpolation. The output is double-quoted in Trino’s ANSI dialect (not backticks).
- Parameters:
target_catalog (str) – Trino catalog the view lives in (e.g.
"iceberg"for an OSS UC-backed Iceberg catalog).target_schema (str) – Schema within the target catalog (e.g.
"analytics").target_view (str) – View name (e.g.
"persons").postgres_catalog (str) – Trino catalog alias for the PostgreSQL connector (whatever the operator named the
etc/catalog/postgresql.propertiesfile, sans extension).source_schema (str) – PostgreSQL schema (e.g.
"public").source_table (str | None) – PostgreSQL table name. Defaults to
target_viewwhen omitted, which is the common case (same name on both sides).
- Returns:
A single SQL statement ending in
;.- Return type:
Example
>>> build_trino_federation_view_sql( ... target_catalog="iceberg", ... target_schema="analytics", ... target_view="persons", ... postgres_catalog="postgresql", ... source_schema="public", ... ) 'CREATE OR REPLACE VIEW "iceberg"."analytics"."persons" AS\nSELECT * FROM "postgresql"."public"."persons";'
- siege_utilities.trino.federation.build_trino_schema_and_view_sync_sql(target_catalog, target_schema, postgres_catalog, source_schema, tables)[source]
Build
CREATE SCHEMA+ per-tableCREATE VIEWstatements.Convenience for syncing many PostgreSQL tables into a Trino catalog in one pass. The schema statement uses
IF NOT EXISTSso the list is safe to re-run. Each view statement isCREATE OR REPLACEso re-runs after upstream column additions stay correct.- Parameters:
target_catalog (str) – Trino catalog the schema + views live in.
target_schema (str) – Schema within
target_catalog.postgres_catalog (str) – Trino PostgreSQL connector alias.
source_schema (str) – PostgreSQL schema containing
tables.tables (Iterable[str]) – Iterable of PostgreSQL table names. Same names are used for the Trino views.
- Returns:
one
CREATE SCHEMAfollowed by oneCREATE OR REPLACE VIEWper table, in the order given.- Return type:
List of SQL statements
- siege_utilities.trino.federation.quote_ident(value)[source]
Quote an identifier in Trino dialect.
Trino uses ANSI double quotes for identifiers (not backticks like Databricks). Internal double-quote characters are escaped by doubling. Callers must validate identifiers before passing them here (the higher-level federation builders call
validate_sql_identifierbeforequote_ident).