cancel
Showing results forย 
Search instead forย 
Did you mean:ย 
Data Engineering
Join discussions on data engineering best practices, architectures, and optimization strategies within the Databricks Community. Exchange insights and solutions with fellow data engineers.
cancel
Showing results forย 
Search instead forย 
Did you mean:ย 

Genie spaces with DABs - how do you deal with the table ordering?

juanlozadab
Contributor

Hi all,

I'm about to start managing Genie spaces as code with Asset Bundles and wanted
to ask before I build it.

From what I'm reading, the genie_spaces resource needs the tables in its
data_sources to already exist when you deploy. That's fine for an environment
that's already running, but it seems to break the first deploy to a new target,
where the same bundle is creating the schema and tables and then declaring the
Genie space on top of them.

I could split it into two deploys, but then I lose the single command deploy
that's half the point of using bundles.

For anyone already doing this:

Are you keeping the Genie space in the same bundle as the tables it reads, or
did you end up separating them?

And one I haven't found an answer to anywhere: on a redeploy, what happens to
the instructions and example queries people add to the space through the UI?
Does the bundle overwrite them?

Thanks

jlb
3 ACCEPTED SOLUTIONS

Accepted Solutions

maggie33west
New Contributor III

Managing Databricks Genie spaces via Asset Bundles (DABs) introduces a few specific state and dependency challenges, especially around initial provisioning and UI collaboration. Most teams end up separating the Genie space from the underlying data layer. Because the genie_spaces resource validates its data_sources against Unity Catalog at deployment time, a single-bundle deploy will fail on a brand-new target environment where the tables don't exist yet. Keeping data pipeline jobs/tables in a primary data bundle and provisioning the Genie space in a secondary, downstream bundle ensures that all referenced schemas, views, and tables are fully established before the Genie space is declared.

View solution in original post

Valeria_Koz_DBX
Databricks Employee
Databricks Employee

Hi @juanlozadab ,

To answer your questions separately:

Q1: same bundle or separate? Answer in short: separate

  • Deploying schema + pipeline + genie_spaces in one bundle fails on a fresh target. A pipeline or job resource only gets defined at deploy time; it doesn't run, so no tables exist yet when the Genie space is created. 
  • Splitting into two bundles is a valid workaround. It's not the only answer anymore, though. There is a new job_run resource (CLI โ‰ฅ 1.7.0, direct engine only). It triggers a job run as part of bundle deploy, and "downstream objects that take a deployment on the run completing will only deploy once it has successfully run." That keeps everything in one bundle: schema โ†’ job that builds the tables โ†’ job_run โ†’ genie_spaces.
  • Couple of Prerequisites for the deployment
    • genie_spaces needs the direct deployment engine (bundle: engine: direct) and CLI โ‰ฅ 1.3.0.
    • The identity that deploys must be able to read every table the space uses.

Q2: are UI edits overwritten on redeploy?

  • The bundle is the source of truth. The space definition (serialized_space / file_path โ†’ *.geniespace.json) includes the instructions and sample/example SQL, so a redeploy puts the bundle's version back.
  • The supported workflow is to pull UI edits back into the bundle first:
    • databricks bundle generate genie-space --resource <key> --force for a one-off sync, or --watch to keep it in sync during development;
    • commit the result;
    • then bundle deploy --target prod.
  • Recommended practice: edit in a dev space, sync, commit and promote. Treat prod as read-only in the UI.

View solution in original post

VladTamas
New Contributor III

Short answer: you can keep everything in one bundle and one databricks bundle deploy. Add a job_runs resource that runs the job that builds the tables, and reference that run from the Genie agent so the CLI creates the agent last. On a redeploy the bundle does overwrite instructions and example queries added in the UI, so pull UI edits back with databricks bundle generate genie-space --resource <key> --force before you deploy [1][2].

1. Same bundle or separate?

The Genie agent create call validates the tables in data_sources, so a fresh target fails if the tables don't exist yet. I reproduced it on CLI 1.20.0:

Error: cannot create resources.genie_spaces.probe_space: ... Table 'workspace.mvp_probe.not_created_yet' does not exist. (403 PERMISSION_DENIED)

This shape fixed it in a single deploy. genie_spaces and job_runs both need the direct deployment engine, which is the only engine in CLI 1.20.0 [1][3]:

bundle:
  name: sales_genie
  engine: direct

