Instructions
Phase 1: Initial Setup & Discovery
- •Read the Task: Use
filesystem-read_fileto read the task file (e.g.,task.md) to understand the analytical questions and required output format. - •Inspect Kubernetes Resources: Use
k8s-kubectl_getto list all resources in the target namespace (e.g.,data). Identify the databaseService(e.g.,mysql-f1) and its correspondingPod. - •Establish Database Connection: Use
k8s-port_forwardto create a persistent port forward from a local port (e.g.,30124) to the database service's target port (e.g.,3306). Note theportForwardIdto keep it alive. - •List Workspace Files: Use
filesystem-list_directoryto identify any template or input files in the workspace.
Phase 2: Database Schema Exploration
- •Connect and Explore: Use
local-python-executeto run a Python script that:- •Connects to the forwarded database using provided credentials (host=
127.0.0.1, port=[LOCAL_PORT]). - •Lists all tables to understand the data structure.
- •Examines the schema of key tables relevant to the task (e.g.,
drivers,constructors,results,races,standingstables).
- •Connects to the forwarded database using provided credentials (host=
Phase 3: Query Execution & Analysis
- •Develop and Test Queries: Based on the task requirements, craft SQL queries within
local-python-executeblocks. Test them iteratively to ensure correctness.- •For ranking/aggregation tasks (e.g., "highest points per year"), join
races,standings, and dimension tables (drivers,constructors). Use window functions or subqueries withGROUP BYandMAX(). - •For complex conditional logic (e.g., "same constructor in first and last race"), use Common Table Expressions (CTEs) to break down the problem: filter by date/year, calculate first/last race per driver-season, count distinct rounds, and join on constructor ID.
- •For ranking/aggregation tasks (e.g., "highest points per year"), join
- •Validate Results: Check the row count and sample data of query results for logical consistency before writing to file.
Phase 4: Report Generation & Cleanup
- •Write Results to CSV: Use
local-python-executewith thecsvmodule to write the final query results to CSV files with the exact names specified in the task (e.g.,results_1.csv,results_2.csv). Ensure headers match the template format. - •Remove Template Files: Use
local-python-executewithos.remove()to delete any provided template files from the workspace as instructed. - •Verify Output: Use
filesystem-read_multiple_filesto confirm the final CSV files exist and contain the expected data. - •Finalize: The port forward started in Step 3 should remain active. Use
local-claim_doneto signal task completion.