Skip to content
Merged
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
2 changes: 1 addition & 1 deletion src/drs/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ async def delete_project(self, project_id: str) -> dict:

async def submit_sql(self, sql: str, context: list[str] | None = None) -> dict:
"""Submit a SQL query. Returns job metadata including job_id."""
body: dict[str, Any] = {"sql": sql}
body: dict[str, Any] = {"sql": f"/* dremio-cli: submitter=cli */ {sql}"}
if context:
body["context"] = context
return await self._post(self._v0("/sql"), json=body)
Expand Down
39 changes: 39 additions & 0 deletions tests/test_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

from __future__ import annotations

import httpx
import pytest

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

def test_content_type(self, client: DremioClient) -> None:
assert client._client.headers["content-type"] == "application/json"


class TestSQLBreadcrumb:
@pytest.mark.asyncio
async def test_submit_sql_prepends_breadcrumb(self, client: DremioClient) -> None:
"""SQL submitted via the client must carry the dremio-cli breadcrumb comment."""
captured: dict = {}

async def _capture(request: httpx.Request) -> httpx.Response:
import json

captured["body"] = json.loads(request.content)
return httpx.Response(200, json={"id": "job-1"})

client._client = httpx.AsyncClient(transport=httpx.MockTransport(_capture))

await client.submit_sql("SELECT 1")

assert captured["body"]["sql"] == "/* dremio-cli: submitter=cli */ SELECT 1"

@pytest.mark.asyncio
async def test_submit_sql_breadcrumb_with_context(self, client: DremioClient) -> None:
"""Breadcrumb should be present even when a schema context is provided."""
captured: dict = {}

async def _capture(request: httpx.Request) -> httpx.Response:
import json

captured["body"] = json.loads(request.content)
return httpx.Response(200, json={"id": "job-2"})

client._client = httpx.AsyncClient(transport=httpx.MockTransport(_capture))

await client.submit_sql("SELECT * FROM orders", context=["myspace"])

assert captured["body"]["sql"].startswith("/* dremio-cli: submitter=cli */")
assert "SELECT * FROM orders" in captured["body"]["sql"]
assert captured["body"]["context"] == ["myspace"]
Loading