diff --git a/debugger/test_catalog_magic.ipynb b/debugger/test_catalog_magic.ipynb index 72b0b59..341df06 100644 --- a/debugger/test_catalog_magic.ipynb +++ b/debugger/test_catalog_magic.ipynb @@ -29,27 +29,10 @@ }, { "cell_type": "code", - "execution_count": 1, + "execution_count": null, "id": "3f7af2e9", "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "Sign in to the EEA Lakehouse: open https://172.28.1.6:31443/auth/realms/eea_datalakehouse/device?user_code=EWYT-YSAG (code EWYT-YSAG)\n", - "signed in as eea-admin\n", - "env file /home/oesparza/datahub/EEALakeHouse.python/debugger/.env\n", - "backend polaris\n", - "POLARIS_URI https://172.28.1.6:31443/api/catalog\n", - "catalog (root) eea_lakehouse\n", - "CA file /home/oesparza/datahub/EEALakeHouse.python/debugger/lakehouse-ca.crt\n", - "signed in as eea-admin\n", - "object store http://172.28.1.6:9000\n", - "DDS https://172.28.1.6:31443/dds\n" - ] - } - ], + "outputs": [], "source": [ "import os\n", "from pathlib import Path\n", @@ -100,7 +83,7 @@ }, { "cell_type": "code", - "execution_count": 2, + "execution_count": null, "id": "bdfc96fa", "metadata": {}, "outputs": [], @@ -120,38 +103,10 @@ }, { "cell_type": "code", - "execution_count": 3, + "execution_count": null, "id": "b94a800b", "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "%catalog methods — usage: %catalog data_copy(\"a.b\", \"c.d\") | %catalog set_tags(\"a.b\", [\"reviewed\"]) (each call runs immediately)\n", - "Backend: Dremio or Polaris, picked by EEA_CATALOG_BACKEND (unset: Polaris when POLARIS_URI is set). On Polaris paths start with the catalog's name (POLARIS_CATALOG, 'eea_lakehouse'), a folder is a namespace, and you are signed in with your Keycloak token (KEYCLOAK_ACCESS_TOKEN; else POLARIS_CLIENT_ID/POLARIS_CLIENT_SECRET).\n", - "A new session's context starts at 'catalog' (the root source), not empty — use(None)/use('') reset back to it too; only set_context(None) clears it to no context at all.\n", - "Every path/source_path/target_path (except use's own) is either absolute or relative to the current context, once one is set:\n", - " - starts with 'catalog.' (this deployment's one real root source; 'eea_lakehouse.' on Polaris) -> always absolute, used exactly as given, never appended to the context\n", - " - '.' or './' alone -> the context itself, exactly as get_context() shows it\n", - " - '../' (or a bare '..'), optionally chained ('../../') -> walks up that many levels of the context first, then appends whatever's left, if anything\n", - " - '.name', or a bare 'name' with no leading '.' at all -> both mean relative to the context; the dot is optional sugar, not what makes it relative\n", - "Only use() ever changes the context — no other call does, even one that fully resolved an absolute path.\n" - ] - }, - { - "data": { - "text/html": [ - "
| Command | Parameters | Description |
|---|---|---|
| use | path | Set the current path for every call after this one; path must be a whole, absolute path — never relative to the current context, unlike every other verb's path/source_path/target_path. None or '' resets it to the root ('catalog' on Dremio, 'eea_lakehouse' on Polaris). Raises if path doesn't exist in the catalog. See %%catalog to set it once at the top of a cell. |
| get_context | Show the current path. A new session starts at the root ('catalog' on Dremio, 'eea_lakehouse' on Polaris); use(None)/use('') reset back to it too — None only after an explicit set_context(None). | |
| data_copy | source_path, target_path, overwrite=False, create_target_folder=False | Copy source_path to target_path. overwrite=False (default) raises CatalogOperationError if target_path already exists; overwrite=True replaces it and is not undoable. A target_path ending in / is a folder, not the table: the folder is created first if it doesn't exist (every missing level), and the table lands inside it under the source's own name — data_copy("draft.t", "archive/2027/") makes archive.2027.t; "./" is the context itself; undo removes the folders it created. create_target_folder=True creates every missing folder level of target_path — except the space/source itself, which must already exist (raises CatalogOperationError otherwise). |
| data_move | source_path, target_path, overwrite=False, create_target_folder=False | Move source_path to target_path, always as a TABLE (use create_view for a view). overwrite=False (default) raises CatalogOperationError if target_path already exists; overwrite=True replaces it and is not undoable. A target_path ending in / is a folder, not the table: the folder is created first if it doesn't exist (every missing level), and the table lands inside it under the source's own name — data_copy("draft.t", "archive/2027/") makes archive.2027.t; "./" is the context itself; undo removes the folders it created. create_target_folder=True creates every missing folder level of target_path — except the space/source itself, which must already exist (raises CatalogOperationError otherwise). |
| create_version | source_path, version_name, tables=None, target_path=None, overwrite=False, create_target_folder=True | Copy the listed tables from source_path into a new folder target_path.version_name (as CREATE TABLE snapshots, keeping each table's sub-folders). source_path and version_name must not be blank. tables omitted or empty copies everything under source_path. Each entry is a table or a folder (= every table under it), named as listed under source_path or as list() shows them. target_path omitted means the current context — use() picks where versions go; a missing target_path is created unless create_target_folder=False. Reference/vocabulary tables (a folder named reference(s)/vocabulary(ies) in the path) and views are skipped; the report's notes say which. An existing version folder is an error unless overwrite=True (replaces the listed tables, keeps the rest). |
| draft_to_version | version_name, tables=None, overwrite=False | create_version from the dataflow's draft folder, with no paths to type: the source is the draft folder the context is in (or the draft folder inside the context), the target is draft's parent.versions.version_name (versions is created if missing). tables as in create_version: omitted or empty copies everything in draft. Unlike create_version, views in draft are not skipped: each is copied into the version as a table (a snapshot of what it returns); the report's notes say which. |
| update_latest_release | version_name, overwrite=True | Create a view at the Area's root for every table in versions.version_name, keeping its sub-folders (versions.v1.a.t gets the view a.t; missing folders are created). The context must be the Area folder — one with draft and versions folders just below it, typically catalog.<domain>.<subdomain>.<area> — and versions.version_name must exist — raises at once otherwise. Views in the version are skipped. An existing view is dropped and recreated over the version (overwrite=True, the default; not undoable) — overwrite=False makes it an error instead; an existing table is always an error. Each view is tagged #public, and #public is removed from every table/view under versions, so only the latest release is public. |
| publish | path=None, overwrite=True, partition_by=None | Copy every #public view of a dataflow folder (as update_latest_release leaves them) into public_s3."dh-prod-data-public", as tables at the same full catalog path (catalog.x.y.dataflow.a.t is copied to public_s3."dh-prod-data-public".catalog.x.y.dataflow.a.t). The dataflow folder is path when given (absolute, or relative to the context), else the %catalog use(...) context; with neither it raises. It must have draft, versions and reference (or references) folders just below it — raises at once otherwise. Views and tables in those three folders are ignored; views without the tag are skipped and the report's notes say which. An existing table is replaced (overwrite=True, the default; not undoable) — overwrite=False makes it an error, and then nothing is copied. Each table is checked once copied, and the report's notes give its row count. All or nothing: if any table fails, everything the publish did is rolled back (replaced tables are restored) and an error says which table failed. partition_by (optional) partitions the tables by existing fields, in order: a list for every view (partition_by=["year", "country"]), or a dict for each view's own, keyed by its path below the Area (partition_by={"eu_sdg.monitoringsites": ["year"]}; views left out are not partitioned). A field a view doesn't have raises at once, when publish is called. On Polaris each #public view goes through the Document Service into the public store at <namespace path>/<view>/ (DDS_BASE_URL; you must be a publisher): not all or nothing — an error names the views already published — and partition_by / overwrite=False are not available. |
| list | path='' | Show every table/view under path as a JSON array of {type, name} — type TABLE or VIEW, name the full dot-separated path: its own, then every child folder's, at any depth — walked folder by folder through the catalog's own API (Dremio's or Polaris'), no SQL. path may use '.' or '/' separators. path may be omitted to list the current context itself — raises CatalogSessionError if none is set. Raises CatalogOperationError if path doesn't exist. |
| schema | path | Show path's column schema and row count (never fetches the actual rows). path must be a table or view — raises CatalogOperationError otherwise, or if path doesn't exist at all. |
| delete_table | path | Delete the table at path. Not undoable. Raises CatalogOperationError if path doesn't exist (unlike a bare DROP TABLE, this doesn't quietly no-op on a typo). |
| create_view | source_path, target_path, overwrite=False, create_target_folder=False | Create a VIEW at target_path over source_path, leaving source_path untouched. overwrite=False (default) raises CatalogOperationError if target_path already exists; overwrite=True replaces it and is not undoable. create_target_folder=True creates every missing folder level of target_path — except the space/source itself, which must already exist (raises CatalogOperationError otherwise). |
| delete_view | path | Delete the view at path. Not undoable. Raises CatalogOperationError if path doesn't exist (unlike a bare DROP VIEW, this doesn't quietly no-op on a typo). |
| set_wiki | path, text, tags=None | Set a path's wiki text. tags: a list of {tag_name, tag_value, tag_title} dicts, e.g. [{"tag_name": "owner", "tag_value": "bw-team", "tag_title": "Owner"}]. Ignored if path is a table/view (they have set_tags/get_tags for that instead). |
| delete_wiki | path | Delete a path's wiki text. |
| get_wiki | path | Show a path's wiki text. Raises CatalogOperationError if the path doesn't exist, or exists but has no wiki at all. |
| set_tags | path, tags | Replace a path's tag set. tags: a list of strings, e.g. ["reviewed"]. Tables/views only — raises CatalogOperationError otherwise. On Polaris folders take tags too, and tags are kept lower case without '#' ('#public' and 'public' are the same tag). |
| delete_tags | path, tags | Remove tags from a path's tag set. tags: a list of strings, e.g. ["reviewed"]. Tables/views only — raises CatalogOperationError otherwise. |
| get_tags | path | Show the tags on a path — tables/views only. Raises CatalogOperationError if the path doesn't exist or isn't a table/view. |
| create_folder | path, create_parents=False | Create a folder. create_parents=True creates every missing level of the full path; create_parents=False (default) raises CatalogOperationError if the parent folder doesn't already exist. |
| delete_folder | path, cascade=False | Delete a folder. Not undoable. cascade=True also deletes everything at path and below; cascade=False (default) raises CatalogOperationError if the folder isn't empty. A path that's already gone is not an error. |