airflow.providers.apache.polaris.operators.policy

Operators for Polaris policies.

Polaris stores policies (for example the table-maintenance types system.snapshot-expiry, system.data-compaction, system.metadata-compaction and system.orphan-file-removal), attaches them to catalogs, namespaces and tables, and resolves which ones apply to a table through inheritance. It does not execute them; PolarisGetApplicablePoliciesOperator hands the resolved policies to downstream tasks that do.

Attributes

ORPHAN_FILE_REMOVAL

Classes

PolarisCreatePolicyOperator

Create a policy in a namespace, or bring an existing one up to date.

PolarisDropPolicyOperator

Drop a policy.

PolarisAttachPolicyOperator

Attach a policy to a catalog, namespace or table. Re-attaching the same policy is a no-op.

PolarisDetachPolicyOperator

Detach a policy from a catalog, namespace or table.

PolarisGetApplicablePoliciesOperator

Resolve the policies in effect on a catalog, namespace or table (inheritance applied by Polaris).

Functions

policy_to_dict(policy)

Return a JSON-serializable view of a policy, with content parsed from its JSON string.

Module Contents

airflow.providers.apache.polaris.operators.policy.ORPHAN_FILE_REMOVAL = 'system.orphan-file-removal'[source]
airflow.providers.apache.polaris.operators.policy.policy_to_dict(policy)[source]

Return a JSON-serializable view of a policy, with content parsed from its JSON string.

class airflow.providers.apache.polaris.operators.policy.PolarisCreatePolicyOperator(*, namespace, policy_name, policy_type, content=None, description=None, catalog=None, if_exists='update', **kwargs)[source]

Bases: airflow.providers.apache.polaris.operators.base.PolarisCatalogBaseOperator

Create a policy in a namespace, or bring an existing one up to date.

See also

For more information, take a look at the guide: PolarisCreatePolicyOperator

Parameters:
  • namespace (str | list[str]) – Namespace that holds the policy, as "a.b" or ["a", "b"].

  • policy_name (str) – Policy name, unique within the namespace.

  • policy_type (str) – Policy type, for example system.snapshot-expiry.

  • content (dict[str, Any] | str | None) – Policy content as a dict or JSON string; Polaris validates it against the type’s schema.

  • description (str | None) – Optional description.

  • catalog (str | None) – Catalog; defaults to the connection’s default_catalog.

  • if_exists (airflow.providers.apache.polaris.hooks.polaris.IfPolicyExists) – "update" (default) updates content and description when they differ, so the task is declarative; "skip" leaves an existing policy unchanged; "fail" raises.

  • polaris_conn_id – Polaris connection id.

Returns:

The policy as a dict, with content parsed.

template_fields: collections.abc.Sequence[str] = ('polaris_conn_id', 'namespace', 'policy_name', 'policy_type', 'content', 'description', 'catalog')[source]
template_fields_renderers[source]
namespace[source]
policy_name[source]
policy_type[source]
content = None[source]
description = None[source]
catalog = None[source]
if_exists = 'update'[source]
execute(context)[source]

Derive when creating an operator.

The main method to execute the task. Context is the same dictionary used as when rendering jinja templates.

Refer to get_template_context for more context.

class airflow.providers.apache.polaris.operators.policy.PolarisDropPolicyOperator(*, namespace, policy_name, detach_all=False, catalog=None, if_missing='skip', **kwargs)[source]

Bases: airflow.providers.apache.polaris.operators.base.PolarisCatalogBaseOperator

Drop a policy.

See also

For more information, take a look at the guide: Attaching, detaching and dropping policies

Parameters:
Returns:

True if dropped, False if it did not exist.

template_fields: collections.abc.Sequence[str] = ('polaris_conn_id', 'namespace', 'policy_name', 'catalog')[source]
namespace[source]
policy_name[source]
detach_all = False[source]
catalog = None[source]
if_missing = 'skip'[source]
execute(context)[source]

Derive when creating an operator.

The main method to execute the task. Context is the same dictionary used as when rendering jinja templates.

Refer to get_template_context for more context.

class airflow.providers.apache.polaris.operators.policy.PolarisAttachPolicyOperator(*, namespace, policy_name, target, parameters=None, catalog=None, **kwargs)[source]

Bases: airflow.providers.apache.polaris.operators.base.PolarisCatalogBaseOperator

