# lserinol/hive-udfs architecture

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

- Interactive diagram: https://gitdiagram.com/lserinol/hive-udfs
- Repository: https://github.com/lserinol/hive-udfs

## Overview

##### Project Type and Purpose
- This project is essentially a library of Hive UDFs implemented in Scala, built with SBT.
- Its primary role is to be compiled and deployed as a JAR that gets added to Hive (via HIVE_AUX_JARS_FILE_PATH or "add jar" commands). Once the JAR is available in the Hive context, the UDFs can be registered and utilized in Hive queries.

##### Analyzing the File Structure
- Top-level files: LICENSE, README.md, and build.sbt confirm that this is a source-based Scala project.
- The "project" directory contains SBT configuration files (build.properties, plugins.sbt) that support building the project.
- The "src/main/scala" folder contains the package hierarchy "com/levent/hive/udfs", where each individual UDF (lcrc32, ldays_between, lmonths_between, liLIKE, lurldecode, and lurlencode) is implemented in its own Scala file.
- There isn’t a front-end, backend separation since this is not a full-stack application but a Scala library for Hive extensions.

##### Key Components
a. Build and Deployment:
- SBT Build Process: Illustrate the SBT build tool and the assembly process. This is where the source code is compiled and packaged into an assembly JAR.
- Assembly JAR: Represent the resulting JAR artifact that contains all UDF classes.

b. UDF Package and Functions:
- For each UDF, list them as sub-components:
- lcrc32 – computes a crc32 checksum.
- ldays_between – calculates the difference in days between two dates.
- lmonths_between – computes the difference in months between two dates.
- liLIKE – performs a case-insensitive LIKE operation.
- lurlDecode – decodes URL-encoded strings.
- lurlEncode – encodes strings to URL format.

c. Hive Interaction:
- Hive Environment: Use a component marker for Hive, where the JAR is added.
- UDF Registration: Show the process where Hive loads the JAR and registers the UDFs via commands such as “create temporary function ...”.

##### Relationships and Interactions
- Within the Hive Environment, illustrate the registration process where each UDF is mapped to its corresponding function in the JAR.

##### Architectural Patterns and Design Principles
- Modular Design: The project is structured in a modular package under "com.levent.hive.udfs" which allows easy addition or modification of function implementations.
- Loose Coupling via UDF Registration: The UDFs are kept independent from Hive’s internal architecture; instead, they are plugged in by registration commands.
- Separation of Concerns: The build process (configuration in SBT and project settings) is clearly separated from the source code hosting the logic for UDFs.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Source Code Subgraph
    subgraph "Project Source Code"
        UDFPack["UDF Package (com.levent.hive.udfs)"]:::package
        UDFPack --> UDF1["lcrc32 (computes crc32 checksum)"]:::udf
        UDFPack --> UDF2["ldays_between (calculates day difference)"]:::udf
        UDFPack --> UDF3["lmonths_between (computes month difference)"]:::udf
        UDFPack --> UDF4["liLIKE (case-insensitive string matching)"]:::udf
        UDFPack --> UDF5["lurlDecode (decodes URL-encoded strings)"]:::udf
        UDFPack --> UDF6["lurlEncode (encodes strings to URL format)"]:::udf
    end

    %% SBT Build Tools Subgraph
    subgraph "SBT Build Tools"
        BSBT["build.sbt"]:::build
        PROJ["SBT Project Config (project/)"]:::build
    end

    %% Build Process and Deployment
    BuildProc["SBT Build Process"]:::build
    Jar["Assembly JAR Artifact"]:::artifact
    HiveEnv["Hive Environment (UDF Registration)"]:::hive

    %% Connections from Source and Build Tools to Build Process
    UDFPack -->|"compiled_by"| BuildProc
    BSBT -->|"used_by"| BuildProc
    PROJ -->|"used_by"| BuildProc

    %% Build Process to Assembly JAR and Deployment to Hive
    BuildProc -->|"produces"| Jar
    Jar -->|"deployed_to"| HiveEnv
    HiveEnv -->|"registers"| UDFPack

    %% Click Events for Component Mappings
    click BSBT "https://github.com/lserinol/hive-udfs/blob/master/build.sbt"
    click PROJ "https://github.com/lserinol/hive-udfs/tree/master/project/"
    click UDFPack "https://github.com/lserinol/hive-udfs/tree/master/src/main/scala/com/levent/hive/udfs"
    click UDF1 "https://github.com/lserinol/hive-udfs/blob/master/src/main/scala/com/levent/hive/udfs/lcrc32.scala"
    click UDF2 "https://github.com/lserinol/hive-udfs/blob/master/src/main/scala/com/levent/hive/udfs/ldays_between.scala"
    click UDF3 "https://github.com/lserinol/hive-udfs/blob/master/src/main/scala/com/levent/hive/udfs/lmonths_between.scala"
    click UDF4 "https://github.com/lserinol/hive-udfs/blob/master/src/main/scala/com/levent/hive/udfs/liLIKE.scala"
    click UDF5 "https://github.com/lserinol/hive-udfs/blob/master/src/main/scala/com/levent/hive/udfs/lurldecode.scala"
    click UDF6 "https://github.com/lserinol/hive-udfs/blob/master/src/main/scala/com/levent/hive/udfs/lurlencode.scala"

    %% Styles
    classDef package fill:#b2f7b2,stroke:#388e3c,stroke-width:2px;
    classDef udf fill:#fff9c4,stroke:#f9a825,stroke-width:2px;
    classDef build fill:#bbdefb,stroke:#0d47a1,stroke-width:2px;
    classDef artifact fill:#ffc1e3,stroke:#d81b60,stroke-width:2px;
    classDef hive fill:#ffe082,stroke:#ffa000,stroke-width:2px;
```
