Skip to content
Open
Show file tree
Hide file tree
Changes from all 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
20 changes: 10 additions & 10 deletions .github/workflows/deploy_prd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ on:
workflow_dispatch:
push:
branches:
- main
- prod

jobs:
deploy-prd:
Expand Down Expand Up @@ -35,21 +35,21 @@ jobs:

- name: Validar bundle Databricks
env:
DATABRICKS_CONFIG_PROFILE: PRD
DATABRICKS_CONFIG_PROFILE: PROD
run: |
cd dab_treinamento
databricks bundle validate --target prd
cd dab_test
databricks bundle validate --target prod

- name: Deploy bundle Databricks
env:
DATABRICKS_CONFIG_PROFILE: PRD
DATABRICKS_CONFIG_PROFILE: PROD
run: |
cd dab_treinamento
databricks bundle deploy --target prd
cd dab_test
databricks bundle deploy --target prod

- name: Executar job Databricks
env:
DATABRICKS_CONFIG_PROFILE: PRD
DATABRICKS_CONFIG_PROFILE: PROD
run: |
cd dab_treinamento
databricks bundle run dab_treinamento_job --target prd
cd dab_test
databricks bundle run dab_test_job --target prod
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# repositorio-teste video - p
1 change: 0 additions & 1 deletion dab_test
Submodule dab_test deleted from 2850ef
3 changes: 3 additions & 0 deletions dab_test/.vscode/__builtins__.pyi
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Typings for Pylance in Visual Studio Code
# see https://github.com/microsoft/pyright/blob/main/docs/builtins.md
from databricks.sdk.runtime import *
7 changes: 7 additions & 0 deletions dab_test/.vscode/extensions.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"recommendations": [
"charliermarsh.ruff",
"databricks.databricks",
"redhat.vscode-yaml"
]
}
39 changes: 39 additions & 0 deletions dab_test/.vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
{
"jupyter.interactiveWindow.cellMarker.codeRegex": "^# COMMAND ----------|^# Databricks notebook source|^(#\\s*%%|#\\s*\\<codecell\\>|#\\s*In\\[\\d*?\\]|#\\s*In\\[ \\])",
"jupyter.interactiveWindow.cellMarker.default": "# COMMAND ----------",
"python.testing.pytestArgs": [
"."
],
"files.exclude": {
"**/*.egg-info": true,
"**/__pycache__": true,
".pytest_cache": true,
"dist": true,
},
"files.associations": {
"**/.gitkeep": "markdown"
},

// Pylance settings (VS Code)
// Set typeCheckingMode to "basic" to enable type checking!
"python.analysis.typeCheckingMode": "off",
"python.analysis.extraPaths": ["src", "lib", "resources"],
"python.analysis.diagnosticMode": "workspace",
"python.analysis.stubPath": ".vscode",

// Pyright settings (Cursor)
// Set typeCheckingMode to "basic" to enable type checking!
"cursorpyright.analysis.typeCheckingMode": "off",
"cursorpyright.analysis.extraPaths": ["src", "lib", "resources"],
"cursorpyright.analysis.diagnosticMode": "workspace",
"cursorpyright.analysis.stubPath": ".vscode",

// General Python settings
"python.defaultInterpreterPath": "./.venv/bin/python",
"python.testing.unittestEnabled": false,
"python.testing.pytestEnabled": true,
"[python]": {
"editor.defaultFormatter": "charliermarsh.ruff",
"editor.formatOnSave": true,
},
}
25 changes: 25 additions & 0 deletions dab_test/AGENTS.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# Declarative Automation Bundles Project

This project uses Declarative Automation Bundles (DABs) for deployment. Add project-specific instructions below.

## For AI Agents: Use Databricks AI Tools

**BEFORE any other action, read the `databricks-core` skill.**

It sets you up to work with this project reliably: CLI authentication, profile
selection, data discovery, and the bundle deployment workflow. Without it,
results are often slower and less accurate.

If this skill is not available (Databricks AI Tools are not installed), you can install them for your coding agent in seconds:

```bash
databricks aitools install
```

If the CLI is not installed, see: https://docs.databricks.com/dev-tools/cli/install