Attach a policy to a catalog, namespace or table. Re-attaching the same policy is a no-op.

A target holds at most one inheritable policy of each type. If a different policy of the same type is already attached, the task fails without retrying; detach the other policy first.

See also

For more information, take a look at the guide: Attaching, detaching and dropping policies

Parameters:
  • namespace (str | list[str]) – Namespace that holds the policy, as "a.b" or ["a", "b"].

  • policy_name (str) – Policy to attach.

  • target (dict[str, Any]) – {"type": "catalog"}, {"type": "namespace", "path": ["sales"]} or {"type": "table-like", "path": ["sales", "orders"]}.

  • parameters (dict[str, str] | None) – Optional attachment parameters.

  • catalog (str | None) – Catalog; defaults to the connection’s default_catalog.

  • polaris_conn_id – Polaris connection id.

template_fields: collections.abc.Sequence[str] = ('polaris_conn_id', 'namespace', 'policy_name', 'target', 'parameters', 'catalog')[source]
template_fields_renderers[source]
namespace[source]
policy_name[source]
target[source]
parameters = None[source]
catalog = None[source]
execute(context)[source]

Derive when creating an operator.

The main method to execute the task. Context is the same dictionary used as when rendering jinja templates.

Refer to get_template_context for more context.

class airflow.providers.apache.polaris.operators.policy.PolarisDetachPolicyOperator(*, namespace, policy_name, target, catalog=None, if_missing='skip', **kwargs)[source]

Bases: airflow.providers.apache.polaris.operators.base.PolarisCatalogBaseOperator

Detach a policy from a catalog, namespace or table.

See also

For more information, take a look at the guide: Attaching, detaching and dropping policies

Parameters:
Returns:

True if detached, False if it was not attached.

template_fields: collections.abc.Sequence[str] = ('polaris_conn_id', 'namespace', 'policy_name', 'target', 'catalog')[source]
template_fields_renderers[source]
namespace[source]
policy_name[source]
target[source]
catalog = None[source]
if_missing = 'skip'[source]
execute(context)[source]

Derive when creating an operator.

The main method to execute the task. Context is the same dictionary used as when rendering jinja templates.

Refer to get_template_context for more context.

class airflow.providers.apache.polaris.operators.policy.PolarisGetApplicablePoliciesOperator(*, catalog=None, namespace=None, table=None, policy_types=None, per_table=False, enabled_only=True, **kwargs)[source]

Bases: airflow.providers.apache.polaris.operators.base.PolarisCatalogBaseOperator

Resolve the policies in effect on a catalog, namespace or table (inheritance applied by Polaris).

Two output shapes:

  • per_table=False (default): a list of policies for the target, each {"name", "type", "description", "inheritable", "version", "content", "inherited", "defined_in"} with content parsed from JSON.

  • per_table=True: one item per (table, policy) for every table in namespace, ready for dynamic task mapping: {"catalog", "namespace", "table", "policy": {...}}. Items for system.orphan-file-removal policies also carry table_location (the table’s base location), so a downstream task can check that the policy’s locations stay inside it.

See also

For more information, take a look at the guide: PolarisGetApplicablePoliciesOperator

Parameters:
  • catalog (str | None) – Catalog; defaults to the connection’s default_catalog.

  • namespace (str | list[str] | None) – Namespace to resolve for ("a.b" or ["a", "b"]). Required with per_table or table; omit both for the catalog itself.

  • table (str | None) – A single table in namespace. Not allowed with per_table.

  • policy_types (list[str] | str | None) – Only return policies of these types (a list, or one type as a string).

  • per_table (bool) – Resolve policies for every table in namespace.

  • enabled_only (bool) – Drop policies whose content has "enable": false (default true).

  • polaris_conn_id – Polaris connection id.

Returns:

With per_table=False, a list of policy dicts; with per_table=True, a list of {"catalog", "namespace", "table", "policy"} items (plus "table_location" for system.orphan-file-removal), one per table and policy.

template_fields: collections.abc.Sequence[str] = ('polaris_conn_id', 'catalog', 'namespace', 'table', 'policy_types')[source]
catalog = None[source]
namespace = None[source]
table = None[source]
policy_types = None[source]
per_table = False[source]
enabled_only = True[source]
execute(context)[source]

Derive when creating an operator.

The main method to execute the task. Context is the same dictionary used as when rendering jinja templates.

Refer to get_template_context for more context.

Was this entry helpful?