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: object

Abstract HDFS Operations class that can be configured for any project

__init__(config)[source]

Initialize with HDFSConfig

check_hdfs_status()[source]

Check if HDFS is accessible

Return type:

bool

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:
Parameters:
  • local_path (str | None)

  • hdfs_subdir (str)

Return type:

Tuple[str, Dict]

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:
Parameters:
  • data_path (str | None)

  • dependency_paths (List[str] | None)

siege_utilities.distributed.hdfs_operations.create_hdfs_operations(config)[source]

Factory function to create HDFS operations instance

siege_utilities.distributed.hdfs_operations.setup_distributed_environment(config, data_path=None, dependency_paths=None)[source]

Convenience function to set up distributed environment

Parameters:
  • data_path (str | None)

  • dependency_paths (List[str] | None)

Functions

siege_utilities.distributed.hdfs_operations.create_hdfs_operations(config)[source]

Factory function to create HDFS operations instance

siege_utilities.distributed.hdfs_operations.setup_distributed_environment(config, data_path=None, dependency_paths=None)[source]

Convenience function to set up distributed environment

Parameters:
  • data_path (str | None)

  • dependency_paths (List[str] | None)

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.