Version v0.4.0 of the documentation is no longer actively maintained. The site that you are currently viewing is an archived snapshot. For up-to-date documentation, see the latest version.

HiveServer2 connection

HiveServer2 connection

Query Apache Hive over HiveServer2 from a task via a managed Leoflow Connection and Airflow’s HiveServer2Hook. The conn_type is hiveserver2. A connection carries the host:port plus credentials and the default database (schema).

Declare the provider

# leoflow.yaml
dag_id: hive_query
connectors:
  - hiveserver2

Fields the UI asks for

FieldWhere it goesNotes
Conn Ide.g. hiveserver2_default.
HosthostThe HiveServer2 host, e.g. hive.example.com.
PortportDefault 10000.
LoginloginThe Hive user.
PasswordpasswordEncrypted at rest (ADR 0019).
SchemaschemaDefault database, e.g. default.

The host:port + user + password round-trip (reserved characters) is pinned by TestHiveServer2ConnectionURIShapeIntegration.

Example DAG (copy-paste)

Docs-only recipe (needs a real Hive cluster). The hook is imported inside the task — a top-level provider import fails the compile (see Installing a connector’s provider).

# dag.py
from __future__ import annotations

from airflow.sdk import DAG, task


@task
def query() -> None:
    from airflow.providers.apache.hive.hooks.hive import HiveServer2Hook

    hook = HiveServer2Hook(hiveserver2_conn_id="hiveserver2_default")
    print("query: connecting via HiveServer2Hook(hiveserver2_default)")
    rows = hook.get_records("SELECT COUNT(*) FROM my_table")
    print(f"query: my_table has {rows[0][0]} rows")


with DAG("hive_query", schedule=None, catchup=False, tags=["example"]):
    query()
# leoflow.yaml
schema_version: "1.0"
dag_id: hive_query
description: Query Hive via HiveServer2Hook.
owner: examples
tags:
  - example
python_version: "3.11"
connectors:
  - hiveserver2

Run it

  1. Admin → Connections → +, type hiveserver2. Set Host, Port, Login, Password, and the default Schema.
  2. leoflow lite path/to/this/dag → trigger hive_query.

Security notes

  • Least privilege: the Hive user should be scoped to the tables it reads.
  • Never print() the URI — it carries the password.
  • docs/connections/index.mdInstalling a connector’s provider.
  • ADR 0019 / 0021 — secret encryption + agent delivery.