Skip to main content

Hana Injector

MQTT stream to SAP Hana database converter and forwarder API.

The following application was created by a project with the purpose to connect MQTT parts with the SAP HANA DB. The goal was to implement an application that is capable of transforming incoming MQTT topics to a SQL format that is compliant with the Hana DB, as the original data was streamed with MQTT, whereas the HANA database was only able to receive data sent in Hana SQL format.

Basic information about the application and key features

The Hana Injector is based on a Python Flask microservice architecture. Therefore, one of the key features of the application is the low consumption of resources, as the framework allows for the efficient distribution and usage of resources in general.

Furthermore, the architecture includes multiple packages, such as the Python MQTT Paho client and the PyHDB library.

The features of this application are the conversion process in SQL, the element identification and the insertion into the HANA DB.

Architecture and functional principles of the Hana Injector

Architecture

The service based on a microservice architecture and the Python Flask framework. The application include a Prometheus metric endpoint and a code generator to produce the corresponding functions and transformation code to forward/ modify the incoming MQTT stream. After the transformation process, the core functionality of the tool is the injection of the modified and transformed MQTT stream and in the meantime already a Hana database query to the attached and configured SAP Hana database.

Process flow

The transformation process identify the elements and puts these variables in the SQL statement. For this process, the statements were defined before the application starts. As soon as the transforming is done, the string is transformed to the HANA DB SQL format and can then be directly inserted to the HANA database.

Installation, startup and configuration

Installation

PyPi

pip install hana-injector
export HANA_INJECTOR_CONFIG_FILE_PATH=/storage/conf/config.yml
hana-injector

Manual

  1. Please clone the injector code inside your local environment.
  2. Install all dependencies with uv sync (or pip install -e . for classic pip workflows).
  3. Modify the execution rights of the app.py file e.g. on Linux chmod +x app.py

Configuration

Before starting the application, you must ensure that both the MQTT server and the corresponding HANA DB server are running.

In case these preconditions are not set, the application will throw multiple errors and will eventually crash.

You set up all related configuration parameters like the Hana and MQTT credentials and channels inside the configuration YAML file. You can check out the predefined example configuration inside the next paragraph. To specify the used configuration file it's necessary to set up the env variable HANA_INJECTOR_CONFIG_FILE_PATH and to store the path of the configuration file inside the variable e.g. HANA_INJECTOR_CONFIG_FILE_PATH=config/config.yml.

Environment Variables

Variable Required Default Description
HANA_INJECTOR_CONFIG_FILE_PATH ✅ Yes — Absolute or relative path to the YAML configuration file. Example: config/config.yml
HANA_INJECTOR_GENERATOR_MODE ❌ No (unset) Controls whether the code generator runs on startup. See details below.
HANA_INJECTOR_GENERATOR_MODE in detail

The generator creates the converter, MQTT callback and SQL query source files from the generator section of the configuration YAML. Its behaviour depends on how the variable is set:

Value Behaviour
(not set) Generator runs on startup and writes the generated files. After the run the application internally sets the variable to "False".
"True" Generator runs on startup (same as not set).
"False" or any other value Generator is skipped. Use this when generated files already exist, e.g. in production containers where code was pre-generated during the image build.

Configuration Yaml

hana_injector:
  secret_key: "test"
  log_mode: "debug"
  template: "injector/templates"
  host: "localhost"
  port: 8080
  threads: 4

mqtt:
  hostname: "localhost"
  port: 3555
  username: "3555"
  password: "3555"
  subscribed_topics:
    - name: "Test1"
      qos: 0
    - name: "Test2"
      qos: 0

hana_database:
  hostname: "Test"
  port: 123
  username: "test"
  password: "Test"

