@@ -37,11 +37,21 @@ public DatabaseQueryTools(@Qualifier("clickhouseDataSource") DataSource dataSour
3737 + "Use this to retrieve cancer genomics data including studies, patients, samples, mutations, and clinical information. "
3838 + "Only SELECT queries are allowed for security. "
3939 + "The database contains base tables and optimized derived tables (*_derived). "
40+ + "CRITICAL - ClickHouse Syntax Requirements: "
41+ + "1. Column names are CASE-SENSITIVE and stored in LOWERCASE (use 'cancer_study_id' NOT 'CANCER_STUDY_ID'). "
42+ + "2. Table names are lowercase (use 'cancer_study' NOT 'CANCER_STUDY'). "
43+ + "3. Always use lowercase in WHERE, JOIN, and SELECT clauses. "
44+ + "4. If unsure about column names, use 'SELECT * FROM table LIMIT 1' first to see actual column names. "
4045 + "Returns formatted query results with clear explanations." )
4146 public String queryDatabase (
4247 @ ToolParam (
4348 description =
44- "SQL SELECT query to execute. Example: 'SELECT * FROM cancer_study LIMIT 10'" )
49+ "SQL SELECT query to execute using ClickHouse syntax. "
50+ + "IMPORTANT: Use lowercase for ALL column and table names! "
51+ + "Examples: "
52+ + "'SELECT * FROM cancer_study LIMIT 10' (discover columns), "
53+ + "'SELECT cancer_study_id, name, type_of_cancer_id FROM cancer_study LIMIT 5' (specific columns), "
54+ + "'SELECT p.stable_id, s.stable_id FROM patient p JOIN sample s ON p.internal_id = s.patient_id LIMIT 5' (with JOIN)" )
4555 String query ,
4656 @ ToolParam (
4757 description = "Maximum number of rows to return (optional, default: 100, max: 1000)" ,
@@ -96,20 +106,26 @@ public String queryDatabase(
96106 if (errorMsg .contains ("Table" ) && errorMsg .contains ("doesn't exist" )) {
97107 return "Error: The specified table doesn't exist. "
98108 + "Use the listTables tool to see available tables, "
99- + "or check the table name spelling." ;
100- } else if (errorMsg .contains ("Unknown column" )) {
109+ + "or check the table name spelling (remember: use lowercase) ." ;
110+ } else if (errorMsg .contains ("Unknown column" ) || errorMsg . contains ( "Unknown identifier" ) ) {
101111 return "Error: Unknown column in the query. "
102- + "Use the getTableSchema tool to see available columns for the table." ;
103- } else if (errorMsg .contains ("syntax" )) {
104- return "Error: SQL syntax error. Please check the query structure. "
112+ + "ClickHouse column names are CASE-SENSITIVE and stored in lowercase! "
113+ + "Use 'SELECT * FROM table LIMIT 1' to see actual column names, "
114+ + "or use the getTableSchema tool. "
115+ + "Example: use 'cancer_study_id' instead of 'CANCER_STUDY_ID'." ;
116+ } else if (errorMsg .contains ("syntax" ) || errorMsg .contains ("bad SQL grammar" )) {
117+ return "Error: SQL syntax error. "
118+ + "Common issue: ClickHouse requires lowercase column names! "
119+ + "Use 'SELECT * FROM table LIMIT 1' first to see the correct column names. "
105120 + "Error details: "
106121 + errorMsg ;
107122 }
108123 }
109124
110125 return "Error executing query: "
111126 + errorMsg
112- + "\n Tip: Use getTableSchema to verify table structure before querying." ;
127+ + "\n \n ClickHouse Reminder: Column names are case-sensitive and stored in lowercase. "
128+ + "Try 'SELECT *' first to see actual column names." ;
113129 }
114130 }
115131
0 commit comments