Skip to content

feat: render SDK SQL through the Bruin CLI - #10

Draft
sabrikaragonen wants to merge 1 commit into
mainfrom
budapest-v2/bruin-sdk-cli-sql-render-ekle
Draft

sabrikaragonen wants to merge 1 commit into
mainfrom
budapest-v2/bruin-sdk-cli-sql-render-ekle

Conversation

@sabrikaragonen

Copy link
Copy Markdown
Contributor

Both bruin.query() and get_connection(...).query() now render SQL through the Bruin CLI before sending it to the existing Python database client. This enables Jinja and environment schema prefixes while preserving the selected connection, query annotations, and existing DataFrame/None behavior. The CLI only supplies SQL; database results stay in Python.

The shared _run_cli() helper handles binary selection (BRUIN_PATH or PATH), shell-free subprocess execution, stdin, environment forwarding, timeouts, and process errors. Render failures raise QueryError before client initialization, with no fallback to the original SQL. Documentation and tests cover the process boundary and query execution.

Pending CLI integration

This PR is prepared for the separate Bruin CLI render implementation. The command contract below is provisional and has not been validated against that implementation:

bruin render --stdin --connection NAME --raw-query --output json
stdin: query SQL
stdout: {"query": "rendered SQL"}

The SDK also passes --environment, start/end dates, --full-refresh, and typed --var KEY=JSON values when present. It inherits the full environment and working directory, overriding only the child's BRUIN_CONNECTION with the selected name.

For the CLI agent: align _render.py, its tests, and README with the final command/response contract; verify Jinja, schema prefixes, selected connection/environment, and inherited run context against a real CLI build. Ensure query-only rendering excludes materialization and asset hooks. Identify the compatible CLI release before merging/releasing this SDK change. No CLI code is changed here.

Validation

  • uv run ruff check . and uv run ruff format --check . passed.
  • uv run python -m pytest tests/ -q: 256 passed, 13 skipped.
  • The render process test uses a contract stub and a real SQLite client; it does not establish compatibility with the pending CLI implementation.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant