aidp-analyzing-data — natural language → Spark SQL
Answer business questions by grounding in the catalog/semantic model, reusing verified queries when
possible, then executing Spark SQL via the bundled scripts/aidp_sql.py helper.
When to use
- Any data question, or "run this SQL on AIDP".
Source is an external / non-lakehouse system (Fusion, EPM, Oracle ADB/ExaCS, Snowflake, S3, …)? This skill is lakehouse-native Spark SQL. To pull from an external source, use the
oracle-ai-data-platform-workbench-spark-connectorsplugin'saidp-<source>skill (install it if absent; run itsaidp-connectors-bootstrapskill once to push the helper package to the cluster), oraidp-federateto join across sources.
Workflow (grounding-first — this is the accuracy lever)
- Verified-query match. Read
.aidp/verified-queries.md; if averified: trueentry closely matches the question (similar text + table overlap), reuse its SQL (adapt only dates/bind values) and say so. - Ground. Otherwise read
.aidp/catalog.md+.aidp/semantic.md: map concepts→tables via Quick Reference/synonyms, use recorded join keys (don't guess joins), use value dictionaries for WHERE literals, prefer metric SQL expressions from the semantic model. If the catalog cache is missing, runaidp-catalog-initfirst. - Scope small. Use the few tables the question needs; for big fact tables add date filters; consider a pre-joined view for repeated complex asks.
- Execute. Run the SQL via the bundled helper — it mints a UPST from the api_key DEFAULT profile and
auto-creates a scratch notebook on the target cluster (no MCP, no AIDP_SESSION required):
Returns JSON
{status, execution_count, outputs, spark_job_ids, error}. Each invocation runs the cell; keep the same<SQL>shape across follow-ups. Smoke-test connectivity with--code "spark.sql('SELECT 1').show()". - Present the result clearly (table + a one-line read of what it shows). Show the SQL you ran.
- Cache the learning. Offer to save a new concept→table mapping to
.aidp/catalog.mdand/or register the working query viaaidp-verified-queries(which validates before marking it verified).
Reliability rules
- Real-world NL-to-SQL is unreliable without grounding — never fabricate column/table names; if unsure,
confirm against the catalog cache (or a
SHOW COLUMNS/DESCRIBEcell) or ask. - Qualify tables fully (
catalog.schema.table). Default catalog/schema only when the user implies them. This includes metadata commands: useSHOW TABLES IN <catalog>.<schema>(e.g.SHOW TABLES IN default.default), not the unqualifiedSHOW TABLES IN default— the bare form raisesAnalysisException: [SCHEMA_NOT_FOUND]becausedefaultresolves as a catalog, not a schema. - If a query errors, read the Spark error from the helper's
errorfield, fix grounded in the catalog, and retry — don't guess repeatedly. - Ensure the cluster is RUNNING before executing (see
aidp-cluster-ops); the helper attaches to the cluster you pass via--cluster. - For LLM-in-SQL (
ai_generate) seeaidp-ai-sql; for cross-source joins seeaidp-federate.
References
- scripts/aidp_sql.py — bundled Spark-SQL executor (the plugin's only code)
- references/verified-queries.md · references/semantic-model.md · references/no-mcp-rest-map.md


