Skip to content

Commit 2532cb2

Browse files
feat: prepend breadcrumb comment to all SQL queries (DX-117497) (#9)
## Summary - All SQL submitted through `dremio-cli` now carries a leading breadcrumb comment: `/* dremio-cli: submitter=cli */ <user SQL>` - Enables backend query attribution — the Jobs service can detect CLI-originated queries, consistent with how `dremio-mcp` uses `/* dremioai: submitter=agent */` - Applied in the single `submit_sql()` method in `client.py`, so every command that runs SQL (query, job, schema, folder, reflection) gets it automatically ## Test plan - [x] 2 new tests in `test_client.py` verify breadcrumb is prepended (with and without context) - [x] Full test suite passes (140/140) - [ ] Manual: run `dremio query run "SELECT 1"` against Dremio Cloud and verify the breadcrumb appears in the job's SQL via `sys.project.history.jobs` JIRA: [DX-117497](https://dremio.atlassian.net/browse/DX-117497) 🤖 Generated with [Claude Code](https://claude.com/claude-code) [DX-117497]: https://dremio.atlassian.net/browse/DX-117497?atlOrigin=eyJpIjoiNWRkNTljNzYxNjVmNDY3MDlhMDU5Y2ZhYzA5YTRkZjUiLCJwIjoiZ2l0aHViLWNvbS1KU1cifQ Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 85f20fa commit 2532cb2

2 files changed

Lines changed: 40 additions & 1 deletion

File tree

src/drs/client.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ async def delete_project(self, project_id: str) -> dict:
164164

165165
async def submit_sql(self, sql: str, context: list[str] | None = None) -> dict:
166166
"""Submit a SQL query. Returns job metadata including job_id."""
167-
body: dict[str, Any] = {"sql": sql}
167+
body: dict[str, Any] = {"sql": f"/* dremio-cli: submitter=cli */ {sql}"}
168168
if context:
169169
body["context"] = context
170170
return await self._post(self._v0("/sql"), json=body)

tests/test_client.py

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717

1818
from __future__ import annotations
1919

20+
import httpx
2021
import pytest
2122

2223
from drs.auth import DrsConfig
@@ -100,3 +101,41 @@ def test_auth_header(self, client: DremioClient) -> None:
100101

101102
def test_content_type(self, client: DremioClient) -> None:
102103
assert client._client.headers["content-type"] == "application/json"
104+
105+
106+
class TestSQLBreadcrumb:
107+
@pytest.mark.asyncio
108+
async def test_submit_sql_prepends_breadcrumb(self, client: DremioClient) -> None:
109+
"""SQL submitted via the client must carry the dremio-cli breadcrumb comment."""
110+
captured: dict = {}
111+
112+
async def _capture(request: httpx.Request) -> httpx.Response:
113+
import json
114+
115+
captured["body"] = json.loads(request.content)
116+
return httpx.Response(200, json={"id": "job-1"})
117+
118+
client._client = httpx.AsyncClient(transport=httpx.MockTransport(_capture))
119+
120+
await client.submit_sql("SELECT 1")
121+
122+
assert captured["body"]["sql"] == "/* dremio-cli: submitter=cli */ SELECT 1"
123+
124+
@pytest.mark.asyncio
125+
async def test_submit_sql_breadcrumb_with_context(self, client: DremioClient) -> None:
126+
"""Breadcrumb should be present even when a schema context is provided."""
127+
captured: dict = {}
128+
129+
async def _capture(request: httpx.Request) -> httpx.Response:
130+
import json
131+
132+
captured["body"] = json.loads(request.content)
133+
return httpx.Response(200, json={"id": "job-2"})
134+
135+
client._client = httpx.AsyncClient(transport=httpx.MockTransport(_capture))
136+
137+
await client.submit_sql("SELECT * FROM orders", context=["myspace"])
138+
139+
assert captured["body"]["sql"].startswith("/* dremio-cli: submitter=cli */")
140+
assert "SELECT * FROM orders" in captured["body"]["sql"]
141+
assert captured["body"]["context"] == ["myspace"]

0 commit comments

Comments
 (0)