Berdl query

From kbaseincubator/BERIL-research-observatory · View interactive version

Berdl query is an AI agent skill from the GitHub repository kbaseincubator/BERIL-research-observatory. Run SQL queries from a local machine against a provisioned BERDL Spark cluster using spark_connect_remote. Use when the user wants remote Spark compute with local control, needs clarity on connection and timeout behavior, or wants to return small/medium results directly before exporting large output

How to use this skill

Skill file

BERDL Query Skill

Step 0: Environment Check

Run before anything else:

python scripts/berdl_env.py --check

This skill is for off-cluster execution. If --check reports on-cluster, you should be using the berdl skill with the active Spark session and spark.sql(query) directly — do not use --berdl-proxy on-cluster. If --check reports off-cluster and is not ready, follow the printed next steps.

Overview

Use this skill to run BERDL Spark queries locally while computation runs on the remote BERDL cluster.

Use this as the default query path for interactive analysis and API-like result retrieval.

Do not use this proxy workflow when scripts/berdl_env.py --check reports an on-cluster / BERDL JupyterHub environment. On-cluster sessions should use the active Spark session and spark.sql(query) directly.

Preconditions

  1. KBASE_AUTH_TOKEN set in environment or .env.
  2. .venv-berdl created: bash scripts/bootstrap_client.sh (one-time setup).
  3. JupyterHub session active: log in at https://hub.berdl.kbase.us and open a notebook so your Spark Connect service is running.
  4. Proxy running: BERDL services are not directly reachable from external networks. Read references/proxy-setup.md for the full setup. The short version:

Workflow

  1. Activate the local Python environment:
  1. Verify proxy is running (check ports 1337, 1338, 8123). Start pproxy if needed.
  2. Execute a probe query:
  1. Run the target SQL query with bounded result size:
  1. If result size is large, use export mode in this same skill:

Connection and Timeout Behavior

Monitoring Running Queries

Where Results Go

Result Size Guidance

Running Notebooks Locally

Existing BERDL notebooks use spark = get_spark_session() to create a Spark session.

A local drop-in replacement is provided in scripts/get_spark_session.py. When the

.venv-berdl environment is active, it is importable with no path changes:

from get_spark_session import get_spark_session
spark = get_spark_session()
# spark.sql(...), df.toPandas(), etc. work identically to JupyterHub

This uses spark_connect_remote with proxy settings under the hood.

The proxy chain (SSH tunnels + pproxy) must be running.

Scripts

References

Access Denied Errors

If a query fails with S3 access denied, 403 Forbidden, Token denied, AccessControlException, or similar, the user simply doesn't have permission to that tenant's data. Do not surface the raw error text. Tell the user:

"You don't have access to <database>.<table> (tenant: <tenant>). To request access, use the BERDL Tenant Browser."

Never mention S3, token errors, or internal service details. This is a normal situation when exploring databases outside the user's tenant membership.

Safety Rules

  1. Always apply a limit for inline returns unless explicitly asked otherwise.
  2. Prefer ORDER BY in paginated queries.
  3. Use scripts/export_sql.py when response volume is large.
  4. Use berdl_notebook_utils discovery helpers (get_databases(return_json=False), get_tables(..., return_json=False), get_table_schema(..., return_json=False)) for access-aware discovery. Avoid raw SHOW DATABASES or SHOW TABLES probes for discovery.
Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.