HDFS Operations
The HDFS operations module provides utilities for working with Hadoop Distributed File System operations, including file management, configuration, and environment setup.
Module Overview
Abstract HDFS Operations - Fully Configurable and Reusable Zero hard-coded project dependencies
- class siege_utilities.distributed.hdfs_operations.AbstractHDFSOperations[source]
Bases:
objectAbstract HDFS Operations class that can be configured for any project
- create_spark_session()[source]
Create Spark session using configuration.
Supports local, standalone cluster, and YARN deployments based on the master URL in the config.
- sync_directory_to_hdfs(local_path=None, hdfs_subdir='inputs')[source]
Sync local directory/file to HDFS with proper verification.
- Raises:
ValueError – If no data path is provided.
FileNotFoundError – If the local path does not exist.
RuntimeError – If HDFS is not accessible or sync verification fails.
subprocess.CalledProcessError – If an HDFS command fails.
subprocess.TimeoutExpired – If an HDFS command times out.
- Parameters:
- Return type:
- setup_distributed_environment(data_path=None, dependency_paths=None)[source]
Main setup function with proper verification.
- Returns:
Tuple of (spark_session, data_url, None).
- Raises:
ValueError – If no data path is provided.
FileNotFoundError – If the data path does not exist.
ImportError – If PySpark is not available.
RuntimeError – If HDFS sync or Spark session creation fails.
- Parameters:
Functions
- siege_utilities.distributed.hdfs_operations.create_hdfs_operations(config)[source]
Factory function to create HDFS operations instance
Usage Examples
Basic HDFS operations setup:
File operations:
File transfer operations:
Batch operations:
Unit Tests
The HDFS operations module has comprehensive test coverage:
Test Results: All HDFS operations tests pass successfully with comprehensive coverage.