---

## Project Instructions

<!-- Add your project-specific instructions, coding conventions, or notes here -->
6 changes: 6 additions & 0 deletions dab_test/CLAUDE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# CLAUDE.md

Project guidance for AI agents lives in AGENTS.md.
Claude Code loads it via the import below.

@AGENTS.md
71 changes: 71 additions & 0 deletions dab_test/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
# dab_test

The 'dab_test' project was generated by using the default-python template.

* `src/`: Python source code for this project.
* `src/dab_test/`: Shared Python code that can be used by jobs and pipelines.
* `resources/`: Resource configurations (jobs, pipelines, etc.)
* `tests/`: Unit tests for the shared Python code.
* `fixtures/`: Fixtures for data sets (primarily used for testing).


## Getting started

Choose how you want to work on this project:

(a) Directly in your Databricks workspace, see
https://docs.databricks.com/dev-tools/bundles/workspace.

(b) Locally with an IDE like Cursor or VS Code, see
https://docs.databricks.com/dev-tools/vscode-ext.html.

(c) With command line tools, see https://docs.databricks.com/dev-tools/cli/databricks-cli.html

If you're developing with an IDE, dependencies for this project should be installed using uv:

* Make sure you have the UV package manager installed.
It's an alternative to tools like pip: https://docs.astral.sh/uv/getting-started/installation/.
* Run `uv sync --dev` to install the project's dependencies.


# Using this project using the CLI

The Databricks workspace and IDE extensions provide a graphical interface for working
with this project. It's also possible to interact with it directly using the CLI:

1. Authenticate to your Databricks workspace, if you have not done so already:
```
$ databricks configure
```

2. To deploy a development copy of this project, type:
```
$ databricks bundle deploy --target dev
```
(Note that "dev" is the default target, so the `--target` parameter
is optional here.)

This deploys everything that's defined for this project.
For example, the default template would deploy a pipeline called
`[dev yourname] dab_test_etl` to your workspace.
You can find that resource by opening your workpace and clicking on **Jobs & Pipelines**.

