helios-cloudera 0.3.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,18 @@
1
+ tpcds/
2
+ *.parquet
3
+ __pycache__/
4
+ .env
5
+ .env.sh
6
+ /requirements.lock
7
+ .helios-python/
8
+ state/
9
+ *.db-wal
10
+ *.db-shm
11
+ node_modules/
12
+ *.tsbuildinfo
13
+ .cursor/
14
+ runs/
15
+ run_archive/
16
+ .DS_Store
17
+ *.pptx
18
+ .venv/
@@ -0,0 +1,66 @@
1
+ Metadata-Version: 2.5
2
+ Name: helios-cloudera
3
+ Version: 0.3.0
4
+ Summary: Helios plugins for Cloudera: the Impala engine and the Atlas catalog
5
+ Project-URL: Homepage, https://github.com/christopheraburns/helios
6
+ Project-URL: Documentation, https://github.com/christopheraburns/helios/tree/main/packages/helios-cloudera#readme
7
+ Project-URL: Repository, https://github.com/christopheraburns/helios
8
+ Project-URL: Issues, https://github.com/christopheraburns/helios/issues
9
+ Author: Helios Team
10
+ License-Expression: Apache-2.0
11
+ Keywords: atlas,cloudera,impala,semantic layer
12
+ Classifier: Development Status :: 3 - Alpha
13
+ Classifier: Intended Audience :: Developers
14
+ Classifier: Operating System :: OS Independent
15
+ Classifier: Programming Language :: Python :: 3
16
+ Classifier: Programming Language :: Python :: 3 :: Only
17
+ Classifier: Programming Language :: Python :: 3.11
18
+ Classifier: Programming Language :: Python :: 3.12
19
+ Classifier: Programming Language :: Python :: 3.13
20
+ Classifier: Topic :: Database
21
+ Classifier: Typing :: Typed
22
+ Requires-Python: >=3.11
23
+ Requires-Dist: helios-cortex>=0.3.0
24
+ Requires-Dist: impyla>=0.20.0
25
+ Requires-Dist: pydantic-settings>=2.6
26
+ Requires-Dist: requests>=2.32.0
27
+ Description-Content-Type: text/markdown
28
+
29
+ # helios-cloudera
30
+
31
+ Helios plugins for Cloudera Data Platform. Install it next to helios-cortex and
32
+ name the plugins in your settings:
33
+
34
+ ```toml
35
+ [connections.default]
36
+ engine = "impala"
37
+ host = "jdbc:impala://<vw-host>:443/default;transportMode=http;httpPath=cliservice"
38
+ identity = "impersonate" # or "service", "token"
39
+ user = "<workload user>"
40
+ password = "<workload password>"
41
+
42
+ [catalogs.default]
43
+ catalog = "atlas"
44
+ base_url = "https://<datalake-host>/<datalake>/cdp-proxy-api/atlas/api/atlas/v2"
45
+ user = "<workload user>"
46
+ password = "<workload password>"
47
+ ```
48
+
49
+ | Module | What it provides |
50
+ |---|---|
51
+ | `helios_cloudera.impala` | `ImpalaEngine` (the `impala` engine plugin), `ImpalaOptions`, `impala_config` |
52
+ | `helios_cloudera.atlas` | `AtlasClient` (the `atlas` catalog plugin), `AtlasOptions`, `atlas_config` |
53
+ | `helios_cloudera.index` | `impala_index_store`; `helios --profile workbench impala init-index` (or `python -m helios_cloudera.index init-tables`) |
54
+ | `helios_cloudera.workbench` | `WorkbenchSettings`: Settings that also read the Workbench variables (`CDSW_*`, `IMPALA_*`, `WORKLOAD_*`, `ATLAS_*`, `INFERENCE_*`) |
55
+ | `helios_cloudera.impala_diagnose` | `helios --profile workbench impala diagnose [--delegated-user USER]` (or `python -m helios_cloudera.impala_diagnose`): checks workload and proxy authentication |
56
+ | `helios_cloudera.commands` | the `helios impala` command; and `--profile workbench` (`WorkbenchSettings`, registered under `helios.profiles`) |
57
+
58
+ On Cloudera AI Workbench, build `WorkbenchSettings()` instead of `Settings()`. It reads the
59
+ variables Workbench projects already set: `IMPALA_HOST` with `WORKLOAD_USER` and
60
+ `WORKLOAD_PASSWORD` become the `default` connection, `ATLAS_BASE` / `ATLAS_USER` / `ATLAS_PASS`
61
+ the `default` catalog, `INFERENCE_*` a Cloudera AI Inference LLM, and `CDSW_PROJECT_DIR` the
62
+ data directory. `HELIOS_*` variables and the config file still apply.
63
+
64
+ The Impala engine supports all three identity modes: `service` (LDAP as the
65
+ workload user), `impersonate` (adds `doAs` and checks `EFFECTIVE_USER()`) and
66
+ `token` (the caller's JWT, no workload user).
@@ -0,0 +1,38 @@
1
+ # helios-cloudera
2
+
3
+ Helios plugins for Cloudera Data Platform. Install it next to helios-cortex and
4
+ name the plugins in your settings:
5
+
6
+ ```toml
7
+ [connections.default]
8
+ engine = "impala"
9
+ host = "jdbc:impala://<vw-host>:443/default;transportMode=http;httpPath=cliservice"
10
+ identity = "impersonate" # or "service", "token"
11
+ user = "<workload user>"
12
+ password = "<workload password>"
13
+
14
+ [catalogs.default]
15
+ catalog = "atlas"
16
+ base_url = "https://<datalake-host>/<datalake>/cdp-proxy-api/atlas/api/atlas/v2"
17
+ user = "<workload user>"
18
+ password = "<workload password>"
19
+ ```
20
+
21
+ | Module | What it provides |
22
+ |---|---|
23
+ | `helios_cloudera.impala` | `ImpalaEngine` (the `impala` engine plugin), `ImpalaOptions`, `impala_config` |
24
+ | `helios_cloudera.atlas` | `AtlasClient` (the `atlas` catalog plugin), `AtlasOptions`, `atlas_config` |
25
+ | `helios_cloudera.index` | `impala_index_store`; `helios --profile workbench impala init-index` (or `python -m helios_cloudera.index init-tables`) |
26
+ | `helios_cloudera.workbench` | `WorkbenchSettings`: Settings that also read the Workbench variables (`CDSW_*`, `IMPALA_*`, `WORKLOAD_*`, `ATLAS_*`, `INFERENCE_*`) |
27
+ | `helios_cloudera.impala_diagnose` | `helios --profile workbench impala diagnose [--delegated-user USER]` (or `python -m helios_cloudera.impala_diagnose`): checks workload and proxy authentication |
28
+ | `helios_cloudera.commands` | the `helios impala` command; and `--profile workbench` (`WorkbenchSettings`, registered under `helios.profiles`) |
29
+
30
+ On Cloudera AI Workbench, build `WorkbenchSettings()` instead of `Settings()`. It reads the
31
+ variables Workbench projects already set: `IMPALA_HOST` with `WORKLOAD_USER` and
32
+ `WORKLOAD_PASSWORD` become the `default` connection, `ATLAS_BASE` / `ATLAS_USER` / `ATLAS_PASS`
33
+ the `default` catalog, `INFERENCE_*` a Cloudera AI Inference LLM, and `CDSW_PROJECT_DIR` the
34
+ data directory. `HELIOS_*` variables and the config file still apply.
35
+
36
+ The Impala engine supports all three identity modes: `service` (LDAP as the
37
+ workload user), `impersonate` (adds `doAs` and checks `EFFECTIVE_USER()`) and
38
+ `token` (the caller's JWT, no workload user).
@@ -0,0 +1,53 @@
1
+ [build-system]
2
+ requires = ["hatchling"]
3
+ build-backend = "hatchling.build"
4
+
5
+ [project]
6
+ name = "helios-cloudera"
7
+ version = "0.3.0"
8
+ description = "Helios plugins for Cloudera: the Impala engine and the Atlas catalog"
9
+ readme = "README.md"
10
+ authors = [{name = "Helios Team"}]
11
+ license = "Apache-2.0"
12
+ requires-python = ">=3.11"
13
+ keywords = ["cloudera", "impala", "atlas", "semantic layer"]
14
+ classifiers = [
15
+ "Development Status :: 3 - Alpha",
16
+ "Intended Audience :: Developers",
17
+ "Operating System :: OS Independent",
18
+ "Programming Language :: Python :: 3",
19
+ "Programming Language :: Python :: 3 :: Only",
20
+ "Programming Language :: Python :: 3.11",
21
+ "Programming Language :: Python :: 3.12",
22
+ "Programming Language :: Python :: 3.13",
23
+ "Topic :: Database",
24
+ "Typing :: Typed",
25
+ ]
26
+ dependencies = [
27
+ "helios-cortex>=0.3.0",
28
+ "impyla>=0.20.0",
29
+ "pydantic-settings>=2.6",
30
+ "requests>=2.32.0",
31
+ ]
32
+
33
+ [project.urls]
34
+ Homepage = "https://github.com/christopheraburns/helios"
35
+ Documentation = "https://github.com/christopheraburns/helios/tree/main/packages/helios-cloudera#readme"
36
+ Repository = "https://github.com/christopheraburns/helios"
37
+ Issues = "https://github.com/christopheraburns/helios/issues"
38
+
39
+ [project.entry-points."helios.engines"]
40
+ impala = "helios_cloudera.impala:ImpalaEngine"
41
+
42
+ [project.entry-points."helios.catalogs"]
43
+ atlas = "helios_cloudera.atlas:AtlasClient"
44
+
45
+ [project.entry-points."helios.commands"]
46
+ impala = "helios_cloudera.commands:ImpalaCommand"
47
+
48
+ # helios --profile workbench: the Workbench environment variables, read into Settings.
49
+ [project.entry-points."helios.profiles"]
50
+ workbench = "helios_cloudera.workbench:WorkbenchSettings"
51
+
52
+ [tool.hatch.build.targets.wheel]
53
+ packages = ["src/helios_cloudera"]
@@ -0,0 +1,18 @@
1
+ """Helios plugins for Cloudera: the Impala engine and the Atlas catalog.
2
+
3
+ Installing this package registers ``engine = "impala"`` (helios_cloudera.impala)
4
+ and ``catalog = "atlas"`` (helios_cloudera.atlas) with helios-cortex's plugin loader.
5
+ """
6
+
7
+
8
+ def __getattr__(name: str) -> str:
9
+ # __version__ is read from the installed metadata on first use, so importing
10
+ # helios_cloudera opens no files.
11
+ if name == "__version__":
12
+ from importlib.metadata import PackageNotFoundError, version
13
+
14
+ try:
15
+ return version("helios-cloudera")
16
+ except PackageNotFoundError: # running from a source path without an install
17
+ return "0.0.0+unknown"
18
+ raise AttributeError(f"module {__name__!r} has no attribute {name!r}")
@@ -0,0 +1,214 @@
1
+ """
2
+ Thin client for the Apache Atlas v2 REST API, scoped to what helios needs:
3
+ glossary CRUD, term CRUD, term <-> entity assignment, entity lookup and lineage.
4
+ """
5
+ from __future__ import annotations
6
+
7
+ import os
8
+ from dataclasses import dataclass
9
+ from io import BytesIO
10
+ from typing import Any
11
+
12
+ import requests
13
+ from pydantic import BaseModel, ConfigDict, SecretStr
14
+
15
+ from helios_cortex.catalog import CatalogError, ColumnLineage
16
+ from helios_cortex.settings import CatalogSettings, Settings
17
+
18
+ COLUMN_TYPES = ("hive_column", "iceberg_column")
19
+
20
+
21
+ @dataclass(frozen=True)
22
+ class AtlasConfig:
23
+ base_url: str # e.g. https://<datalake-host>/<datalake-name>/cdp-proxy-api/atlas/api/atlas/v2
24
+ user: str
25
+ password: str
26
+ verify_ssl: bool = True
27
+
28
+
29
+ class AtlasOptions(BaseModel):
30
+ """Options of a ``catalog = "atlas"`` catalog."""
31
+
32
+ model_config = ConfigDict(extra="forbid")
33
+
34
+ base_url: str # e.g. https://<datalake-host>/<datalake-name>/cdp-proxy-api/atlas/api/atlas/v2
35
+ user: str
36
+ password: SecretStr
37
+ verify_ssl: bool = True
38
+
39
+
40
+ def atlas_config_for(catalog: CatalogSettings) -> AtlasConfig:
41
+ if catalog.catalog != "atlas":
42
+ raise ValueError(f"not an Atlas catalog: catalog is {catalog.catalog!r}")
43
+ options = AtlasOptions.model_validate(catalog.options)
44
+ return AtlasConfig(
45
+ options.base_url.rstrip("/"), options.user, options.password.get_secret_value(), options.verify_ssl
46
+ )
47
+
48
+
49
+ def atlas_config(settings: Settings, name: str | None = None) -> AtlasConfig | None:
50
+ """The Atlas catalog ``name`` (else ``default``), or None when there is none."""
51
+ catalog = settings.catalog(name)
52
+ if catalog is None or catalog.catalog != "atlas":
53
+ return None
54
+ return atlas_config_for(catalog)
55
+
56
+
57
+ class AtlasError(CatalogError):
58
+ def __init__(self, status: int, message: str):
59
+ super().__init__(f"Atlas {status}: {message}")
60
+ self.status = status
61
+
62
+
63
+ class AtlasClient:
64
+ """The ``atlas`` catalog plugin: a glossary and column lineage (both catalog capabilities)."""
65
+
66
+ def __init__(self, cfg: AtlasConfig):
67
+ self.base = cfg.base_url
68
+ self.s = requests.Session()
69
+ self.s.auth = (cfg.user, cfg.password)
70
+ self.s.verify = cfg.verify_ssl
71
+ self.s.headers.update({"X-XSRF-HEADER": "valid", "Accept": "application/json"})
72
+
73
+ # ---------------------------------------------------------------- plumbing
74
+ def _req(self, method: str, path: str, **kw) -> Any:
75
+ try:
76
+ r = self.s.request(method, f"{self.base}{path}", timeout=60, **kw)
77
+ except requests.RequestException as exc:
78
+ raise AtlasError(0, "Atlas service is unavailable") from exc
79
+ if r.status_code >= 400:
80
+ try:
81
+ msg = r.json().get("errorMessage", r.text)
82
+ except ValueError:
83
+ msg = r.text
84
+ raise AtlasError(r.status_code, msg[:500])
85
+ if r.status_code == 204 or not r.content:
86
+ return None
87
+ return r.json()
88
+
89
+ def ping(self) -> bool:
90
+ self._req("GET", "/types/typedefs/headers")
91
+ return True
92
+
93
+ # ---------------------------------------------------------------- glossaries
94
+ def list_glossaries(self) -> list[dict]:
95
+ return self._req("GET", "/glossary", params={"limit": 100}) or []
96
+
97
+ def get_glossary(self, guid: str) -> dict:
98
+ return self._req("GET", f"/glossary/{guid}")
99
+
100
+ def create_glossary(self, name: str, short_description: str = "") -> dict:
101
+ return self._req("POST", "/glossary", json={"name": name, "shortDescription": short_description})
102
+
103
+ def delete_glossary(self, guid: str) -> None:
104
+ self._req("DELETE", f"/glossary/{guid}")
105
+
106
+ # ---------------------------------------------------------------- terms
107
+ def list_terms(
108
+ self,
109
+ glossary_guid: str,
110
+ limit: int = 1000,
111
+ offset: int = 0,
112
+ ) -> list[dict]:
113
+ return self._req(
114
+ "GET",
115
+ f"/glossary/{glossary_guid}/terms",
116
+ params={"limit": limit, "offset": offset},
117
+ ) or []
118
+
119
+ def get_term(self, term_guid: str) -> dict:
120
+ return self._req("GET", f"/glossary/term/{term_guid}")
121
+
122
+ def create_term(self, glossary_guid: str, name: str, short_description: str = "",
123
+ long_description: str = "", abbreviation: str = "", examples: list[str] | None = None) -> dict:
124
+ body = {"name": name, "shortDescription": short_description, "longDescription": long_description,
125
+ "abbreviation": abbreviation, "examples": examples or [], "anchor": {"glossaryGuid": glossary_guid}}
126
+ return self._req("POST", "/glossary/term", json=body)
127
+
128
+ def update_term(self, term_guid: str, **fields) -> dict:
129
+ """Atlas PUT replaces the term, so fetch, merge the editable fields, and send back."""
130
+ term = self.get_term(term_guid)
131
+ for k in ("name", "shortDescription", "longDescription", "abbreviation", "examples"):
132
+ if k in fields and fields[k] is not None:
133
+ term[k] = fields[k]
134
+ return self._req("PUT", f"/glossary/term/{term_guid}", json=term)
135
+
136
+ def delete_term(self, term_guid: str) -> None:
137
+ self._req("DELETE", f"/glossary/term/{term_guid}")
138
+
139
+ def import_csv(self, path: str) -> dict:
140
+ with open(path, "rb") as f:
141
+ return self.import_csv_bytes(os.path.basename(path), f.read())
142
+
143
+ def import_csv_bytes(self, filename: str, content: bytes) -> dict:
144
+ return self._req(
145
+ "POST",
146
+ "/glossary/import",
147
+ files={
148
+ "file": (
149
+ os.path.basename(filename) or "glossary.csv",
150
+ BytesIO(content),
151
+ "text/csv",
152
+ )
153
+ },
154
+ )
155
+
156
+ # ---------------------------------------------------------------- assignments
157
+ def assigned_entities(self, term_guid: str) -> list[dict]:
158
+ return self._req("GET", f"/glossary/terms/{term_guid}/assignedEntities") or []
159
+
160
+ def assign(self, term_guid: str, entities: list[tuple[str, str]]) -> None:
161
+ """entities: list of (guid, typeName)."""
162
+ if entities:
163
+ self._req("POST", f"/glossary/terms/{term_guid}/assignedEntities",
164
+ json=[{"guid": g, "typeName": t} for g, t in entities])
165
+
166
+ def unassign(self, term_guid: str, entity_guid: str) -> None:
167
+ """Atlas needs the relationship guid to disassociate; look it up from the term's assignments."""
168
+ for e in self.assigned_entities(term_guid):
169
+ if e.get("guid") == entity_guid:
170
+ self._req("PUT", f"/glossary/terms/{term_guid}/assignedEntities",
171
+ json=[{"guid": entity_guid, "relationshipGuid": e.get("relationshipGuid")}])
172
+ return
173
+ raise AtlasError(404, f"entity {entity_guid} is not assigned to term {term_guid}")
174
+
175
+ # ---------------------------------------------------------------- entities
176
+ def dsl(self, query: str, limit: int = 25) -> list[dict]:
177
+ return (self._req("GET", "/search/dsl", params={"query": query, "limit": limit}) or {}).get("entities") or []
178
+
179
+ def find_column(self, db: str, table: str, column: str) -> tuple[str, str] | None:
180
+ """Return (guid, typeName) of the ACTIVE column entity for db.table.column, checking each known column type."""
181
+ for typ in COLUMN_TYPES:
182
+ try:
183
+ ents = self.dsl(f'{typ} where qualifiedName like "{db}.{table}.{column}@*"', limit=5)
184
+ except AtlasError as e:
185
+ if e.status == 400: # type does not exist on this Atlas
186
+ continue
187
+ raise
188
+ ents = [x for x in ents if x.get("status", "ACTIVE") == "ACTIVE"]
189
+ if ents:
190
+ return ents[0]["guid"], typ
191
+ return None
192
+
193
+ def entity(self, guid: str) -> dict:
194
+ return self._req("GET", f"/entity/guid/{guid}").get("entity", {})
195
+
196
+ def lineage(self, guid: str, depth: int = 3) -> dict:
197
+ return self._req("GET", f"/lineage/{guid}", params={"depth": depth, "direction": "BOTH"})
198
+
199
+ # ------------------------------------------------------------ catalog plugin
200
+ @classmethod
201
+ def from_catalog(cls, catalog: CatalogSettings) -> AtlasClient:
202
+ return cls(atlas_config_for(catalog))
203
+
204
+ def column_lineage(self, database: str, table: str, column: str, depth: int = 3) -> ColumnLineage | None:
205
+ hit = self.find_column(database, table, column)
206
+ if not hit:
207
+ return None
208
+ graph = self.lineage(hit[0], depth)
209
+ return ColumnLineage(
210
+ column=f"{database}.{table}.{column}",
211
+ entities={guid: {"type": e.get("typeName"), "name": e.get("displayText")}
212
+ for guid, e in (graph.get("guidEntityMap") or {}).items()},
213
+ edges=[(r["fromEntityId"], r["toEntityId"]) for r in graph.get("relations") or []],
214
+ )
@@ -0,0 +1,42 @@
1
+ """helios-cloudera's subcommand of ``helios``: ``impala``.
2
+
3
+ helios --profile workbench impala diagnose [--delegated-user USER]
4
+ helios --profile workbench impala init-index
5
+
6
+ ``--profile workbench`` reads the Workbench variables (IMPALA_HOST, WORKLOAD_USER, ...);
7
+ without it the ``default`` connection comes from helios.toml or HELIOS_* variables.
8
+ """
9
+ from __future__ import annotations
10
+
11
+ import argparse
12
+
13
+ from helios_cortex.cli import CommandContext, CommandError
14
+
15
+
16
+ class ImpalaCommand:
17
+ help = "Impala on Cloudera: check the credentials, or create the helios_index tables"
18
+
19
+ def configure(self, parser: argparse.ArgumentParser) -> None:
20
+ actions = parser.add_subparsers(dest="action", metavar="ACTION", required=True)
21
+ diagnose = actions.add_parser("diagnose", help="test the workload credential, then an optional doAs user; "
22
+ "prints no credential or SQL")
23
+ diagnose.add_argument("--delegated-user", metavar="USER",
24
+ help="an authenticated Cloudera SSO subject to verify through doAs")
25
+ actions.add_parser("init-index", help="create the helios_index tables through Impala")
26
+
27
+ def run(self, args: argparse.Namespace, context: CommandContext) -> int:
28
+ if args.action == "diagnose":
29
+ from helios_cloudera.impala_diagnose import DiagnosisFailed, diagnose
30
+
31
+ try:
32
+ diagnose(context.settings, args.delegated_user, context.echo)
33
+ except DiagnosisFailed as exc:
34
+ raise CommandError(str(exc)) from exc
35
+ return 0
36
+ from helios_cloudera.index import init_tables
37
+
38
+ if not init_tables(context.settings):
39
+ raise CommandError("Impala is not configured: no impala [connections.default] "
40
+ "(on Workbench, pass --profile workbench)")
41
+ context.echo("helios_index tables are in place.")
42
+ return 0