# golosegor/pyspark-nested-fields-functions architecture

> Architecture diagram of the GitHub repository golosegor/pyspark-nested-fields-functions, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-02-09). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/golosegor/pyspark-nested-fields-functions
- Repository: https://github.com/golosegor/pyspark-nested-fields-functions

## Overview

##### Connection and Flow Representation

The flow should generally be:
**Public API → Processors → Function Implementations → Utilities**

##### Special Elements

a) Input/Output Representation:
- PySpark DataFrame input on the left
- Transformed DataFrame output on the right

b) Integration Points:
- Integration with PySpark's native functions
- Where custom transformations are applied
- Use interface symbols to show these connection points

##### Key Design Patterns to Highlight

- Processor Pattern: Show how the different processors handle nested field operations
- Strategy Pattern: Illustrate how different functions implement various transformation strategies
- Chain of Responsibility: Demonstrate how nested field operations are processed through the layers

##### Technical Details to Emphasize

- How the library handles nested JSON structures
- Schema flattening process
- Demonstrate predicate-based operation handling
- Error handling flow

## Diagram (Mermaid)

```mermaid
flowchart TB
    subgraph "Public API Layer"
        API["Main Entry Point"]:::api
        TO["Terminal Operations Interface"]:::api
    end

    subgraph "Processor Layer"
        CP["CoreProcessor"]:::processor
        ALP["AnyLevelProcessor"]:::processor
        AOP["AddOperationProcessor"]:::processor
        TOP["TerminalOperationProcessor"]:::processor
        TOPWP["TerminalOperationProcessorWithPredicate"]:::processor
    end

    subgraph "Function Implementation Layer"
        subgraph "Field Manipulation"
            ANF["Add Nested Field"]:::function
            DROP["Drop"]:::function
            DUP["Duplicate"]:::function
            FR["Field Rename"]:::function
        end

        subgraph "Data Transformation"
            HASH["Hash"]:::function
            DF["Date Format"]:::function
            TRUNC["Truncate"]:::function
        end

        subgraph "String Operations"
            CONCAT["String Concatenation"]:::function
            REGEX["Regex Extract"]:::function
        end

        subgraph "Filtering Operations"
            FILTER["Filter"]:::function
            WL["Whitelist"]:::function
        end

        subgraph "Null Handling"
            FNA["Fill NA"]:::function
            NULL["Nullify"]:::function
        end
    end

    subgraph "Utility Layer"
        SF["Schema Flattener"]:::utility
        SU["Schema Utilities"]:::utility
        IU["Iterator Utils"]:::utility
        VAL["Validators"]:::utility
    end

    %% Connections
    API --> CP
    API --> TO
    TO --> TOP
    TO --> TOPWP

    CP --> ALP
    CP --> AOP
    CP --> TOP
    CP --> TOPWP

    ALP --> ANF
    ALP --> DROP
    ALP --> DUP
    ALP --> FR

    TOP --> HASH
    TOP --> DF
    TOP --> TRUNC
    TOP --> CONCAT
    TOP --> REGEX

    TOPWP --> FILTER
    TOPWP --> WL
    TOPWP --> FNA
    TOPWP --> NULL

    ANF --> SF
    DROP --> SF
    HASH --> IU
    FILTER --> VAL
    WL --> VAL
    SF --> SU

    %% Click Events
    click API "https://github.com/golosegor/pyspark-nested-fields-functions/blob/main/nestedfunctions/__init__.py"
    click TO "https://github.com/golosegor/pyspark-nested-fields-functions/blob/main/nestedfunctions/functions/terminal_operations.p"
    click CP "https://github.com/golosegor/pyspark-nested-fields-functions/blob/main/nestedfunctions/processors/coreprocessor.py"
    click ALP "https://github.com/golosegor/pyspark-nested-fields-functions/blob/main/nestedfunctions/processors/any_level_processor.py"
    click AOP "https://github.com/golosegor/pyspark-nested-fields-functions/blob/main/nestedfunctions/processors/add_operation_processor.py"
    click TOP "https://github.com/golosegor/pyspark-nested-fields-functions/blob/main/nestedfunctions/processors/terminal_operation_processor.py"
    click TOPWP "https://github.com/golosegor/pyspark-nested-fields-functions/blob/main/nestedfunctions/processors/terminal_operation_processor_with_predicate.py"
    click ANF "https://github.com/golosegor/pyspark-nested-fields-functions/blob/main/nestedfunctions/functions/add_nested_field.py"
    click DROP "https://github.com/golosegor/pyspark-nested-fields-functions/blob/main/nestedfunctions/functions/drop.py"
    click DUP "https://github.com/golosegor/pyspark-nested-fields-functions/blob/main/nestedfunctions/functions/duplicate.py"
    click FR "https://github.com/golosegor/pyspark-nested-fields-functions/blob/main/nestedfunctions/functions/field_rename.py"
    click HASH "https://github.com/golosegor/pyspark-nested-fields-functions/blob/main/nestedfunctions/functions/hash.py"
    click DF "https://github.com/golosegor/pyspark-nested-fields-functions/blob/main/nestedfunctions/functions/date_format.py"
    click TRUNC "https://github.com/golosegor/pyspark-nested-fields-functions/blob/main/nestedfunctions/functions/truncate.py"
    click CONCAT "https://github.com/golosegor/pyspark-nested-fields-functions/blob/main/nestedfunctions/functions/str_concat.py"
    click REGEX "https://github.com/golosegor/pyspark-nested-fields-functions/blob/main/nestedfunctions/functions/str_regx_extract.py"
    click FILTER "https://github.com/golosegor/pyspark-nested-fields-functions/blob/main/nestedfunctions/functions/filter.py"
    click WL "https://github.com/golosegor/pyspark-nested-fields-functions/blob/main/nestedfunctions/functions/whitelist.py"
    click FNA "https://github.com/golosegor/pyspark-nested-fields-functions/blob/main/nestedfunctions/functions/fillna.py"
    click NULL "https://github.com/golosegor/pyspark-nested-fields-functions/blob/main/nestedfunctions/functions/nullify.py"
    click SF "https://github.com/golosegor/pyspark-nested-fields-functions/blob/main/nestedfunctions/spark_schema/schema_flattener.py"
    click SU "https://github.com/golosegor/pyspark-nested-fields-functions/blob/main/nestedfunctions/spark_schema/utility.py"
    click IU "https://github.com/golosegor/pyspark-nested-fields-functions/blob/main/nestedfunctions/utils/iterators/iterator_utils.py"
    click VAL "https://github.com/golosegor/pyspark-nested-fields-functions/blob/main/nestedfunctions/validation/validators.py"

    %% Styling
    classDef api fill:#90EE90,stroke:#333,stroke-width:2px
    classDef processor fill:#87CEEB,stroke:#333,stroke-width:2px
    classDef function fill:#FFA500,stroke:#333,stroke-width:2px
    classDef utility fill:#D3D3D3,stroke:#333,stroke-width:2px

    %% Legend
    subgraph Legend
        L1["API Component"]:::api
        L2["Processor Component"]:::processor
        L3["Function Component"]:::function
        L4["Utility Component"]:::utility
    end
```