3. Similarly, to deploy a production copy, type:
```
$ databricks bundle deploy --target prod
```
Note the default template has a includes a job that runs the pipeline every day
(defined in resources/sample_job.job.yml). The schedule
is paused when deploying in development mode (see
https://docs.databricks.com/dev-tools/bundles/deployment-modes.html).

4. To run a job or pipeline, use the "run" command:
```
$ databricks bundle run
```

5. Finally, to run tests locally, use `pytest`:
```
$ uv run pytest
```
video 01
51 changes: 51 additions & 0 deletions dab_test/databricks.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
# This is a Declarative Automation Bundle definition for dab_test.
# See https://docs.databricks.com/dev-tools/bundles/index.html for documentation.
bundle:
name: dab_test
uuid: 348afa13-f395-4806-9fcf-f5fc52935756

include:
- resources/jobs/*.yml
- resources/pipelines/*.yml
- resources/schemas/*.yml

artifacts:
python_artifact:
type: whl
build: uv build --wheel

# Variable declarations. These variables are assigned in the dev/prod targets below.
variables:
catalog:
description: The catalog to use
schema:
description: The schema to use
catalog_name:
description: "Catalog used by the job"
default: dev
performance_target:
description: "Performance target for the job"
default: "STANDARD"
targets:
dev:
# The default target uses 'mode: development' to create a development copy.
# - Deployed resources get prefixed with '[dev my_user_name]'
# - Any job schedules and triggers are paused by default.
# See also https://docs.databricks.com/dev-tools/bundles/deployment-modes.html.
mode: development
default: true
workspace:
host: https://dbc-39ee3252-8e93.cloud.databricks.com
variables:
catalog: dev
schema: rescue_b
prod:
mode: production
workspace:
host: https://dbc-39ee3252-8e93.cloud.databricks.com
variables:
catalog: prod
schema: rescue_b
permissions:
- user_name: rubencruzh@gmail.com
level: CAN_MANAGE
9 changes: 9 additions & 0 deletions dab_test/fixtures/.gitkeep
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# Test fixtures directory

Add JSON or CSV files here. In tests, use them with `load_fixture()`:

```
def test_using_fixture(load_fixture):
data = load_fixture("my_data.json")
assert len(data) >= 1
```
36 changes: 36 additions & 0 deletions dab_test/pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
[project]
name = "dab_test"
version = "0.0.1"
authors = [{ name = "rubencruzh@gmail.com" }]
requires-python = ">=3.10,<3.13"
dependencies = [
# Any dependencies for jobs and pipelines in this project can be added here
# See also https://docs.databricks.com/dev-tools/bundles/library-dependencies
#
# LIMITATION: for pipelines, dependencies are cached during development;
# add dependencies to the 'environment' section of your pipeline.yml file instead
]

[dependency-groups]
dev = [
"pytest",
"ruff",
"pyyaml",
"databricks-dlt",
"databricks-connect>=15.4,<15.5",
"ipykernel",
]

[project.scripts]
main = "dab_test.main:main"

[build-system]
requires = ["hatchling"]
build-backend = "hatchling.build"


[tool.hatch.build.targets.wheel]
packages = ["src/dab_test"]

[tool.ruff]
line-length = 120
36 changes: 36 additions & 0 deletions dab_test/resources/jobs/dab_test_job.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# Job do treinamento para executar o notebook demo.
resources:
jobs:
dab_test_job:
name: dab_test_job
tags:
treinamento: dab
ambiente: dev
area: engenharia
description: Job de treinamento que ingere usuários de exemplo com parâmetros dinâmicos.
parameters:
- name: catalog_name
default: ${var.catalog_name}
- name: user_id
default: "3"
- name: user_name
default: "Anselmo"
email_notifications:
on_failure:
- rubencruzh@gmail.com
timeout_seconds: 900
schedule:
quartz_cron_expression: "0 0 8 ? * TUE *"
timezone_id: America/Sao_Paulo
tasks:
- task_key: ingestao_usuarios
description: Ingestão de usuários de exemplo via notebook.
notebook_task:
notebook_path: ../../src/notebooks/demo_notebook.py
base_parameters:
catalog_name: "{{job.parameters.catalog_name}}"
user_id: "{{job.parameters.user_id}}"
user_name: "{{job.parameters.user_name}}"
queue:
enabled: true
performance_target: ${var.performance_target}
Empty file.
14 changes: 14 additions & 0 deletions dab_test/src/dab_test/main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
from databricks.sdk.runtime import spark
from pyspark.sql import DataFrame


def find_all_taxis() -> DataFrame:
return spark.read.table("samples.nyctaxi.trips")


def main():
find_all_taxis().show(5)


if __name__ == "__main__":
main()
30 changes: 30 additions & 0 deletions dab_test/src/notebooks/demo_notebook.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# Databricks notebook source
# DBTITLE 1,Configura widgets de entrada
dbutils.widgets.text("catalog", "dev", "Catalog Name")
dbutils.widgets.text("user_id", "3", "User ID")
dbutils.widgets.text("user_name", "Anselmo", "User Name")

# COMMAND ----------
# DBTITLE 1,Obtém valores informados
catalog_name = dbutils.widgets.get("catalog")
user_id = int(dbutils.widgets.get("user_id"))
user_name = dbutils.widgets.get("user_name")
print(f"Using Catalog: {catalog_name}")
print(f"Inserting user_id={user_id}, user_name={user_name}")

# COMMAND ----------
# DBTITLE 1,Cria tabela e insere dados de exemplo + parâmetro
spark.sql(
f"CREATE TABLE IF NOT EXISTS {catalog_name}.rescue_b.users (id INT, name STRING)"
)
spark.sql(
f"INSERT OVERWRITE {catalog_name}.rescue_b.users VALUES (1, 'Alice'), (2, 'Bob')"
)
spark.sql(
f"INSERT INTO {catalog_name}.rescue_b.users VALUES ({user_id}, '{user_name}')"
)

# COMMAND ----------
# DBTITLE 1,Lê os dados inseridos
result_df = spark.sql(f"SELECT * FROM {catalog_name}.rescue_b.users ORDER BY id")
display(result_df)
Loading