Repository: mindsdb/mindsdb

Issue:
Add support of `DROP predictor` sql statement



Discussion:

Resolving patch:
diff --git a/mindsdb/api/mysql/mysql_proxy/classes/sql_statement_parser.py b/mindsdb/api/mysql/mysql_proxy/classes/sql_statement_parser.py
--- a/mindsdb/api/mysql/mysql_proxy/classes/sql_statement_parser.py
+++ b/mindsdb/api/mysql/mysql_proxy/classes/sql_statement_parser.py
@@ -76,6 +76,8 @@ def __init__(self, text, init_parse=True):
                 self._struct = self.parse_as_insert()
             elif self._keyword == 'delete':
                 self._struct = self.parse_as_delete()
+            elif self._keyword == 'drop':
+                self._struct = None
             elif self._keyword == 'create_predictor':
                 self._struct = self.parse_as_create_predictor()
             elif self._keyword in 'create_ai_table':
@@ -139,12 +141,13 @@ def get_keyword(sql):
             rollback
             commit
             explain
+            drop
 
             create_predictor
             create_ai_table
         '''
-        START, SET, USE, SHOW, DELETE, INSERT, UPDATE, ALTER, SELECT, ROLLBACK, COMMIT, EXPLAIN, CREATE, AI, TABLE, PREDICTOR, VIEW = map(
-            CaselessKeyword, "START SET USE SHOW DELETE INSERT UPDATE ALTER SELECT ROLLBACK COMMIT EXPLAIN CREATE AI TABLE PREDICTOR VIEW".split()
+        START, SET, USE, SHOW, DELETE, INSERT, UPDATE, ALTER, SELECT, ROLLBACK, COMMIT, EXPLAIN, CREATE, AI, TABLE, PREDICTOR, VIEW, DROP = map(
+            CaselessKeyword, "START SET USE SHOW DELETE INSERT UPDATE ALTER SELECT ROLLBACK COMMIT EXPLAIN CREATE AI TABLE PREDICTOR VIEW DROP".split()
         )
         CREATE_PREDICTOR = CREATE + PREDICTOR
         CREATE_AI_TABLE = CREATE + AI + TABLE
@@ -156,7 +159,7 @@ def get_keyword(sql):
             | UPDATE | ALTER | SELECT
             | ROLLBACK | COMMIT | EXPLAIN
             | CREATE_PREDICTOR | CREATE_AI_TABLE
-            | CREATE_VIEW
+            | CREATE_VIEW | DROP
         )('keyword')
 
         r = expr.parseString(sql)
diff --git a/mindsdb/api/mysql/mysql_proxy/mysql_proxy.py b/mindsdb/api/mysql/mysql_proxy/mysql_proxy.py
--- a/mindsdb/api/mysql/mysql_proxy/mysql_proxy.py
+++ b/mindsdb/api/mysql/mysql_proxy/mysql_proxy.py
@@ -43,6 +43,7 @@
     Set,
 )
 from mindsdb_sql.parser.dialects.mysql import Variable
+from mindsdb_sql.parser.dialects.mindsdb import DropPredictor, DropIntegration
 
 from mindsdb.utilities.wizards import make_ssl_cert
 from mindsdb.utilities.config import Config
@@ -991,7 +992,13 @@ def query_answer(self, sql):
                 statement = parse_sql('set autocommit')
             statement.category = 'error'
 
-        if isinstance(statement, Show) or keyword == 'show':
+        if isinstance(statement, DropPredictor):
+            predictor_name = statement.name.parts[-1]
+            self.session.datahub['mindsdb'].delete_predictor(predictor_name)
+            self.packet(OkPacket).send()
+        elif isinstance(statement, DropIntegration):
+            raise Exception('Not ready')
+        elif isinstance(statement, Show) or keyword == 'show':
             sql_category = statement.category.lower()
             condition = statement.condition.lower() if isinstance(statement.condition, str) else statement.condition
             expression = statement.expression
@@ -2097,7 +2104,7 @@ def handle(self):
             try:
                 if p.type.value == COMMANDS.COM_QUERY:
                     sql = self.decode_utf(p.sql.value)
-                    sql = SqlStatementParser(sql).sql
+                    sql = SqlStatementParser.clear_sql(sql)
                     log.debug(f'COM_QUERY: {sql}')
                     self.query_answer(sql)
                 elif p.type.value == COMMANDS.COM_STMT_PREPARE:


Test patch: