airflow.providers.apache.polaris.utils.maintenance

Turn resolved Polaris table-maintenance policies into Iceberg’s Spark procedure calls.

Polaris stores and resolves maintenance policies but does not run them. to_spark_sql() turns one item returned by PolarisGetApplicablePoliciesOperator(per_table=True) into the CALL statement that applies it, for a Spark task to run. It makes no network calls.

Attributes

log

PROCEDURES

PASS_THROUGH

Functions

to_spark_sql(item, *[, spark_catalog, strict, dry_run])

Return the Iceberg Spark CALL statement that applies one resolved maintenance policy.

Module Contents

airflow.providers.apache.polaris.utils.maintenance.log[source]
airflow.providers.apache.polaris.utils.maintenance.PROCEDURES[source]
airflow.providers.apache.polaris.utils.maintenance.PASS_THROUGH[source]
airflow.providers.apache.polaris.utils.maintenance.to_spark_sql(item, *, spark_catalog=None, strict=False, dry_run=False)[source]

Return the Iceberg Spark CALL statement that applies one resolved maintenance policy.

Policy settings map to procedure arguments as follows; times become UTC timestamps counted back from now:

  • system.snapshot-expiry -> expire_snapshots: config.max_snapshot_age_days -> older_than, config.min_snapshot_to_keep -> retain_last.

  • system.data-compaction -> rewrite_data_files: config.compaction_strategy (bin-pack or sort) -> strategy, config.target_file_size_bytes and every hyphenated key (an Iceberg rewrite option, e.g. min-input-files) -> options.

  • system.metadata-compaction -> rewrite_manifests.

  • system.orphan-file-removal -> remove_orphan_files: max_orphan_file_age_in_days (at least 1, as Iceberg requires) -> older_than; each of locations -> one statement with location, which must lie inside the table’s location.

Other config keys named in PASS_THROUGH are passed as the procedure argument of the same name. Any other key is dropped with a warning, or raises with strict=True.

Parameters:
  • item (dict[str, Any]) – One item of PolarisGetApplicablePoliciesOperator(per_table=True).

  • spark_catalog (str | None) – Name of the Polaris catalog in Spark, used for the CALL and to qualify the table; defaults to the Polaris catalog name.

  • strict (bool) – Raise on config keys this function does not map, instead of dropping them.

  • dry_run (bool) – Only list orphan files (dry_run => true). Raises for other policy types, which have no dry run.

Returns:

The statement; for an orphan-file policy with several locations, one statement per location, separated by ; (spark-sql and SparkSqlOperator run them all; PySpark’s spark.sql() takes one at a time).

Raises:

PolarisInvalidArgumentError – For a policy that is disabled, of an unsupported type or schema version, or that holds invalid values.

Return type:

str

Was this entry helpful?