Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions knowledge_base/database_with_catalog/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# OLTP database instance with a catalog

This example demonstrates how to define an OLTP database instance and a database catalog in a Databricks Asset Bundle.

It includes and deploys an example database instance and a catalog. When the instance is making changes to the database, the changes are reflected in Unity Catalog.
Comment thread
anton-107 marked this conversation as resolved.
Outdated

For more information about Databricks database instances, see the [documentation](https://docs.databricks.com/aws/en/oltp/).

## Prerequisites

* Databricks CLI v0.265.0 or above
* `psql` client version 14 or above (only needed to run the demo data generation)

## Usage

Modify `databricks.yml`:
* Update the `host` field under `workspace` to the Databricks workspace to deploy to

Run `databricks bundle deploy` to deploy the bundle.

Run the following queries to populate your database with sample data:

- `databricks psql my-instance -- -d my_database -c "CREATE TABLE IF NOT EXISTS hello_world (id SERIAL PRIMARY KEY, message TEXT, number INTEGER, created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP);"`
- `databricks psql my-instance -- -d my_database -c "INSERT INTO hello_world (message, number) SELECT 'Hello World #' || generate_series, generate_series FROM generate_series(1, 100);"`
- `databricks psql my-instance -- -d my_database -c "SELECT * FROM hello_world;"`
Comment thread
anton-107 marked this conversation as resolved.
Outdated

Open your catalog in Databricks Workspace to explore generated data in Unity Catalog: `databricks bundle open my_catalog`
Comment thread
anton-107 marked this conversation as resolved.
Outdated
Navigate to `public` schema, then to `hello_world` table, then to "Sample data"
Comment thread
anton-107 marked this conversation as resolved.
Outdated
31 changes: 31 additions & 0 deletions knowledge_base/database_with_catalog/databricks.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
bundle:
name: database-catalog-example

# workspace:
# host: https://myworkspace.cloud.databricks.com
Comment thread
anton-107 marked this conversation as resolved.

resources:
database_instances:
my_instance:
name: my-instance
capacity: CU_1
database_catalogs:
my_catalog:
database_instance_name: ${resources.database_instances.my_instance.name}
name: example_catalog
database_name: my_database
create_database_if_not_exists: true
Comment thread
anton-107 marked this conversation as resolved.


# Defines the targets for this bundle.
# Targets allow you to deploy the same bundle to different Databricks workspaces.
targets:
prod: {
# No overrides
}
Comment thread
anton-107 marked this conversation as resolved.
Outdated
dev:
# This target is for development purposes.
# It defaults to the current Databricks workspace.
default: true
mode: development