Commit
·
14c3e34
1
Parent(s):
4abc28e
feat: enhanced query execution with an error management
Browse files
climateqa/engine/talk_to_data/query.py
CHANGED
|
@@ -40,15 +40,19 @@ async def execute_sql_query(sql_query: str) -> pd.DataFrame:
|
|
| 40 |
"""
|
| 41 |
def _execute_query():
|
| 42 |
# Execute the query
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
|
| 46 |
-
|
| 47 |
-
|
| 48 |
-
|
| 49 |
-
|
| 50 |
-
|
| 51 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 52 |
|
| 53 |
# Run the query in a thread pool to avoid blocking
|
| 54 |
loop = asyncio.get_event_loop()
|
|
|
|
| 40 |
"""
|
| 41 |
def _execute_query():
|
| 42 |
# Execute the query
|
| 43 |
+
try:
|
| 44 |
+
con = duckdb.connect()
|
| 45 |
+
HF_TTD_TOKEN = os.getenv("HF_TTD_TOKEN")
|
| 46 |
+
con.execute(f"""CREATE SECRET hf_token (
|
| 47 |
+
TYPE huggingface,
|
| 48 |
+
TOKEN '{HF_TTD_TOKEN}'
|
| 49 |
+
);""")
|
| 50 |
+
results = con.execute(sql_query).fetchdf()
|
| 51 |
+
except Exception as e:
|
| 52 |
+
print(f"Error during tehe execution of the query : {sql_query}\n Error : {e}")
|
| 53 |
+
finally:
|
| 54 |
+
# return fetched data
|
| 55 |
+
return results
|
| 56 |
|
| 57 |
# Run the query in a thread pool to avoid blocking
|
| 58 |
loop = asyncio.get_event_loop()
|