11from mindsdb_sql_parser .ast .base import ASTNode
2- from mindsdb_sql_parser .utils import indent
2+ from mindsdb_sql_parser .utils import indent , dump_using_dict
33from mindsdb_sql_parser .ast .select .identifier import Identifier
44
55
@@ -12,6 +12,7 @@ def __init__(
1212 name : Identifier ,
1313 query_str : str ,
1414 from_table : Identifier = None ,
15+ using : dict = None ,
1516 * args ,
1617 ** kwargs
1718 ):
@@ -20,11 +21,13 @@ def __init__(
2021 name: Identifier -- name of the view to alter.
2122 query_str: str -- the new query string for the view.
2223 from_table: Identifier -- optional table to alter the view from.
24+ using: dict -- optional USING parameters.
2325 """
2426 super ().__init__ (* args , ** kwargs )
2527 self .name = name
2628 self .query_str = query_str
2729 self .from_table = from_table
30+ self .using = using
2831
2932 def to_tree (self , * args , level = 0 , ** kwargs ):
3033 ind = indent (level )
@@ -33,17 +36,22 @@ def to_tree(self, *args, level=0, **kwargs):
3336 name_str = f'\n { ind1 } name={ self .name .to_string ()} ,'
3437 from_table_str = f'\n { ind1 } from_table=\n { self .from_table .to_tree (level = level + 2 )} ,' if self .from_table else ''
3538 query_str = f'\n { ind1 } query="{ self .query_str } "'
39+ using_str = f'\n { ind1 } using={ self .using } ,' if self .using else ''
3640
3741 out_str = f'{ ind } AlterView(' \
3842 f'{ name_str } ' \
3943 f'{ query_str } ' \
4044 f'{ from_table_str } ' \
45+ f'{ using_str } ' \
4146 f'\n { ind } )'
4247 return out_str
4348
4449 def get_string (self , * args , ** kwargs ):
4550 from_str = f' FROM { str (self .from_table )} ' if self .from_table else ''
51+ using_str = ''
52+ if self .using :
53+ using_str = f'USING { dump_using_dict (self .using )} '
4654
47- out_str = f'ALTER VIEW { self .name .to_string ()} { from_str } AS ( { self .query_str } )'
55+ out_str = f'ALTER VIEW { self .name .to_string ()} { from_str } AS ( { self .query_str } ){ using_str } '
4856
4957 return out_str
0 commit comments