Repository navigation
Polaris backend for %catalog, %gpkg, %dds and %ingest - #116
Merged
Merged
Conversation
Updates the requirements on [duckdb](https://github.com/duckdb/duckdb-python) to permit the latest version. - [Release notes](https://github.com/duckdb/duckdb-python/releases) - [Commits](duckdb/duckdb-python@v1.3.0...v2.0.0) --- updated-dependencies: - dependency-name: duckdb dependency-version: 2.0.0 dependency-type: direct:production ... Signed-off-by: dependabot[bot] <support@github.com>
…d-lt-3 build(deps): Update duckdb requirement from <2,>=1.1 to >=1.1,<3
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
First step of the Polaris migration: no behaviour change on Dremio.
- catalog/backend.py: CatalogBackend, the operations CatalogSession needs
(exists, is_folder, list_datasets/list_dataset_kinds, entry_kind/
entry_exists, drop_entry, ensure_folder_path, require_table_or_view,
publish_target/check_publish/publish_dataflow, plus the existing verbs)
and the catalog root that starts every absolute path.
- Catalog (Dremio) implements it with thin public methods over what the
session used to reach into _catalog_rest/_executor/_flight_executor for.
- The Dremio publish machinery (PUBLIC_ROOT, plan, backup/rollback) moves
unchanged to catalog/dremio_publish.py; the shared folder layout
(draft, versions, reference, #public) to catalog/layout.py. Both are
still importable from catalog.session.
- CatalogSession talks only to CatalogBackend and takes its root from
the backend ("catalog" on Dremio) instead of a hard-coded constant.
- catalog/settings.py: EEA_CATALOG_BACKEND=polaris|dremio (unset: polaris
when POLARIS_URI is set, else dremio), DremioSettings, and
PolarisSettings reading the JupyterLab kernel's variable names with the
local-stack/.env names as fallbacks.
- %catalog builds its session from the settings; the Polaris backend
itself comes in the next step and reports so for now.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… backend
Second step of the Polaris migration.
- catalog/polaris_rest.py: PolarisRestClient over the Iceberg REST catalog
(/v1/{prefix}, prefix from /v1/config) and Polaris generic tables
(/polaris/v1): namespaces (list with paging, HEAD exists, properties,
create - 409 is "already there" -, drop), tables and views (list,
exists, load, drop with purge, view registration with SQL and schema,
property commits) and read-only Parquet tables. Authenticates as the
signed-in user (KEYCLOAK_ACCESS_TOKEN, read per request) or with Polaris
client credentials (scope PRINCIPAL_ROLE:ALL, minted once, re-minted on
401). 401/403 -> CatalogAuthError, 404 -> PolarisNotFoundError, other
failures -> PolarisHttpError with the status and Polaris' message.
- catalog/duckdb_engine.py: DuckDbEngine, one lazy DuckDB connection with
iceberg + httpfs (spatial when available), the S3 and Polaris secrets
and the catalog ATTACHed under its own name, as datalakehouse.duckdb()
does; vended credentials when POLARIS_VENDED_CREDENTIALS is on.
table_ref() writes catalog."ns.parts"."name". Works with DuckDB 1 and 2.
- catalog/polaris.py: PolarisCatalog, the CatalogBackend for Polaris.
Root = the catalog name (eea_lakehouse); folders are namespaces, tables
Iceberg tables or read-only Parquet tables, views Iceberg views.
exists/is_folder/entry_kind/entry_exists/require_table_or_view and the
recursive listing work; the other verbs say they are not on Polaris yet.
- %catalog builds a PolarisCatalog session when the backend is polaris,
so use(), list() and relative paths work against Polaris.
- CatalogBackend.root is a read-only property.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Third step of the Polaris migration: the metadata verbs of %catalog on Polaris. - schema: an Iceberg table's column types and row count come from its metadata (the current snapshot's total-records; COUNT(*) in DuckDB when it has delete files). A view's row count runs its own stored SQL (DuckDB can't read Iceberg views); a read-only Parquet table is read with read_parquet over its location. - create_folder / ensure_folder_path create namespaces, checking each level before creating it; delete_folder drops an empty namespace, or with cascade=True every view, table (purged), Parquet registration and sub-namespace inside, deepest first. - wiki: the "wiki" property of the namespace, table, view or Parquet table (re-registered, since generic tables can't be updated in place). Folder Meta Data tags are rendered into the text as on Dremio. - tags: kept as the Polaris Navigator does - property "tags" of a namespace, "tags:<name>" on the parent namespace for a table or view - lower case without "#"; "#public" and "public" are the same tag. Folders can be tagged too. - source_sql()/view_sql(): what to SELECT FROM for a table, view or Parquet table, for the data verbs that come next. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Fourth step of the Polaris migration (publish follows separately). - data_copy: CREATE TABLE ... AS SELECT in DuckDB into an Iceberg table, with every column cast to a type Iceberg holds (nanosecond timestamps to microseconds, unsigned/small integers widened, geometry to WKB, enums and intervals to text). Reads a view through its own SQL and a read-only Parquet table through read_parquet. Same rules as on Dremio: an existing folder target gets the source's name, overwrite drops whatever is there (by its kind), create_target_folder makes the namespaces. - data_move: the copy, a check that it is there, then the source dropped. - create_view: an Iceberg view registered over REST with its DuckDB SQL and schema - plus the same SQL for Trino when the source is a table - and the source path in the view's "eea.source" property. - delete_table / delete_view check the kind; a missing one is a no-op. - create_version / draft_to_version: Dremio's planning rules (reference and vocabulary folders and views skipped, overwrite, cleanup of what a failed run created) on top of the Polaris copy. - update_latest_release works on Polaris: the session matches #public with or without "#" and in any case (Dremio keeps "#public", Polaris "public"). - PolarisRestClient.create_view takes SQL for more engines. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Completes step 4 of the Polaris migration: every %catalog verb now runs on Polaris. - publish on Polaris: each #public view of the dataflow (outside draft, versions and reference) is written by DuckDB to one Parquet file and pushed with DDS POST /api/v1/public/files/<namespace...>/<view> (X-Keycloak-Token; DDS lets in its publishers' group only). That is the folder DDS gives a table of the same name, so the public path stays stable across releases, as on Dremio; the earlier data.parquet is replaced. - Unlike Dremio it is not all-or-nothing: a failure stops the run and names the views already published, and a publish can't be undone. partition_by and overwrite=False are refused with the reason. - catalog/dds_public.py: PublicDataClient (config, push_files). - PolarisSettings.dds_base_url reads DDS_BASE_URL. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Fifth step of the Polaris migration. - geopackage/flight_source.py: FlightSource, a DatasetSource over Polaris and the EEA Lakehouse Arrow Flight gateway (plain Arrow Flight: the ticket is the SQL; "authorization: Bearer <KEYCLOAK_ACCESS_TOKEN>" on every call, no shared fallback identity). The listing and column types come from PolarisCatalog; the SELECT is the catalog's own source_sql, so views are read through their stored SQL and read-only Parquet tables through read_parquet. One Flight client per stream; results are fetched from the gateway address the client connected to (FLIGHT_HOST / FLIGHT_HOST_PORT), not the Docker-internal location it advertises. Refused tokens, an unreachable gateway and query errors become catalog errors with the gateway's own message. - geopackage/controller.py: open_source() picks FlightSource on Polaris and DremioSource on Dremio; a source may build its own SELECT (select_sql); Iceberg and DuckDB type names map to GeoPackage types for empty tables. - GpkgSession reads through open_source, so %gpkg follows the %catalog backend. - PolarisCatalog.settings is public. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Sixth step of the Polaris migration, first half. - DocumentsClient signs in with either the Dremio PAT (Authorization: Bearer, as before) or, on the Polaris stack, the user's Keycloak token (X-Keycloak-Token and no Authorization header: DDS then checks the Access service's grants for that user). - DdsSession uses the Keycloak token when the catalog backend is polaris (KEYCLOAK_ACCESS_TOKEN required) and stores under the namespace's own path, without the catalog name: eea_lakehouse.water.bwd -> water/bwd, as DDS maps a Keycloak caller's path onto Polaris namespaces. - settings.polaris_catalog_name(). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Sixth step of the Polaris migration, second half.
- dds_ingestion/polaris_ingest.py: PolarisIngest, one folder -> one table,
as the signed-in user, without the Document Service. table_format picks
the table, as the Polaris Navigator does:
* "iceberg" (default): files are uploaded to the staging prefix
(s3://<bucket>/<POLARIS_INGEST_S3_PREFIX>/<user>/<run>/<table>/), then
DuckDB loads them (Parquet, CSV or JSON, csv_options/json_options
passed to read_csv/read_json) into an Iceberg table with every column
in a type Iceberg holds; the staged files are deleted (kept on failure
unless cleanup_on_failure).
* "parquet": Parquet files are uploaded as they are into the table's own
folder (<namespace location>/<table>/[<sub_path>/]) and registered as a
read-only Parquet table - registered first, so Polaris refuses before
anything is uploaded.
conflict_mode fail/append/replace as on Dremio (replace with sub_path
re-does that sub-folder only); table names follow DDS' rule.
diagnose() checks sign-in, files, target and storage without uploading.
- promote(path): a read-only Parquet table -> an Iceberg table of the same
name, in place; its wiki is kept and its original files removed; the
registration is restored if the load fails.
- catalog/object_store.py: RustFS from the kernel - the user's own STS keys
(AssumeRoleWithWebIdentity with the Keycloak token), else the static key
with a note saying why; upload/list/delete with pyarrow.fs.
- DuckDbEngine.add_s3_secret() (scoped to a prefix);
PolarisCatalog.iceberg_select_from() over any source.
- IngestSession runs PolarisIngest on Polaris: ingest(table_format=...),
commit, diagnose, promote; Document Service-only options are reported as
ignored. %ingest shares %catalog's Polaris catalog; help lists promote.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Seventh step of the Polaris migration. - README: a "Polaris backend" section - how EEA_CATALOG_BACKEND picks the backend, the settings (kernel names with their local-stack/.env fallbacks), and what changes on Polaris for paths, SQL, wiki and tags, publish, %gpkg, %dds and %ingest (table_format, promote); the new modules in the Layout table. - %catalog / %dds / %gpkg help: the backend and the root on Polaris, tags on folders and their spelling, publish through the Document Service and its limits, %dds' Keycloak sign-in and namespace paths, %gpkg's Flight gateway; %catalog list no longer names Dremio's API. - debugger/.env.example: EEA_CATALOG_BACKEND and the Polaris, storage, ingest and Flight variables. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Checked against the EEA Lakehouse Kubernetes PoC (Polaris and RustFS port-forwarded) in a scratch namespace, removed afterwards. - Dropping a table purges its data files; a principal Polaris doesn't let purge (DROP_TABLE_WITH_PURGE - root with catalog_admin, here) now gets the table dropped from the catalog instead, so overwrite=True, data_move, delete_table and delete_folder(cascade=True) work for it. Its data files then stay in the bucket. - data_move: when the source can't be dropped, the copy it just made is removed before the error is raised, so a failed move leaves nothing new (the session only undoes steps that finished). - %ingest diagnose: a missing bucket was reported as reachable (listing it finds nothing, like an empty folder); it now checks the bucket. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The Kubernetes PoC exposes Polaris (and DDS, Keycloak, Trino) through an HTTPS gateway whose certificate is signed by the stack's own CA. - LAKEHOUSE_CA_FILE (fallback TRINO_CA_FILE, where JupyterLab mounts the stack's CA): PolarisSettings.ca_file. PolarisRestClient, the DDS public data client and %dds' DocumentsClient verify against it; DuckDB gets SET ca_cert_file plus enable_server_cert_verification, so its Iceberg REST calls are checked too. - The gateway blocks Polaris' own token endpoint: a 404 there now says to sign in with KEYCLOAK_ACCESS_TOKEN (or reach Polaris directly) instead of "refused the client credentials". - README settings table and debugger/.env.example document it. Checked live: with the CA, httpx and DuckDB reach Polaris through the gateway (401 without a real token); without it, TLS verification fails. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
debugger/test_catalog_magic.ipynb now tests the magics against the Polaris stack in debugger/.env, inside one scratch folder (eea_lakehouse.non_domain_datasets.catalog_magic_smoke_test) that the Cleanup section removes, with any data files left behind: - the env cell shows the backend, Polaris URI, CA and who is signed in; every check goes through an independent PolarisCatalog; - folders, use/relative paths, wiki with meta tags, tags, a failed call; - data_copy / schema / create_view / overwrite / data_move into a folder; - a dataflow release: draft_to_version and update_latest_release; - %ingest: Iceberg from Parquet and CSV, a read-only Parquet table with sub_path, diagnose, commit and promote (on generated files); - %dds target/push/list, %gpkg export (needs the Flight gateway); - publish left commented out: it writes to the real public store. The ad-hoc cells that ran draft_to_version, update_latest_release and publish on real dataflows are gone (see git history). Executed end to end against the 172.28.1.6 cluster (root client over a port-forward): everything passes except %dds and %gpkg, which need a Keycloak token (and %gpkg a Flight gateway the cluster doesn't have). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…DuckDB - geopackage/polaris_source.py: PolarisSource, the listing, column types and SELECT both Polaris sources share, and DuckDbSource: rows from the kernel's own DuckDB (the catalog attached as for %catalog, signed in the same way), each table streamed in batches on a cursor of its own, so tables read at once don't share a connection. FlightSource builds on PolarisSource. - open_source: on Polaris, FlightSource when FLIGHT_HOST names a gateway, else DuckDbSource. PolarisSettings.flight_host is empty unless set (flight_configured); the Flight location still defaults to localhost. - DuckDbEngine.stream_batches(); _run lets a stream's StopIteration through. - %ingest table_format="parquet": a new read-only table refuses files already at its location that belong to no table (e.g. an earlier table dropped without purging its files, which would have become rows), and conflict_mode="replace" removes them first. Found running the smoke notebook after an interrupted run. - %gpkg help, README, the .env example and the smoke notebook say so. Checked live against the 172.28.1.6 cluster (no Flight gateway there): %gpkg exported the dfl_natura2000 draft tables (a POLYGON feature layer and attribute tables), and the smoke notebook runs clean end to end. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
- catalog/keycloak.py: login() runs OAuth 2.0 device authorization against KEYCLOAK_URL with a public client (KEYCLOAK_CLIENT_ID, default eea-notebook): it shows a link and a code, waits while the user signs in in a browser, and keeps the session. settings.user_token() then returns that session's access token, renewed with the refresh token shortly before it expires, so Polaris, DuckDB, DDS, the Flight gateway and RustFS STS act as that user. logout(). No password passes through it. - DuckDbEngine reopens its connection when the user's token changes (renewed, or a new sign-in): the connection keeps the token it was opened with. - The smoke notebook signs in (as eea-admin) in its first cell when KEYCLOAK_URL is set and no token is present. - Flight source tests: wait until the test server answers and connect to 127.0.0.1 - the cause of an intermittent "connection refused" failure. - README and debugger/.env.example document it. The realm needs the public client: EEALakeHouse's realm files gain eea-notebook (device-code flow, the jupyterlab client's scopes). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Found running the smoke notebook as eea-admin (device login): the Access service gives a user RustFS keys only for catalog/<namespace>/... of the namespaces they have grants on. - Iceberg ingest with the user's own keys (STS) stages the files inside the target namespace's folder, <location>/_ingestion/<user>-<run>/ <table>/, the one place those keys may write; with the shared key it keeps using the stack's staging area. Removed after loading as before. - ObjectStore.bucket_exists: keys limited to some prefixes may not ask about the bucket itself (HeadBucket -> ACCESS_DENIED); refused now means "there", only a missing bucket fails diagnose. - Flight source tests: an in-process Flight server occasionally starts without ever serving; the fixture starts another instead of failing. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
%gpkg streams each table on a DuckDB cursor of its own. The CA of the
stack's HTTPS gateway was set with a plain SET, which holds for the
session that ran it only, so the cursors' Iceberg REST calls to Polaris
failed certificate verification ("SSL peer certificate ... was not OK").
SET GLOBAL ca_cert_file / enable_server_cert_verification now - global to
the engine's own database only.
Checked against the 172.28.1.6 gateway: on a cursor, without the CA the
request fails TLS; with it, it reaches Polaris (401 without a token).
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The %gpkg export cell keeps its report (gpkg); a new step pushes it to the context's deliverables folder with %dds push(DELIVERABLES, gpkg, overwrite=True) - the report is the file - and lists the folder. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
In the stack's JupyterLab every setting and secret comes from the pod's environment (POLARIS_URI, POLARIS_CATALOG, POLARIS_VENDED_CREDENTIALS, S3_ENDPOINT, DDS_BASE_URL, TRINO_CA_FILE, KEYCLOAK_ACCESS_TOKEN from the token bridge). Checked by running the library with exactly the pod template's variables: - %dds on Polaris: the kernel environment's DDS_BASE_URL wins over a .env lying in a folder (which only fills in a missing one); Dremio keeps its .env-first rule. - DuckDB gets the stack's CA only when Polaris itself is reached over HTTPS: the pod sets TRINO_CA_FILE for Trino while Polaris is plain HTTP, and the CA would replace DuckDB's own bundle (public HTTPS data too). - A CA file that is set but not there (TRINO_CA_FILE where /etc/lakehouse-ca isn't mounted) is ignored instead of failing every connection. - The smoke notebook runs without debugger/.env: in JupyterLab it uses the kernel environment only; outside, .env never overrides it. - README: where the settings come from in JupyterLab. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
test_the_ca_reaches_the_cursors_streams_run_on loaded httpfs without
installing it, which only works where the extension is already cached;
on a fresh CI runner it failed ("Extension httpfs ... not found").
ca_cert_file / enable_server_cert_verification are httpfs settings, so
the test now installs it as the engine does, and skips with the reason
where it can't be downloaded.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The CA of the local stack's HTTPS gateway, copied from the cluster for the debugger notebooks (LAKEHOUSE_CA_FILE): specific to one deployment, not part of the repository. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
After an Iceberg ingest the staged files were deleted, but their folders stayed under _ingestion/: deleting the last file of a "folder" makes pyarrow's S3 layer write an empty marker object for it, so file-by-file deletes leave the folder skeleton behind (seen on the live RustFS). - ObjectStore.remove_folder(folder, up_to=...): deletes the folder with everything in it, markers included, then each parent left empty, up to and including `up_to`; a parent that still holds something (another run's staging) stops it. - PolarisIngest removes its run's staging folder and the empty folders above it up to _ingestion/ after a successful load, and on failure with cleanup_on_failure=True. Checked on the live RustFS: deleting only the file left three empty folders; remove_folder leaves nothing. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Polaris backend for %catalog, %gpkg, %dds and %ingest
Catalog test notebook: update after a live run on the Polaris stack
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Catalog test notebook: strip outputs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Brings #113, #114 and #115 from development into staging.
%catalog,%gpkg,%ddsand%ingestrun on Apache Polaris, which replaces Dremio in the EEA Lakehouse stack. Dremio keeps working:EEA_CATALOG_BACKEND=polaris|dremiopicks the backend. When it is unset, a kernel withPOLARIS_URIgets Polaris and any other kernel stays on Dremio, so existing Dremio notebooks don't change. Commands and arguments are the same; on Polaris, paths start with the catalog's name (eea_lakehouse.<domain>.…) instead ofcatalog..publishpushes#publicviews through DDS.%gpkgreads through the Arrow Flight gateway, or the kernel's DuckDB when there is none.%ingestuploads files to RustFS and loads them as Iceberg (default) or read-only Parquet tables.KEYCLOAK_ACCESS_TOKEN. Outside JupyterLab,catalog.keycloak.login()signs in with the device-code flow.debugger/.env.exampleand the magics' help.debugger/test_catalog_magic.ipynbis a Polaris smoke test. It reads its settings fromdebugger/.env, which it now requires, and is saved without outputs.>=1.1,<3, and the VS Code workspace sets a default Python env manager.🤖 Generated with Claude Code