generator:
  - method_name: "Service1"
    mqtt_topic: "Service11"
    mqtt_payload:
      - OrderID: "str"
      - OrderDate: "generateDatetime"
      - Color: "sep:listDict(Name, Amount)|OrderID, OrderDate"
      - Color2: "sep:listDict(Name, Amount)|OrderID, OrderDate"
      - CustomerName: "str"
    hana_sql_query:
      - "Test1"
    hana_sql_query_sep:
      - "Test1_sep"
      - "Test2_sep"

  - method_name: "Service2"
    mqtt_topic: "Service21"
    mqtt_payload:
      - OrderID: "str"
      - OrderDate: "generateDate"
      - CustomerName: "str"
      - Color: "list"
    hana_sql_query:
      - "Test2"
      - "Test22"

  - method_name: "Service3"
    mqtt_topic: "Service31"
    mqtt_payload:
      - OrderID: "str"
      - DeviceID: "str"
      - OrderDate: "str"
      - StatusCode: "str"
    hana_sql_query:
      - "Test3"

Supported mapping types and function

  • int | Mapping value for a classical integer like 1
  • double | Mapping value for a classical double like 1.1
  • str | Mapping value for a classical string like test
  • list | Mapping value for a classical list of values like ["test", "test1"]
  • listDict | Mapping value for a list of dictionaries like [{"test": "test1"}, {"test1": "test2"}]
  • sep:listDict | Mapping value the functionality to separate values from MQTT stream and accumulate existing values from configuration/ stream and forward both together to the HANA database via a separate methode and query sep:listDict(Name, Amount)|OrderID, OrderDate. For this datatype it's also necessary to specify the hana_sql_query_sep configuration option and forward the queries in the right order to the generator functionality.
  • Dict | Mapping value for a dictionary like {"test": "test1"}
  • generateDate | Mapping value for the functionality to generate a date inside the following format %Y-%m-%d
  • generateDatetime | Mapping value for the functionality to generate a date time inside the following format %Y-%m-%dT%H:%M:%SZ

Api Endpoints

Health

The corresponding app includes a health endpoint to check the status of the application. You can call the /health page to get the corresponding status of the app.

Metrics

The corresponding app includes a Prometheus metric endpoint to get the metrics of the application. You can call the /metrics page to get the corresponding metrics of the app.

Swagger

The corresponding app includes a documentation endpoint to check the documentation pages of the API. You can call the /api/docs page to get the corresponding documentation pages.

Contribution

If you would like to contribute, have an improvement request, or want to make a change inside the code, please open a pull request and write unit tests.

Support

If you need support, or you encounter a bug, please don't hesitate to open an issue.

Donations

If you would like to support my work, I ask you to take an unusual action inside the open source community. Donate the money to a non-profit organization like Doctors Without Borders or the Children's Cancer Aid. I will continue to build tools because I like it and it is my passion to develop and share applications.

License

This product is available under the Apache 2.0.

Metadata

Release files for hana-injector 1.0.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for hana-injector 1.0.2
File Size Uploaded
hana_injector-1.0.2.tar.gz 17.4 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for hana-injector 1.0.2
File Interpreter ABI Platform
hana_injector-1.0.2-py3-none-any.whl Python 3 none any Details

Total release size: 35.1 kB

Release files / hana_injector-1.0.2.tar.gz

Download URL hana_injector-1.0.2.tar.gz
Size 17.4 kB
Tags Source
SHA-256 checksum
How to use checksums
af0738a410d67d9f257fe57ce6491f5dffa6461a52bde5d13a987a6e2a781a5b
BLAKE2b-256 checksum
How to use checksums
f06dc230d8a97f2af5267827a29688e672737fae04ce66b3e8e5e55e0ffa2052
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.9.25

Release files / hana_injector-1.0.2-py3-none-any.whl

Download URL hana_injector-1.0.2-py3-none-any.whl
Size 17.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
c445e6771527f753415c0a21763ae2ad91ec2bb5b995e8473c711e373cbc622b
BLAKE2b-256 checksum
How to use checksums
a264019fea4b09ccf9915cf6a74492d4fc5179af5c0088123e999d9ca84698a1
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.9.25

Release history Release notifications | RSS feed

This release

1.0.2 This release

2 release files

1.0.1

2 release files

1.0.0

2 release files

0.0.1

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page