resources:
  pipelines:
    sales_pipeline:
      name: sales_pipeline
      serverless: true
      catalog: workspace
      schema: sales
      libraries:
        - file:
            path: ./src/sales.sql

  jobs:
    build_tables:
      name: build_tables
      tasks:
        - task_key: refresh
          pipeline_task:
            pipeline_id: ${resources.pipelines.sales_pipeline.id}

  job_runs:
    seed:
      job_id: ${resources.jobs.build_tables.id}

  genie_spaces:
    sales_agent:
      title: Sales agent
      description: 'Built after run ${resources.job_runs.seed.run_id}'
      warehouse_id: <warehouse-id>
      file_path: ./src/sales_agent.geniespace.json

What happened on the first deploy:

  1. The pipeline and job were created.
  2. The job_runs resource started the job, and the CLI printed Output from job_runs.seed: ... SUCCESS once the run finished.
  3. Only then did it print Created genie_spaces.<key>, because the ${resources.job_runs.seed.run_id} reference makes the agent depend on the run.

The run is recorded in bundle state, so my next deploy didn't re-run it. If you want it to re-run on every deploy, job_runs supports lifecycle.triggers (on_bundle_deploy: true) [1].

I'd still split into two bundles if the table build is slow (the deploy blocks until the run ends) or if another team owns the tables.

2. What happens to UI edits on redeploy?

They get overwritten. I added a text instruction outside the bundle, which is what a UI edit does. databricks bundle plan then showed update genie_spaces.sales_agent, and after deploy the instruction was gone.

To keep UI work:

  1. Store the definition in a file (file_path: ./src/<name>.geniespace.json). The --resource sync needs this. With an inline serialized_space the CLI fails with genie space resource "..." has no file path defined.
  2. Export an existing agent once:
databricks bundle generate genie-space --existing-id <space-id> --key sales_agent
  1. Before each deploy, pull UI changes, review the diff and commit [2]:
databricks bundle generate genie-space --resource sales_agent --force
  1. While people are actively iterating in the UI, --watch --force keeps polling for changes [2].

After a pull, bundle plan can still show an update because the JSON key order differs. The content is the same.

What I'd do

Keep the Genie agent in the same bundle as its pipeline for dev and test targets, with the job_runs seed, and treat the .geniespace.json file in Git as the source of truth. Let people edit in the dev agent, sync with bundle generate genie-space --resource ... --force, and promote to prod only through bundle deploy.

References

[1] Declarative Automation Bundles resources | Databricks on AWS โ€” docs.databricks.com/aws/dev-tools/bundles/resources
[2] bundle command group | Databricks on AWS โ€” docs.databricks.com/aws/dev-tools/cli/bundle-commands
[3] Migrate to the direct deployment engine | Databricks on AWS โ€” docs.databricks.com/aws/dev-tools/bundles/direct

View solution in original post

3 REPLIES 3

maggie33west
New Contributor III

Managing Databricks Genie spaces via Asset Bundles (DABs) introduces a few specific state and dependency challenges, especially around initial provisioning and UI collaboration. Most teams end up separating the Genie space from the underlying data layer. Because the genie_spaces resource validates its data_sources against Unity Catalog at deployment time, a single-bundle deploy will fail on a brand-new target environment where the tables don't exist yet. Keeping data pipeline jobs/tables in a primary data bundle and provisioning the Genie space in a secondary, downstream bundle ensures that all referenced schemas, views, and tables are fully established before the Genie space is declared.

Valeria_Koz_DBX
Databricks Employee
Databricks Employee

Hi @juanlozadab ,

To answer your questions separately:

Q1: same bundle or separate? Answer in short: separate

  • Deploying schema + pipeline + genie_spaces in one bundle fails on a fresh target. A pipeline or job resource only gets defined at deploy time; it doesn't run, so no tables exist yet when the Genie space is created. 
  • Splitting into two bundles is a valid workaround. It's not the only answer anymore, though. There is a new job_run resource (CLI โ‰ฅ 1.7.0, direct engine only). It triggers a job run as part of bundle deploy, and "downstream objects that take a deployment on the run completing will only deploy once it has successfully run." That keeps everything in one bundle: schema โ†’ job that builds the tables โ†’ job_run โ†’ genie_spaces.
  • Couple of Prerequisites for the deployment
    • genie_spaces needs the direct deployment engine (bundle: engine: direct) and CLI โ‰ฅ 1.3.0.
    • The identity that deploys must be able to read every table the space uses.

