armanddemasson commited on
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
- con = duckdb.connect()
44
- HF_TTD_TOKEN = os.getenv("HF_TTD_TOKEN")
45
- con.execute(f"""CREATE SECRET hf_token (
46
- TYPE huggingface,
47
- TOKEN '{HF_TTD_TOKEN}'
48
- );""")
49
- results = con.execute(sql_query).fetchdf()
50
- # return fetched data
51
- return results
 
 
 
 
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()