fsspeckit.core.maintenance API Reference¶
maintenance
¶
Backend-neutral maintenance layer for parquet dataset operations.
This module provides shared functionality for dataset discovery, statistics, and grouping algorithms used by both DuckDB and PyArrow maintenance operations. It serves as the authoritative implementation for maintenance planning, ensuring consistent behavior across different backends.
Key responsibilities: 1. Dataset discovery and file-level statistics 2. Compaction grouping algorithms with streaming execution 3. Optimization planning with z-order validation 4. Canonical statistics structures 5. Partition filtering and edge case handling
Architecture: - Functions accept both dict format (legacy) and FileInfo objects for backward compatibility - All planning functions return structured results with canonical MaintenanceStats - Backend implementations delegate to this core for consistent behavior - Streaming design avoids materializing entire datasets in memory
Core components: - FileInfo: Canonical file information with validation - MaintenanceStats: Canonical statistics structure across backends - CompactionGroup: Logical grouping of files for processing - collect_dataset_stats: Dataset discovery with partition filtering - plan_compaction_groups: Shared compaction planning algorithm - plan_optimize_groups: Shared optimization planning with z-order validation
Usage: Backend functions should delegate to this module rather than implementing their own discovery and planning logic. This ensures that DuckDB and PyArrow produce identical grouping decisions and statistics structures.
Classes¶
fsspeckit.core.maintenance.DatasetMaintenanceCoordinator
¶
DatasetMaintenanceCoordinator(
backend: str | MaintenanceBackend,
)
Direct coordinator that creates immutable, backend-pinned maintenance plans.
Planning is lock-free and does not modify dataset files. Execution
implements the full staged-rename lifecycle for atomic_local
:class:CompactionPlan (flat local datasets, issue #37) and the
staged-copy lifecycle for best_effort_object_store
:class:CompactionPlan (issue #39). Other plan types are left as
typed seams with descriptive NotImplementedError messages.
Source code in src/fsspeckit/core/maintenance.py
Functions¶
fsspeckit.core.maintenance.DatasetMaintenanceCoordinator.execute
¶
execute(
plan: MaintenancePlan,
filesystem: AbstractFileSystem | None = None,
lock_timeout_s: float = 30.0,
lock_retry_interval_s: float = 0.05,
) -> MaintenanceResult
Execute an accepted maintenance plan and return a typed result.
Implemented paths:
atomic_local:class:CompactionPlan— full staged-rename lifecycle with advisory locking and partition-subtree preservation.atomic_local:class:PartitionLocalDeduplicationPlan— partition-local staged-rename deduplication with rollback.atomic_local:class:GlobalRepartitionDeduplicationPlan— global cross-partition staged-rename deduplication with rollback (#42).best_effort_object_store:class:CompactionPlan— staged-copy lifecycle with per-key validation, source-drift revalidation, and recovery artifact reporting. filesystem is required for this path.best_effort_object_store:class:PartitionLocalDeduplicationPlan— staged-copy deduplication with per-key validation and source-drift revalidation.best_effort_object_store:class:GlobalRepartitionDeduplicationPlan— staged-copy global repartitioning deduplication.atomic_local:class:CoordinatedOptimizationPlan— optional partition-local deduplication followed by compaction through one staged, validated, locked, and rollback-capable publication.best_effort_object_store:class:CoordinatedOptimizationPlan— optional partition-local deduplication followed by compaction, reported as separate phases. filesystem is required for this path.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
plan
|
MaintenancePlan
|
An accepted plan created by one of the |
required |
filesystem
|
AbstractFileSystem | None
|
Required for |
None
|
lock_timeout_s
|
float
|
Maximum seconds to wait for the publication lock
( |
30.0
|
lock_retry_interval_s
|
float
|
Sleep between lock-acquisition retries
( |
0.05
|
Returns:
| Name | Type | Description |
|---|---|---|
A |
MaintenanceResult
|
class: |
MaintenanceResult
|
subclass) carrying per-phase outcomes, validation, publication, |
|
MaintenanceResult
|
recovery artifacts, and actual metrics. |
Raises:
| Type | Description |
|---|---|
NotImplementedError
|
For plan types or guarantee levels not yet implemented in this release. |
ValueError
|
When filesystem is not provided for a
|
Source code in src/fsspeckit/core/maintenance.py
5272 5273 5274 5275 5276 5277 5278 5279 5280 5281 5282 5283 5284 5285 5286 5287 5288 5289 5290 5291 5292 5293 5294 5295 5296 5297 5298 5299 5300 5301 5302 5303 5304 5305 5306 5307 5308 5309 5310 5311 5312 5313 5314 5315 5316 5317 5318 5319 5320 5321 5322 5323 5324 5325 5326 5327 5328 5329 5330 5331 5332 5333 5334 5335 5336 5337 5338 5339 5340 5341 5342 5343 5344 5345 5346 5347 5348 5349 5350 5351 5352 5353 5354 5355 5356 5357 5358 5359 5360 5361 5362 5363 5364 5365 5366 5367 5368 5369 5370 5371 5372 5373 5374 5375 5376 5377 5378 5379 5380 5381 5382 5383 5384 5385 5386 5387 5388 5389 5390 5391 5392 5393 5394 5395 5396 5397 5398 5399 5400 5401 5402 5403 5404 5405 5406 5407 5408 5409 5410 5411 5412 5413 5414 5415 5416 5417 5418 5419 5420 5421 5422 5423 5424 5425 5426 | |
fsspeckit.core.maintenance.DatasetMaintenanceCoordinator.plan_compaction
¶
plan_compaction(
dataset_path: str,
filesystem: AbstractFileSystem | None = None,
target_mb_per_file: int | None = None,
target_rows_per_file: int | None = None,
partition_filter: list[str] | None = None,
validation_level: ValidationLevel | str | None = None,
codec: str | None = None,
) -> CompactionPlan
Create an immutable compaction plan without modifying files.
Source code in src/fsspeckit/core/maintenance.py
4983 4984 4985 4986 4987 4988 4989 4990 4991 4992 4993 4994 4995 4996 4997 4998 4999 5000 5001 5002 5003 5004 5005 5006 5007 5008 5009 5010 5011 5012 5013 5014 5015 5016 5017 5018 5019 5020 5021 5022 5023 5024 5025 5026 5027 5028 5029 5030 5031 5032 5033 5034 5035 5036 5037 5038 5039 5040 5041 5042 5043 5044 5045 | |
fsspeckit.core.maintenance.DatasetMaintenanceCoordinator.plan_coordinated_optimization
¶
plan_coordinated_optimization(
dataset_path: str,
filesystem: AbstractFileSystem | None = None,
dedup_key_columns: list[str] | None = None,
dedup_order_by: list[str] | None = None,
target_mb_per_file: int | None = None,
target_rows_per_file: int | None = None,
partition_filter: list[str] | None = None,
validation_level: ValidationLevel | str | None = None,
codec: str | None = None,
) -> CoordinatedOptimizationPlan
Create an immutable coordinated optimization plan.
Coordinated optimization is defined as optional deduplication followed by compaction. No z-ordering, sorting, or implicit repartitioning is planned.
Source code in src/fsspeckit/core/maintenance.py
5193 5194 5195 5196 5197 5198 5199 5200 5201 5202 5203 5204 5205 5206 5207 5208 5209 5210 5211 5212 5213 5214 5215 5216 5217 5218 5219 5220 5221 5222 5223 5224 5225 5226 5227 5228 5229 5230 5231 5232 5233 5234 5235 5236 5237 5238 5239 5240 5241 5242 5243 5244 5245 5246 5247 5248 5249 5250 5251 5252 5253 5254 5255 5256 5257 5258 5259 5260 5261 5262 5263 5264 5265 5266 | |
fsspeckit.core.maintenance.DatasetMaintenanceCoordinator.plan_global_repartition_deduplication
¶
plan_global_repartition_deduplication(
dataset_path: str,
partition_columns: list[str],
filesystem: AbstractFileSystem | None = None,
key_columns: list[str] | None = None,
dedup_order_by: list[str] | None = None,
target_mb_per_file: int | None = None,
target_rows_per_file: int | None = None,
validation_level: ValidationLevel | str | None = None,
codec: str | None = None,
) -> GlobalRepartitionDeduplicationPlan
Create an immutable global-repartitioning deduplication plan.
Source code in src/fsspeckit/core/maintenance.py
5107 5108 5109 5110 5111 5112 5113 5114 5115 5116 5117 5118 5119 5120 5121 5122 5123 5124 5125 5126 5127 5128 5129 5130 5131 5132 5133 5134 5135 5136 5137 5138 5139 5140 5141 5142 5143 5144 5145 5146 5147 5148 5149 5150 5151 5152 5153 5154 5155 5156 5157 5158 5159 5160 5161 5162 5163 5164 5165 5166 5167 5168 5169 5170 5171 5172 5173 5174 5175 5176 5177 5178 5179 5180 5181 5182 5183 5184 5185 5186 5187 5188 5189 5190 5191 | |
fsspeckit.core.maintenance.DatasetMaintenanceCoordinator.plan_partition_local_deduplication
¶
plan_partition_local_deduplication(
dataset_path: str,
filesystem: AbstractFileSystem | None = None,
key_columns: list[str] | None = None,
dedup_order_by: list[str] | None = None,
target_mb_per_file: int | None = None,
target_rows_per_file: int | None = None,
partition_filter: list[str] | None = None,
validation_level: ValidationLevel | str | None = None,
codec: str | None = None,
) -> PartitionLocalDeduplicationPlan
Create an immutable partition-local deduplication plan.
Source code in src/fsspeckit/core/maintenance.py
fsspeckit.core.maintenance.MaintenancePlan
dataclass
¶
MaintenancePlan(
operation: MaintenanceOperation,
source_snapshot: SourceSnapshot,
selected_backend: str,
guarantee_level: GuaranteeLevel,
partition_scope: PartitionScope,
schema_outcome: SchemaOutcome,
selected_codec: str,
max_rows_per_file: int | None,
target_byte_size: int | None,
validation_level: ValidationLevel,
schema: Schema | None = None,
)
Base immutable maintenance plan.
Attributes:
| Name | Type | Description |
|---|---|---|
operation |
MaintenanceOperation
|
The maintenance operation this plan represents. |
source_snapshot |
SourceSnapshot
|
Snapshot of the source dataset at plan time. |
selected_backend |
str
|
Backend pinned to this plan. |
guarantee_level |
GuaranteeLevel
|
Automatic guarantee classification. |
partition_scope |
PartitionScope
|
Partition scope of the operation. |
schema_outcome |
SchemaOutcome
|
Lossless schema-reconciliation outcome. |
selected_codec |
str
|
Selected compression codec. |
max_rows_per_file |
int | None
|
Hard upper bound on output rows per file. |
target_byte_size |
int | None
|
Advisory target for output bytes per file. |
validation_level |
ValidationLevel
|
Validation level requested for the operation. |
schema |
Schema | None
|
Optional captured source schema. |
fsspeckit.core.maintenance.CompactionPlan
dataclass
¶
CompactionPlan(
operation: MaintenanceOperation,
source_snapshot: SourceSnapshot,
selected_backend: str,
guarantee_level: GuaranteeLevel,
partition_scope: PartitionScope,
schema_outcome: SchemaOutcome,
selected_codec: str,
max_rows_per_file: int | None,
target_byte_size: int | None,
validation_level: ValidationLevel,
schema: Schema | None = None,
compaction_groups: tuple[CompactionGroup, ...] = (),
)
fsspeckit.core.maintenance.PartitionLocalDeduplicationPlan
dataclass
¶
PartitionLocalDeduplicationPlan(
operation: MaintenanceOperation,
source_snapshot: SourceSnapshot,
selected_backend: str,
guarantee_level: GuaranteeLevel,
partition_scope: PartitionScope,
schema_outcome: SchemaOutcome,
selected_codec: str,
max_rows_per_file: int | None,
target_byte_size: int | None,
validation_level: ValidationLevel,
schema: Schema | None = None,
dedup_key_columns: tuple[str, ...] | None = None,
dedup_order_by: tuple[str, ...] | None = None,
dedup_groups: tuple[CompactionGroup, ...] = (),
)
fsspeckit.core.maintenance.GlobalRepartitionDeduplicationPlan
dataclass
¶
GlobalRepartitionDeduplicationPlan(
operation: MaintenanceOperation,
source_snapshot: SourceSnapshot,
selected_backend: str,
guarantee_level: GuaranteeLevel,
partition_scope: PartitionScope,
schema_outcome: SchemaOutcome,
selected_codec: str,
max_rows_per_file: int | None,
target_byte_size: int | None,
validation_level: ValidationLevel,
schema: Schema | None = None,
partition_columns: tuple[str, ...] = (),
dedup_key_columns: tuple[str, ...] | None = None,
dedup_order_by: tuple[str, ...] | None = None,
dedup_groups: tuple[CompactionGroup, ...] = (),
)
fsspeckit.core.maintenance.CoordinatedOptimizationPlan
dataclass
¶
CoordinatedOptimizationPlan(
operation: MaintenanceOperation,
source_snapshot: SourceSnapshot,
selected_backend: str,
guarantee_level: GuaranteeLevel,
partition_scope: PartitionScope,
schema_outcome: SchemaOutcome,
selected_codec: str,
max_rows_per_file: int | None,
target_byte_size: int | None,
validation_level: ValidationLevel,
schema: Schema | None = None,
dedup_key_columns: tuple[str, ...] | None = None,
dedup_order_by: tuple[str, ...] | None = None,
optimization_groups: tuple[CompactionGroup, ...] = (),
)
fsspeckit.core.maintenance.MaintenanceResult
dataclass
¶
MaintenanceResult(
plan: MaintenancePlan,
succeeded: bool,
guarantee_level: GuaranteeLevel,
phase_outcomes: tuple[PhaseOutcome, ...],
validation: ValidationOutcome | None = None,
publication: PublicationOutcome | None = None,
recovery: RecoveryArtifacts | None = None,
actual_metrics: ActualMetrics | None = None,
error: str | None = None,
)
Typed result returned by DatasetMaintenanceCoordinator.execute().
Attributes:
| Name | Type | Description |
|---|---|---|
plan |
MaintenancePlan
|
The plan that was executed. |
succeeded |
bool
|
True when the operation completed successfully end-to-end. |
guarantee_level |
GuaranteeLevel
|
Guarantee level that governed this execution. |
phase_outcomes |
tuple[PhaseOutcome, ...]
|
Ordered per-phase outcomes (stage, write, validate, lock, drift_check, publish, cleanup). |
validation |
ValidationOutcome | None
|
Staged-output validation outcome, populated after the write phase. |
publication |
PublicationOutcome | None
|
Atomic-rename publication outcome. |
recovery |
RecoveryArtifacts | None
|
Recovery artifact details; workspace_path is None after a successful cleanup. |
actual_metrics |
ActualMetrics | None
|
Row/file/byte counts of the published output. Only populated on success. |
error |
str | None
|
Top-level error summary, or None on success. |
fsspeckit.core.maintenance.GuaranteeLevel
¶
Bases: str, Enum
Publication guarantee levels for maintenance plans.
fsspeckit.core.maintenance.ValidationLevel
¶
Bases: str, Enum
Validation levels for maintenance plans.
fsspeckit.core.maintenance.MaintenanceBackend
¶
Bases: str, Enum
Supported maintenance backends.
Functions¶
fsspeckit.core.maintenance.collect_dataset_stats
¶
collect_dataset_stats(
path: str,
filesystem: AbstractFileSystem | None = None,
partition_filter: list[str] | None = None,
) -> dict[str, Any]
Collect file-level statistics for a parquet dataset.
This function walks the given dataset directory on the provided filesystem, discovers parquet files (recursively), and returns basic statistics.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
str
|
Root directory of the parquet dataset. |
required |
filesystem
|
AbstractFileSystem | None
|
Optional fsspec filesystem. If omitted, a local "file" filesystem is used. |
None
|
partition_filter
|
list[str] | None
|
Optional list of partition prefix filters
(e.g. ["date=2025-11-04"]). Only files whose path relative to
|
None
|
Returns:
| Type | Description |
|---|---|
dict[str, Any]
|
Dict with keys: |
dict[str, Any]
|
|
dict[str, Any]
|
|
dict[str, Any]
|
|
Raises:
| Type | Description |
|---|---|
FileNotFoundError
|
If the path does not exist or no parquet files match the optional partition filter. |
Source code in src/fsspeckit/core/maintenance.py
204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 | |