Spaces:
Sleeping
Sleeping
| def execution_agent(state): | |
| """Executes the optimized SQL query against BigQuery.""" | |
| query = state.get("optimized_sql", "").strip() | |
| client = state["client"] | |
| if not query: | |
| return {"execution_result": {"error": "No SQL query to execute."}} | |
| print(f"DEBUG: Final SQL Query before execution:\n{query}") | |
| if client is None: | |
| return {"execution_result": {"error": "Failed to connect to BigQuery."}} | |
| try: | |
| # Execute the query | |
| query_job = client.query(query) | |
| results = query_job.result() # Wait for query to complete | |
| # Convert results to a list of tuples (similar to SQLite format) | |
| rows = [] | |
| for row in results: | |
| # Convert each row to a tuple of values | |
| row_values = tuple(row.values()) | |
| rows.append(row_values) | |
| if not rows: | |
| return {"execution_result": {"error": "Query executed successfully but returned no results."}} | |
| return {"execution_result": rows} | |
| except Exception as e: | |
| return {"execution_result": {"error": str(e)}} |