Q2: are UI edits overwritten on redeploy?

  • The bundle is the source of truth. The space definition (serialized_space / file_path โ†’ *.geniespace.json) includes the instructions and sample/example SQL, so a redeploy puts the bundle's version back.
  • The supported workflow is to pull UI edits back into the bundle first:
    • databricks bundle generate genie-space --resource <key> --force for a one-off sync, or --watch to keep it in sync during development;
    • commit the result;
    • then bundle deploy --target prod.
  • Recommended practice: edit in a dev space, sync, commit and promote. Treat prod as read-only in the UI.

VladTamas
New Contributor III

Short answer: you can keep everything in one bundle and one databricks bundle deploy. Add a job_runs resource that runs the job that builds the tables, and reference that run from the Genie agent so the CLI creates the agent last. On a redeploy the bundle does overwrite instructions and example queries added in the UI, so pull UI edits back with databricks bundle generate genie-space --resource <key> --force before you deploy [1][2].

1. Same bundle or separate?

The Genie agent create call validates the tables in data_sources, so a fresh target fails if the tables don't exist yet. I reproduced it on CLI 1.20.0:

Error: cannot create resources.genie_spaces.probe_space: ... Table 'workspace.mvp_probe.not_created_yet' does not exist. (403 PERMISSION_DENIED)

This shape fixed it in a single deploy. genie_spaces and job_runs both need the direct deployment engine, which is the only engine in CLI 1.20.0 [1][3]:

bundle:
  name: sales_genie
  engine: direct

resources:
  pipelines:
    sales_pipeline:
      name: sales_pipeline
      serverless: true
      catalog: workspace
      schema: sales
      libraries:
        - file:
            path: ./src/sales.sql

  jobs:
    build_tables:
      name: build_tables
      tasks:
        - task_key: refresh
          pipeline_task:
            pipeline_id: ${resources.pipelines.sales_pipeline.id}

  job_runs:
    seed:
      job_id: ${resources.jobs.build_tables.id}

  genie_spaces:
    sales_agent:
      title: Sales agent
      description: 'Built after run ${resources.job_runs.seed.run_id}'
      warehouse_id: <warehouse-id>
      file_path: ./src/sales_agent.geniespace.json

What happened on the first deploy:

  1. The pipeline and job were created.
  2. The job_runs resource started the job, and the CLI printed Output from job_runs.seed: ... SUCCESS once the run finished.
  3. Only then did it print Created genie_spaces.<key>, because the ${resources.job_runs.seed.run_id} reference makes the agent depend on the run.

The run is recorded in bundle state, so my next deploy didn't re-run it. If you want it to re-run on every deploy, job_runs supports lifecycle.triggers (on_bundle_deploy: true) [1].

I'd still split into two bundles if the table build is slow (the deploy blocks until the run ends) or if another team owns the tables.

2. What happens to UI edits on redeploy?

They get overwritten. I added a text instruction outside the bundle, which is what a UI edit does. databricks bundle plan then showed update genie_spaces.sales_agent, and after deploy the instruction was gone.

To keep UI work:

  1. Store the definition in a file (file_path: ./src/<name>.geniespace.json). The --resource sync needs this. With an inline serialized_space the CLI fails with genie space resource "..." has no file path defined.
  2. Export an existing agent once:
databricks bundle generate genie-space --existing-id <space-id> --key sales_agent
  1. Before each deploy, pull UI changes, review the diff and commit [2]:
databricks bundle generate genie-space --resource sales_agent --force
  1. While people are actively iterating in the UI, --watch --force keeps polling for changes [2].

After a pull, bundle plan can still show an update because the JSON key order differs. The content is the same.

What I'd do

Keep the Genie agent in the same bundle as its pipeline for dev and test targets, with the job_runs seed, and treat the .geniespace.json file in Git as the source of truth. Let people edit in the dev agent, sync with bundle generate genie-space --resource ... --force, and promote to prod only through bundle deploy.

References

[1] Declarative Automation Bundles resources | Databricks on AWS โ€” docs.databricks.com/aws/dev-tools/bundles/resources
[2] bundle command group | Databricks on AWS โ€” docs.databricks.com/aws/dev-tools/cli/bundle-commands
[3] Migrate to the direct deployment engine | Databricks on AWS โ€” docs.databricks.com/aws/dev-tools/bundles/direct