Source: ds_platform_utils.metaflow.write_audit_publish.publish
Publishes data to a Snowflake table using the write-audit-publish (WAP) pattern.
publish(
table_name: str,
query: str | Path,
audits: list[str | Path] | None = None,
ctx: dict[str, Any] | None = None,
warehouse: Literal["XS", "MED", "XL"] = None,
use_utc: bool = True,
tags: dict[str, str] | None = None,
) -> None- Reads SQL from a string or
.sqlpath. - Runs write/audit/publish operations through Snowflake.
- Adds operation details and table links to the Metaflow card when available.
- Automatically applies ownership object tags to production tables (see Ownership tags below).
| Parameter | Type | Required | Description |
|---|---|---|---|
table_name |
str |
Yes | Destination Snowflake table name for the publish operation. |
query |
str | Path |
Yes | SQL query text or path to SQL file that produces the table data. |
audits |
list[str | Path] | None |
No | Optional SQL audits (strings or file paths) executed as validation checks. |
ctx |
dict[str, Any] | None |
No | Optional template substitution context for SQL operations. |
warehouse |
Literal["XS", "MED", "XL"] | None |
No | Snowflake warehouse override for this operation. Supports XS/MED/XL shortcuts or a full warehouse name. |
use_utc |
bool |
No | If True, uses UTC timezone for Snowflake session. |
tags |
dict[str, str] | None |
No | Overrides for the ownership object tags applied to the published table. See Ownership tags. |
Returns: None
from ds_platform_utils.metaflow import publish
publish(
table_name="MY_TABLE",
query="SELECT * FROM PATTERN_DB.{{schema}}.SOURCE",
audits=["SELECT COUNT(*) > 0 FROM PATTERN_DB.{{schema}}.{{table_name}}"],
)When publishing to production, publish() automatically applies the table-ownership
object tags from the table-ownership RFC. The seven tags are:
| Tag | Source | Always set? |
|---|---|---|
TABLE_OWNER |
ds.owner flow tag, else owning-team alias derived from the domain (ds-<domain>-team), else unknown |
yes |
TABLE_TEAM |
data-science |
yes |
TABLE_DOMAIN |
ds.domain Metaflow tag, else unknown |
yes |
TABLE_PROJECT |
ds.project Metaflow tag, else unknown |
yes |
TABLE_STATUS |
active (override allows active/development/testing/deprecated/archived/retired) |
yes |
TABLE_SLA |
override only (streaming/realtime/hourly/daily/weekly/monthly/quarterly/ad_hoc/on_demand) |
only if given |
TABLE_CONTACT |
override only (Slack channel or email) | only if given |
TABLE_OWNERis not the run user. Owner is resolved by priority: (1) an explicittags={"owner": ...}override, else (2) theds.ownerMetaflow flow tag (set in CI alongsideds.domain/ds.project), else (3) the owning-team aliasds-<domain>-teamwhen the domain is known (e.g. domainadvertising→ds-advertising-team), else (4)unknown. We don't usecurrent.username, because on deployed/argo runs it resolves to a service identity (argo-workflows) rather than a person. Setds.owneron the flow for a per-flow owner, or passtags={"owner": ...}per call.
TABLE_DOMAIN/TABLE_PROJECTdepend on flow tags. These are read from theds.domain/ds.projectMetaflow tags. If a flow runs without them, the value falls back to the literal stringunknownand a warning is printed (the same warning used for select.dev cost tracking). Make sure your flow carries--tag "ds.domain:..."and--tag "ds.project:..."— these are applied automatically in CI and the standardpoerun commands in the monorepo — or passtags={"domain": ..., "project": ...}explicitly. Note: because owner is derived from the domain, a missing domain also meansTABLE_OWNERfalls back tounknown.
Pass tags= to override any value. Keys may be owner/team/domain/project/
status/sla/contact (optionally TABLE_-prefixed):
publish(
table_name="OUT_OF_STOCK_ADS",
query="sql/create_training_data.sql",
tags={"sla": "daily", "contact": "#ds-recsys", "status": "active"},
)Notes:
- Tags are applied only to production tables (
DATA_SCIENCE). Non-prod (DATA_SCIENCE_STAGE) runs apply no tags. The publishing role needsAPPLYon the tags. - The tag definitions must first be created once by a Snowflake admin in
DATA_SCIENCE(the RFCCREATE TAGsetup). Until then, tagging is skipped with a warning — the publish still succeeds. - Invalid
status/slavalues raiseValueErrorbefore any data is written. - Tagged tables surface in the
TABLE_OWNERSHIP_REGISTRYview (see Table-ownership registry view).