Coverage for mindsdb / integrations / utilities / handlers / query_utilities / base_query_utilities.py: 0%
24 statements
« prev ^ index » next coverage.py v7.13.1, created at 2026-01-21 00:36 +0000
« prev ^ index » next coverage.py v7.13.1, created at 2026-01-21 00:36 +0000
1import pandas as pd
2from typing import Text, List
3from mindsdb_sql_parser import ast
4from abc import ABC, abstractmethod
5from mindsdb.integrations.utilities.sql_utils import extract_comparison_conditions, filter_dataframe
8class BaseQueryParser(ABC):
9 """
10 Parses a SQL query into its component parts.
12 Parameters
13 ----------
14 query : ast
15 Given SQL query.
16 """
18 def __init__(self, query: ast):
19 self.query = query
21 @abstractmethod
22 def parse_query(self):
23 """
24 Parses a SQL statement into its components.
25 """
26 pass
28 def parse_where_clause(self) -> List[List[Text]]:
29 """
30 Parses the WHERE clause of the query.
31 """
32 where_conditions = extract_comparison_conditions(self.query.where)
33 return where_conditions
36class BaseQueryExecutor():
37 """
38 Executes a SQL query.
40 Parameters
41 ----------
42 query : ast
43 Given SQL query.
44 """
46 def __init__(self, df: pd.DataFrame, where_conditions: List[List[Text]]):
47 self.df = df
48 self.where_conditions = where_conditions
50 def execute_query(self):
51 """
52 Executes the SQL query.
53 """
54 self.execute_where_clause()
56 return self.df
58 def execute_where_clause(self):
59 """
60 Executes the where clause of the query.
61 """
62 if len(self.where_conditions) > 0:
63 self.df = filter_dataframe(self.df, self.where_conditions)