Repository navigation
fix(databricks): keep result columns in schema order - #9708
Vidit Ostwal (Vidit-Ostwal) merged 1 commit into
Conversation
Strix Security ReviewWarning This pull request has 4 commits after the last Strix review ( ✅ No open security findings. PR summary: Fixes result-column ordering in `DatabricksQueryTool` by tracking column names in an ordered list seeded from the query's schema instead of a set, so headers follow the SELECT list and generated `Column_N` names are appended at the end. Adds two tests using a fake Databricks workspace client. Review summaryReviewed the result-column ordering fix in Review 1 on this PR · Reviewed by Strix |
The result normalizer collected every column name in a set and rebuilt each row from that set. Column order in the formatted table therefore depended on set iteration order, so the same query could return columns in a different order from run to run and never matched the SELECT list. Track the columns as an ordered list seeded from the result schema, and append generated names for extra values after the schema columns.
29b8b1e to
dbdfbc4
Compare
Vidit Ostwal (Vidit-Ostwal)
left a comment
There was a problem hiding this comment.
Thanks, this is a clean, minimal fix: an ordered all_columns list makes the table columns follow the schema, with Column_N names appended at the end.
I checked the tests against the code before and after your change. Both new tests in tests/tools/test_databricks_query_tool.py fail without your change and pass with it. A separate 12-column ordering test behaves the same way.
Optional follow-up: add a test for the result.result.data fallback path, which your change at line ~760 also covers.
Fixes #9703
Summary
DatabricksQueryToolrebuilt each result row from asetof column names and formatted the table from the first row's key order. The rendered columns were therefore ordered by set iteration order: they changed from process to process and never followed the query'sSELECTlist. GeneratedColumn_Nnames for extra values also landed in arbitrary positions.This change tracks the columns in an ordered list seeded from the result schema, appending generated names after the schema columns.
Changes
lib/crewai-tools/src/crewai_tools/tools/databricks_query_tool/databricks_query_tool.pyall_columns = list(columns)and append generatedColumn_Nnames instead of adding them to a set.lib/crewai-tools/tests/tools/test_databricks_query_tool.pyColumn_5at the end.Verification
pytest lib/crewai-tools/tests/tools/test_databricks_query_tool.py→2 passed.databricks_query_tool.py(test file kept):2 failed; the observed header wasgamma | alpha | delta | beta | epsilonfor schema orderalpha, beta, gamma, delta, epsilon.AI assistance
I used an AI coding agent to investigate, implement, and test this change, and reviewed its results. Per CONTRIBUTING.md, please apply the
llm-generatedlabel; external contributors cannot add it with my current permissions.