execute_hg_select_sql_with_serverless
Execute SELECT SQL queries on Hologres databases using serverless computing resources to handle memory-intensive operations and avoid query memory limitations.
Instructions
Use Serverless Computing resources to execute SELECT SQL to query data in Hologres database. When the error like "Total memory used by all existing queries exceeded memory limitation" occurs during execute_hg_select_sql execution, you can re-execute the SQL with the tool execute_hg_select_sql_with_serverless.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| query | Yes | The (SELECT) SQL query to execute with serverless computing in Hologres database |
Implementation Reference
- Specific handler branch in call_tool that extracts and validates the SQL query, ensures it's a SELECT statement, and sets the serverless flag for execution.elif name == "execute_hg_select_sql_with_serverless": query = arguments.get("query") if not query: raise ValueError("Query is required") if not query.strip().upper().startswith("SELECT"): raise ValueError("Query must be a SELECT statement") # 修改 serverless computing 设置方式 serverless = True
- Input schema definition for the tool, specifying a required 'query' string parameter.inputSchema={ "type": "object", "properties": { "query": { "type": "string", "description": "The (SELECT) SQL query to execute with serverless computing in Hologres database" } }, "required": ["query"] }
- src/hologres_mcp_server/server.py:362-375 (registration)Tool registration in the list_tools() function, including name, description, and input schema.Tool( name="execute_hg_select_sql_with_serverless", description="Use Serverless Computing resources to execute SELECT SQL to query data in Hologres database. When the error like \"Total memory used by all existing queries exceeded memory limitation\" occurs during execute_hg_select_sql execution, you can re-execute the SQL with the tool execute_hg_select_sql_with_serverless.", inputSchema={ "type": "object", "properties": { "query": { "type": "string", "description": "The (SELECT) SQL query to execute with serverless computing in Hologres database" } }, "required": ["query"] } ),
- Core helper function that connects to the database, sets the serverless computing resource if specified, executes the SQL query, and formats the results or errors.def handle_call_tool(tool_name, query, serverless = False): """Handle callTool method.""" config = get_db_config() try: with connect_with_retry() as conn: with conn.cursor() as cursor: # 特殊处理 serverless computing 查询 if serverless: cursor.execute("set hg_computing_resource='serverless'") # Execute the query cursor.execute(query) # 特殊处理 ANALYZE 命令 if tool_name == "gather_hg_table_statistics": return f"Successfully {query}" # 处理其他有返回结果的查询 if cursor.description: # SELECT query columns = [desc[0] for desc in cursor.description] rows = cursor.fetchall() result = [",".join(map(str, row)) for row in rows] return "\n".join([",".join(columns)] + result) elif tool_name == "execute_dml_sql": # Non-SELECT query row_count = cursor.rowcount return f"Query executed successfully. {row_count} rows affected." else: return "Query executed successfully" except Exception as e: return f"Error executing query: {str(e)}"