File tree Expand file tree Collapse file tree 1 file changed +49
-0
lines changed
mindsdb_sql_parser/ast/mindsdb Expand file tree Collapse file tree 1 file changed +49
-0
lines changed Original file line number Diff line number Diff line change 1+ from mindsdb_sql_parser .ast .base import ASTNode
2+ from mindsdb_sql_parser .utils import indent
3+ from mindsdb_sql_parser .ast .select .identifier import Identifier
4+
5+
6+ class AlterView (ASTNode ):
7+ """
8+ Alter a view.
9+ """
10+ def __init__ (
11+ self ,
12+ name : Identifier ,
13+ query_str : str ,
14+ from_table : Identifier = None ,
15+ * args ,
16+ ** kwargs
17+ ):
18+ """
19+ Args:
20+ name: Identifier -- name of the view to alter.
21+ query_str: str -- the new query string for the view.
22+ from_table: Identifier -- optional table to alter the view from.
23+ """
24+ super ().__init__ (* args , ** kwargs )
25+ self .name = name
26+ self .query_str = query_str
27+ self .from_table = from_table
28+
29+ def to_tree (self , * args , level = 0 , ** kwargs ):
30+ ind = indent (level )
31+ ind1 = indent (level + 1 )
32+
33+ name_str = f'\n { ind1 } name={ self .name .to_string ()} ,'
34+ from_table_str = f'\n { ind1 } from_table=\n { self .from_table .to_tree (level = level + 2 )} ,' if self .from_table else ''
35+ query_str = f'\n { ind1 } query="{ self .query_str } "'
36+
37+ out_str = f'{ ind } AlterView(' \
38+ f'{ name_str } ' \
39+ f'{ query_str } ' \
40+ f'{ from_table_str } ' \
41+ f'\n { ind } )'
42+ return out_str
43+
44+ def get_string (self , * args , ** kwargs ):
45+ from_str = f' FROM { str (self .from_table )} ' if self .from_table else ''
46+
47+ out_str = f'ALTER VIEW { self .name .to_string ()} AS ( { self .query_str } ){ from_str } '
48+
49+ return out_str
You can’t perform that action at this time.
0 commit comments