kaqing 2.0.102__py3-none-any.whl → 2.0.103__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of kaqing might be problematic. Click here for more details.
- adam/batch.py +0 -14
- adam/commands/audit/audit.py +2 -7
- adam/commands/cd.py +8 -8
- adam/commands/commands_utils.py +1 -2
- adam/commands/cql/cql_completions.py +4 -4
- adam/commands/cql/cql_utils.py +1 -1
- adam/commands/cql/cqlsh.py +1 -1
- adam/commands/deploy/deploy_pg_agent.py +2 -2
- adam/commands/deploy/undeploy_pg_agent.py +2 -2
- adam/commands/ls.py +12 -12
- adam/commands/nodetool.py +1 -1
- adam/commands/postgres/postgres.py +3 -3
- adam/commands/postgres/{postgres_session.py → postgres_context.py} +26 -27
- adam/commands/postgres/postgres_utils.py +5 -5
- adam/commands/postgres/psql_completions.py +1 -1
- adam/commands/preview_table.py +8 -27
- adam/commands/pwd.py +2 -2
- adam/repl.py +3 -3
- adam/repl_commands.py +1 -5
- adam/repl_state.py +2 -2
- adam/sql/automata_completer.py +63 -0
- adam/sql/sql_completer.py +37 -73
- adam/sql/sql_state_machine.py +434 -0
- adam/sql/state_machine.py +52 -421
- adam/sql/term_completer.py +3 -0
- adam/utils_k8s/pods.py +2 -2
- adam/version.py +1 -1
- {kaqing-2.0.102.dist-info → kaqing-2.0.103.dist-info}/METADATA +1 -1
- {kaqing-2.0.102.dist-info → kaqing-2.0.103.dist-info}/RECORD +32 -40
- adam/commands/audit/audit_table_completer.py +0 -9
- adam/commands/cql/cql_table_completer.py +0 -8
- adam/commands/describe/__init__.py +0 -0
- adam/commands/describe/describe.py +0 -61
- adam/commands/describe/describe_keyspace.py +0 -58
- adam/commands/describe/describe_keyspaces.py +0 -46
- adam/commands/describe/describe_schema.py +0 -46
- adam/commands/describe/describe_table.py +0 -57
- adam/commands/describe/describe_tables.py +0 -46
- adam/commands/postgres/psql_table_completer.py +0 -11
- {kaqing-2.0.102.dist-info → kaqing-2.0.103.dist-info}/WHEEL +0 -0
- {kaqing-2.0.102.dist-info → kaqing-2.0.103.dist-info}/entry_points.txt +0 -0
- {kaqing-2.0.102.dist-info → kaqing-2.0.103.dist-info}/top_level.txt +0 -0
adam/sql/state_machine.py
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
from abc import abstractmethod
|
|
1
2
|
from sqlparse.sql import Token
|
|
2
3
|
from sqlparse import tokens as T
|
|
3
4
|
|
|
@@ -5,402 +6,6 @@ __all__ = [
|
|
|
5
6
|
"StateMachine",
|
|
6
7
|
]
|
|
7
8
|
|
|
8
|
-
class SqlSpec:
|
|
9
|
-
SPEC = [
|
|
10
|
-
# <select_statement> ::= SELECT <select_list>
|
|
11
|
-
# FROM <table_expression>
|
|
12
|
-
# [WHERE <search_condition>]
|
|
13
|
-
# [<group_by_clause>]
|
|
14
|
-
# [<having_clause>]
|
|
15
|
-
# [<order_by_clause>]
|
|
16
|
-
# [<limit_clause>]
|
|
17
|
-
|
|
18
|
-
# <search_condition> ::= <boolean_term>
|
|
19
|
-
# | <search_condition> OR <boolean_term>
|
|
20
|
-
|
|
21
|
-
# <boolean_term> ::= <boolean_factor>
|
|
22
|
-
# | <boolean_term> AND <boolean_factor>
|
|
23
|
-
|
|
24
|
-
# <boolean_factor> ::= [NOT] <predicate>
|
|
25
|
-
# | ([NOT] <search_condition>)
|
|
26
|
-
|
|
27
|
-
# <predicate> ::= <comparison_predicate>
|
|
28
|
-
# | <between_predicate>
|
|
29
|
-
# | <in_predicate>
|
|
30
|
-
# | <like_predicate>
|
|
31
|
-
# | <null_predicate>
|
|
32
|
-
# | <exists_predicate>
|
|
33
|
-
# | <quantified_predicate>
|
|
34
|
-
# | <unique_predicate>
|
|
35
|
-
# | <match_predicate>
|
|
36
|
-
# | <overlaps_predicate>
|
|
37
|
-
# | <distinct_predicate>
|
|
38
|
-
# | <member_predicate>
|
|
39
|
-
# | <submultiset_predicate>
|
|
40
|
-
# | <set_predicate>
|
|
41
|
-
|
|
42
|
-
# <comparison_predicate> ::= <row_value_expression> <comparison_operator> <row_value_expression>
|
|
43
|
-
# <comparison_operator> ::= '=' | '<>' | '<' | '<=' | '>' | '>='
|
|
44
|
-
|
|
45
|
-
# <row_value_expression> ::= <value_expression>
|
|
46
|
-
# | (<value_expression> [ { <comma> <value_expression> }... ])
|
|
47
|
-
|
|
48
|
-
# <value_expression> ::= <numeric_value_expression>
|
|
49
|
-
# | <string_value_expression>
|
|
50
|
-
# | <datetime_value_expression>
|
|
51
|
-
# | <interval_value_expression>
|
|
52
|
-
# | <boolean_value_expression>
|
|
53
|
-
# | <user_defined_type_value_expression>
|
|
54
|
-
# | <reference_value_expression>
|
|
55
|
-
# | <collection_value_expression>
|
|
56
|
-
# | <row_value_constructor>
|
|
57
|
-
# | <case_expression>
|
|
58
|
-
# | <cast_expression>
|
|
59
|
-
# | <subquery>
|
|
60
|
-
# | NULL
|
|
61
|
-
# | DEFAULT
|
|
62
|
-
# | <identifier>
|
|
63
|
-
# | <literal>
|
|
64
|
-
' > select > select',
|
|
65
|
-
'select_ > name|* > select_a ^ *',
|
|
66
|
-
'select_a > , > select_a_comma_',
|
|
67
|
-
'select_a_comma_ > name|* > select_a ^ *',
|
|
68
|
-
'select_a_ > from > select_from ^ from',
|
|
69
|
-
'select_from_ > name|audit > select_from_x ^ (select,tables',
|
|
70
|
-
'- > ( > select_from_lp_',
|
|
71
|
-
'- < ) > select_from_sq',
|
|
72
|
-
'select_from_lp_ > select > select',
|
|
73
|
-
'select_from_x > , > select_from_x_comma_ ^ (select,tables',
|
|
74
|
-
'select_from_sq_ > as > select_from_x_as ^ as',
|
|
75
|
-
'select_from_x_comma_ > name > select_from_x ^ tables',
|
|
76
|
-
'select_from_x_ ^ as,where,inner join,left outer join,right outer join,full outer join,group by,order by,limit',
|
|
77
|
-
'select_from_x_as_x_ > , > select_from_x_comma_ ^ where,inner join,left outer join,right outer join,full outer join,group by,order by,limit',
|
|
78
|
-
'- > as > select_from_x_as',
|
|
79
|
-
'- > where > select_where',
|
|
80
|
-
'- > order > select_order',
|
|
81
|
-
'- > order by > select_order_by',
|
|
82
|
-
'- > limit > select_where_sc_limit',
|
|
83
|
-
'- > group > select_group',
|
|
84
|
-
'- > group by > select_group_by',
|
|
85
|
-
'- > inner > select_from_x_inner',
|
|
86
|
-
'- > inner join > select_join',
|
|
87
|
-
'- > left > select_from_x_left',
|
|
88
|
-
'- > left join > select_join',
|
|
89
|
-
'- > left outer join > select_join',
|
|
90
|
-
'- > right > select_from_x_right',
|
|
91
|
-
'- > right join > select_join',
|
|
92
|
-
'- > right outer join > select_join',
|
|
93
|
-
'- > full > select_from_x_full',
|
|
94
|
-
'- > full outer join > select_join',
|
|
95
|
-
'select_from_x_as_ > name > select_from_x_as_x ^ x,y,z',
|
|
96
|
-
'select_from_x_as_x > , > select_from_x_as_x_comma_',
|
|
97
|
-
'select_from_x_as_x_comma_ > name > select_from_x ^ tables',
|
|
98
|
-
'select_where_ > name > select_where_a ^ columns',
|
|
99
|
-
'select_where_a > name > select_where_a ^ columns,=,<,<=,>,>=,<>',
|
|
100
|
-
'- > comparison > select_where_a_op',
|
|
101
|
-
'select_where_a_ > comparison > select_where_a_op ^ =,<,<=,>,>=,<>,like,not,in',
|
|
102
|
-
'- > not > select_where_a_not',
|
|
103
|
-
'- > in > select_where_a_in',
|
|
104
|
-
'select_where_a_not_ > comparison > select_where_a_not_op ^ like,in',
|
|
105
|
-
'- > in > select_where_a_in',
|
|
106
|
-
'select_where_a_in > ( > select_where_a_in_lp_ ^ (',
|
|
107
|
-
'- < ) > select_where_sc',
|
|
108
|
-
'select_where_a_in_lp_ > name|single|num > select_where_a_in_lp_a ^ single,select',
|
|
109
|
-
'- > select > select_where_a_in_lp_select',
|
|
110
|
-
'select_where_a_in_lp_select_ > name > select_a ^ id',
|
|
111
|
-
'select_where_a_in_lp_a > , > select_where_a_in_lp_a_comma_ ^ comma,)',
|
|
112
|
-
'select_where_a_in_lp_a_comma_ > name|single|num > select_where_a_in_lp_a ^ single',
|
|
113
|
-
'select_where_a_not_op > name|single|num > select_where_sc ^ single',
|
|
114
|
-
'select_where_a_op > name|single|num > select_where_sc ^ single',
|
|
115
|
-
'select_where_sc_ > and|or > select_where ^ and,or,order by,group by,limit',
|
|
116
|
-
'- > group > select_group',
|
|
117
|
-
'- > group by > select_group_by',
|
|
118
|
-
'- > order > select_order',
|
|
119
|
-
'- > order by > select_order_by',
|
|
120
|
-
'- > limit > select_where_sc_limit',
|
|
121
|
-
'select_group_ > by > select_group_by ^ by',
|
|
122
|
-
'select_group_by_ > name > select_group_by_a ^ columns',
|
|
123
|
-
'select_group_by_a > name > select_group_by_a ^ columns',
|
|
124
|
-
'- > , > select_group_by_a_comma_ ^ columns',
|
|
125
|
-
'select_group_by_a_comma_ > name > select_group_by_a ^ columns',
|
|
126
|
-
'select_group_by_a_ > limit > select_where_sc_limit ^ limit,order by',
|
|
127
|
-
'- > order > select_order',
|
|
128
|
-
'- > order by > select_order_by',
|
|
129
|
-
'select_order_ > by > select_order_by ^ by',
|
|
130
|
-
'select_order_by_ > name > select_order_by_a ^ columns',
|
|
131
|
-
'select_order_by_a > name > select_order_by_a ^ columns',
|
|
132
|
-
'- > , > select_order_by_a_comma_',
|
|
133
|
-
'select_order_by_a_comma_ > name > select_order_by_a ^ columns',
|
|
134
|
-
'select_order_by_a_ > desc|asc > select_order_by_a_desc ^ desc,asc,limit',
|
|
135
|
-
'- > limit > select_where_sc_limit',
|
|
136
|
-
'select_order_by_a_desc > , > select_order_by_a_comma_',
|
|
137
|
-
'select_order_by_a_desc_ > limit > select_where_sc_limit ^ limit',
|
|
138
|
-
'select_where_sc_limit_ > num > select_where_sc_limit_num ^ 1',
|
|
139
|
-
'select_where_sc_limit_num_rp__ > as > select_from_x_as ^ as',
|
|
140
|
-
'select_where_x_inner_ > join > select_join',
|
|
141
|
-
'select_join_ > name > select_x_join_y ^ tables',
|
|
142
|
-
'select_from_x_left_ > join > select_join ^ outer join',
|
|
143
|
-
'- > outer > select_from_x_left_outer',
|
|
144
|
-
'select_from_x_left_outer_ > join > select_join ^ join',
|
|
145
|
-
'select_from_x_right_ > join > select_join ^ outer join',
|
|
146
|
-
'- > outer > select_from_x_right_outer',
|
|
147
|
-
'select_from_x_right_outer_ > join > select_join ^ join',
|
|
148
|
-
'select_from_x_full_ > join > select_join ^ outer join',
|
|
149
|
-
'- > outer > select_from_x_full_outer',
|
|
150
|
-
'select_from_x_full_outer_ > join > select_join ^ join',
|
|
151
|
-
'select_x_join_y > name > select_x_join_y ^ tables',
|
|
152
|
-
'select_x_join_y_ > as > select_x_join_y_as ^ as,on',
|
|
153
|
-
'- > on > select_x_join_y_on ^ as,on',
|
|
154
|
-
'select_x_join_y_as_ > name > select_x_join_y_as_y ^ x,y,z',
|
|
155
|
-
'select_x_join_y_as_y_ > on > select_x_join_y_on ^ on',
|
|
156
|
-
'select_x_join_y_on_ > name > select_x_join_y_on_a ^ columns',
|
|
157
|
-
'select_x_join_y_on_a > name > select_x_join_y_on_a ^ columns,=',
|
|
158
|
-
'- > comparison > select_x_join_y_on_a_op',
|
|
159
|
-
'select_x_join_y_on_a_ > comparison > select_x_join_y_on_a_op ^ =',
|
|
160
|
-
'select_x_join_y_on_a_op > name > select_x_join_y_on_a_op_b ^ columns',
|
|
161
|
-
'select_x_join_y_on_a_op_b > name > select_x_join_y_on_a_op_b ^ columns',
|
|
162
|
-
'- > _ > select_from_x_as_x_',
|
|
163
|
-
|
|
164
|
-
# <insert_statement> ::= INSERT INTO <table_name> [ ( <column_list> ) ]
|
|
165
|
-
# VALUES ( <value_list> )
|
|
166
|
-
# | INSERT INTO <table_name> [ ( <column_list> ) ]
|
|
167
|
-
# <query_expression>
|
|
168
|
-
|
|
169
|
-
# <table_name> ::= <identifier>
|
|
170
|
-
|
|
171
|
-
# <column_list> ::= <column_name> [ , <column_list> ]
|
|
172
|
-
|
|
173
|
-
# <column_name> ::= <identifier>
|
|
174
|
-
|
|
175
|
-
# <value_list> ::= <expression> [ , <value_list> ]
|
|
176
|
-
|
|
177
|
-
# <query_expression> ::= SELECT <select_list> FROM <table_reference_list> [ WHERE <search_condition> ] [ GROUP BY <grouping_column_list> ] [ HAVING <search_condition> ] [ ORDER BY <sort_specification_list> ]
|
|
178
|
-
' > insert > insert',
|
|
179
|
-
'insert_ > into > insert_into ^ into',
|
|
180
|
-
'insert_into_ > name > insert_into_x ^ tables',
|
|
181
|
-
'insert_into_x > name > insert_into_x ^ tables',
|
|
182
|
-
'- > ( > insert_into_x_lp_',
|
|
183
|
-
'insert_into_x_ > ( > insert_into_x_lp_ ^ (,values(',
|
|
184
|
-
'- > values > insert_values',
|
|
185
|
-
'insert_into_x_lp_ > name > insert_into_x_lp_a ^ id',
|
|
186
|
-
'insert_into_x_lp_a > , > insert_into_x_lp_a_comma_',
|
|
187
|
-
'- > ) > insert_into_x_lp_a_rp_',
|
|
188
|
-
'insert_into_x_lp_a_comma_ > name > insert_into_x_lp_a ^ id',
|
|
189
|
-
'insert_into_x_lp_a_rp__ > values > insert_values ^ values(,select',
|
|
190
|
-
'- > select > select',
|
|
191
|
-
'insert_values > ( > insert_values_lp_',
|
|
192
|
-
'insert_values_lp_ > name|single|num > insert_values_lp_v ^ single',
|
|
193
|
-
'insert_values_lp_v > , > insert_values_lp_v_comma_',
|
|
194
|
-
'insert_values_lp_v_comma_ > name|single|num > insert_values_lp_v',
|
|
195
|
-
|
|
196
|
-
# <update_statement> ::= UPDATE <table_name>
|
|
197
|
-
# SET <set_clause_list>
|
|
198
|
-
# [WHERE <search_condition>]
|
|
199
|
-
|
|
200
|
-
# <set_clause_list> ::= <set_clause> { , <set_clause> }
|
|
201
|
-
|
|
202
|
-
# <set_clause> ::= <column_name> = <update_value>
|
|
203
|
-
|
|
204
|
-
# <update_value> ::= <expression> | NULL | DEFAULT
|
|
205
|
-
|
|
206
|
-
# <search_condition> ::= <boolean_expression>
|
|
207
|
-
' > update > update',
|
|
208
|
-
'update_ > name > update_x ^ tables',
|
|
209
|
-
'update_x > name > update_x ^ tables',
|
|
210
|
-
'update_x_ > set > update_set ^ set',
|
|
211
|
-
'update_set_ > name > update_set_a ^ id',
|
|
212
|
-
'update_set_a > comparison > update_set_a_op',
|
|
213
|
-
'update_set_a_op > name|single|num > update_set_sc ^ single',
|
|
214
|
-
'update_set_sc > , > update_set_sc_comma_',
|
|
215
|
-
'update_set_sc_comma_ > name > update_set_a ^ id',
|
|
216
|
-
'update_set_sc_ > , > update_set_sc_comma_ ^ where',
|
|
217
|
-
'- > where > update_where',
|
|
218
|
-
'update_where_ > name > update_where_a ^ id',
|
|
219
|
-
'update_where_a > comparison > update_where_a_op',
|
|
220
|
-
'update_where_a_ > comparison > update_where_a_op ^ =,<,<=,>,>=,<>,like,not,in',
|
|
221
|
-
'- > not > update_where_a_not',
|
|
222
|
-
'- > in > update_where_a_in',
|
|
223
|
-
'update_where_a_not_ > comparison > update_where_a_not_op ^ like,in',
|
|
224
|
-
'- > in > update_where_a_in',
|
|
225
|
-
'update_where_a_in > ( > update_where_a_in_lp_ ^ (',
|
|
226
|
-
'- < ) > update_where_sc',
|
|
227
|
-
'update_where_a_in_lp_ > name|single|num > update_where_a_in_lp_a ^ single,select',
|
|
228
|
-
'- > select > update_where_a_in_lp_select',
|
|
229
|
-
'update_where_a_in_lp_select_ > name > select_a ^ id',
|
|
230
|
-
'update_where_a_in_lp_a > , > update_where_a_in_lp_a_comma_ ^ comma,)',
|
|
231
|
-
'update_where_a_in_lp_a_comma_ > name|single|num > update_where_a_in_lp_a ^ single',
|
|
232
|
-
'update_where_a_not_op > name|single|num > update_where_sc ^ single',
|
|
233
|
-
'update_where_a_op > name|single|num > update_where_sc ^ single',
|
|
234
|
-
'update_where_sc_ > and|or > update_where ^ and,or',
|
|
235
|
-
|
|
236
|
-
# <delete_statement> ::= DELETE FROM <table_name> [ WHERE <search_condition> ]
|
|
237
|
-
|
|
238
|
-
# <table_name> ::= <identifier>
|
|
239
|
-
|
|
240
|
-
# <search_condition> ::= <boolean_expression>
|
|
241
|
-
|
|
242
|
-
# <boolean_expression> ::= <predicate>
|
|
243
|
-
# | <boolean_expression> AND <predicate>
|
|
244
|
-
# | <boolean_expression> OR <predicate>
|
|
245
|
-
# | NOT <predicate>
|
|
246
|
-
# | ( <boolean_expression> )
|
|
247
|
-
|
|
248
|
-
# <predicate> ::= <expression> <comparison_operator> <expression>
|
|
249
|
-
# | <expression> IS NULL
|
|
250
|
-
# | <expression> IS NOT NULL
|
|
251
|
-
# | <expression> LIKE <pattern> [ ESCAPE <escape_character> ]
|
|
252
|
-
# | <expression> IN ( <expression_list> )
|
|
253
|
-
# | EXISTS ( <select_statement> )
|
|
254
|
-
# | ... (other predicates)
|
|
255
|
-
|
|
256
|
-
# <comparison_operator> ::= = | <> | != | > | < | >= | <=
|
|
257
|
-
|
|
258
|
-
# <expression> ::= <literal>
|
|
259
|
-
# | <column_name>
|
|
260
|
-
# | <function_call>
|
|
261
|
-
# | ( <expression> )
|
|
262
|
-
# | <expression> <arithmetic_operator> <expression>
|
|
263
|
-
# | ... (other expressions)
|
|
264
|
-
|
|
265
|
-
# <literal> ::= <numeric_literal> | <string_literal> | <boolean_literal> | <date_literal> | ...
|
|
266
|
-
|
|
267
|
-
# <column_name> ::= <identifier>
|
|
268
|
-
|
|
269
|
-
# <identifier> ::= <letter> { <letter> | <digit> | _ }...
|
|
270
|
-
|
|
271
|
-
# <pattern> ::= <string_literal>
|
|
272
|
-
|
|
273
|
-
# <escape_character> ::= <string_literal> (single character)
|
|
274
|
-
|
|
275
|
-
# <expression_list> ::= <expression> { , <expression> }...
|
|
276
|
-
' > delete > delete',
|
|
277
|
-
'delete_ > from > delete_from ^ from',
|
|
278
|
-
'delete_from_ > name > delete_from_x ^ tables',
|
|
279
|
-
'delete_from_x > name > delete_from_x ^ tables',
|
|
280
|
-
'delete_from_x_ > where > update_where ^ where',
|
|
281
|
-
|
|
282
|
-
# <alter table action> ::=
|
|
283
|
-
# ADD <column definition>
|
|
284
|
-
# | DROP COLUMN <column name>
|
|
285
|
-
# | MODIFY COLUMN <column name> <column modification>
|
|
286
|
-
# | RENAME TO <new table name>
|
|
287
|
-
# | ADD CONSTRAINT <constraint definition>
|
|
288
|
-
# | DROP CONSTRAINT <constraint name>
|
|
289
|
-
# | ... (other actions like adding/dropping indexes, partitions, etc.)
|
|
290
|
-
|
|
291
|
-
# <column definition> ::= <column name> <data type> [ <column constraint> ... ]
|
|
292
|
-
|
|
293
|
-
# <column modification> ::=
|
|
294
|
-
# SET DATA TYPE <data type>
|
|
295
|
-
# | SET DEFAULT <expression>
|
|
296
|
-
# | DROP DEFAULT
|
|
297
|
-
# | SET NOT NULL
|
|
298
|
-
# | DROP NOT NULL
|
|
299
|
-
# | ...
|
|
300
|
-
|
|
301
|
-
# <constraint definition> ::=
|
|
302
|
-
# PRIMARY KEY ( <column name list> )
|
|
303
|
-
# | UNIQUE ( <column name list> )
|
|
304
|
-
# | FOREIGN KEY ( <column name list> ) REFERENCES <referenced table> ( <referenced column list> )
|
|
305
|
-
# | CHECK ( <search condition> )
|
|
306
|
-
|
|
307
|
-
' > alter > alter',
|
|
308
|
-
'alter_ > table > alter_table ^ table',
|
|
309
|
-
'alter_table_ > name|audit > alter_table_t ^ tables',
|
|
310
|
-
'alter_table_t > name|audit > alter_table_t ^ tables',
|
|
311
|
-
'alter_table_t_ > add > alter_table_add ^ add,add constraint,drop column,drop constraint,rename to',
|
|
312
|
-
'- > drop > alter_table_drop',
|
|
313
|
-
]
|
|
314
|
-
|
|
315
|
-
KEYWORDS = [
|
|
316
|
-
'select', 'from', 'as', 'not', 'in', 'where',
|
|
317
|
-
'and', 'or', 'group', 'by', 'group by', 'order', 'order by', 'limit', 'asc', 'desc',
|
|
318
|
-
'inner join', 'on', 'left', 'right', 'full', 'outer', 'left outer join',
|
|
319
|
-
'left join', 'right outer join', 'right join', 'full join', 'full outer join',
|
|
320
|
-
'insert', 'into', 'values',
|
|
321
|
-
'update', 'where', 'set',
|
|
322
|
-
'delete',
|
|
323
|
-
'audit',
|
|
324
|
-
'alter', 'table', 'tables', 'add', 'drop', 'with',
|
|
325
|
-
'describe'
|
|
326
|
-
]
|
|
327
|
-
|
|
328
|
-
def spec(self):
|
|
329
|
-
return SqlSpec.SPEC
|
|
330
|
-
|
|
331
|
-
def keywords(self):
|
|
332
|
-
return SqlSpec.KEYWORDS
|
|
333
|
-
|
|
334
|
-
class CqlSpec(SqlSpec):
|
|
335
|
-
SPEC = SqlSpec.SPEC + [
|
|
336
|
-
# ALTER TABLE [ <keyspace_name> . ] <table_name>
|
|
337
|
-
# ( ALTER <column_name> TYPE <cql_type>
|
|
338
|
-
# | ADD ( <column_definition_list> )
|
|
339
|
-
# | DROP ( <column_list> )
|
|
340
|
-
# | RENAME <column_name> TO <column_name> [ AND <column_name> TO <column_name> ... ]
|
|
341
|
-
# | WITH <table_properties> );
|
|
342
|
-
|
|
343
|
-
'alter_ > table > alter_table ^ table,`tables`',
|
|
344
|
-
'- > tables > alter_tables',
|
|
345
|
-
'alter_tables_ > with > alter_table_with ^ with',
|
|
346
|
-
'alter_table_t_ > with > alter_table_with ^ with,add,drop',
|
|
347
|
-
'alter_table_with_ > name > alter_table_with_p ^ table-props',
|
|
348
|
-
'alter_table_with_p > comparison > alter_table_with_p_op ^ =',
|
|
349
|
-
'alter_table_with_p_op > name|single|num > alter_table_with_p_op ^ table-prop-values',
|
|
350
|
-
|
|
351
|
-
' > describe > describe',
|
|
352
|
-
'describe_ > table > desc_table ^ table,`tables`,keyspace,keyspaces,schema',
|
|
353
|
-
'- > tables > desc_tables',
|
|
354
|
-
'- > keyspace > desc_keyspace',
|
|
355
|
-
'- > keyspaces > desc_keyspaces',
|
|
356
|
-
'- > schema > desc_schema',
|
|
357
|
-
'desc_table_ > name > desc_table_t ^ tables',
|
|
358
|
-
'desc_table_t > name > desc_table_t ^ tables',
|
|
359
|
-
'desc_table_t_ > & > desc_table_t_bg ^ &',
|
|
360
|
-
'desc_tables_ > & > desc_tables_bg ^ &',
|
|
361
|
-
'desc_keyspace_ > name > desc_keyspace_k',
|
|
362
|
-
'desc_keyspace_k_ > & > desc_keyspace_k_bg ^ &',
|
|
363
|
-
'desc_schema_ > & > desc_schema_bg ^ &',
|
|
364
|
-
]
|
|
365
|
-
|
|
366
|
-
KEYWORDS = SqlSpec.KEYWORDS + [
|
|
367
|
-
'schema', 'keyspace', 'keyspaces', 'tables'
|
|
368
|
-
]
|
|
369
|
-
|
|
370
|
-
def spec(self):
|
|
371
|
-
return CqlSpec.SPEC
|
|
372
|
-
|
|
373
|
-
def keywords(self):
|
|
374
|
-
return CqlSpec.KEYWORDS
|
|
375
|
-
|
|
376
|
-
class AthenaSpec(SqlSpec):
|
|
377
|
-
SPEC = SqlSpec.SPEC + [
|
|
378
|
-
'alter_table_t_ > add > alter_table_add ^ add partition,drop partition',
|
|
379
|
-
'alter_table_add_ > partition > alter_partition ^ partition',
|
|
380
|
-
'alter_table_drop_ > partition > alter_partition ^ partition',
|
|
381
|
-
'alter_partition > ( > alter_partition_lp ^ (',
|
|
382
|
-
'alter_partition_lp > name > alter_partition_lp_a ^ partition-columns',
|
|
383
|
-
'alter_partition_lp_a > comparison > alter_partition_lp_a_op ^ =',
|
|
384
|
-
'alter_partition_lp_a_op > single > alter_partition_lp_a_op_v ^ single',
|
|
385
|
-
'alter_partition_lp_a_op_v > , > alter_partition_lp_sc ^ single',
|
|
386
|
-
'alter_partition_lp_sc > name|) > alter_partition_lp_a ^ partition-columns',
|
|
387
|
-
|
|
388
|
-
' > describe > describe',
|
|
389
|
-
'describe_ > name > desc_t ^ tables',
|
|
390
|
-
'desc_t > name > desc_t ^ tables',
|
|
391
|
-
'desc_t_ > name > desc_t_',
|
|
392
|
-
]
|
|
393
|
-
|
|
394
|
-
KEYWORDS = SqlSpec.KEYWORDS + [
|
|
395
|
-
'partition'
|
|
396
|
-
]
|
|
397
|
-
|
|
398
|
-
def spec(self):
|
|
399
|
-
return AthenaSpec.SPEC
|
|
400
|
-
|
|
401
|
-
def keywords(self):
|
|
402
|
-
return AthenaSpec.KEYWORDS
|
|
403
|
-
|
|
404
9
|
class StateTo:
|
|
405
10
|
def __init__(self, to_s: str, comeback_token: str = None, comeback_state: str = None):
|
|
406
11
|
self.to_s = to_s
|
|
@@ -409,31 +14,46 @@ class StateTo:
|
|
|
409
14
|
self.context: dict[str, str] = {}
|
|
410
15
|
|
|
411
16
|
def __str__(self):
|
|
412
|
-
return f'{self.to_s} comeback[{self.comeback_token} {self.comeback_state}]'
|
|
17
|
+
return f'{self.to_s if self.to_s else None} comeback[{self.comeback_token} {self.comeback_state}]'
|
|
413
18
|
|
|
414
19
|
class StateMachine:
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
20
|
+
@abstractmethod
|
|
21
|
+
def spec(self) -> str:
|
|
22
|
+
return None
|
|
23
|
+
|
|
24
|
+
@abstractmethod
|
|
25
|
+
def keywords(self) -> list[str]:
|
|
26
|
+
return None
|
|
27
|
+
|
|
28
|
+
def incomplete_name_transition_condition(self, from_s: str, token: str, to_s: str, suggestions: str) -> list[str]:
|
|
29
|
+
if not suggestions:
|
|
30
|
+
return None
|
|
421
31
|
|
|
32
|
+
tokens = [token]
|
|
33
|
+
if '|' in token:
|
|
34
|
+
tokens = token.split('|')
|
|
35
|
+
|
|
36
|
+
if 'name' not in tokens:
|
|
37
|
+
return None
|
|
38
|
+
|
|
39
|
+
return tokens
|
|
40
|
+
|
|
41
|
+
def __init__(self, indent=0, push_level = 0, debug = False):
|
|
422
42
|
self.states: dict[str, StateTo] = {}
|
|
423
43
|
self.suggestions: dict[str, str] = {}
|
|
424
44
|
|
|
425
45
|
self.indent = indent
|
|
426
|
-
self.
|
|
46
|
+
self.push_level = push_level
|
|
427
47
|
self.comebacks: dict[int, str] = {}
|
|
428
48
|
self.debug = debug
|
|
429
49
|
|
|
430
50
|
from_ss_to_add = []
|
|
431
51
|
from_ss = ['']
|
|
432
52
|
words: str = None
|
|
433
|
-
for l in self.
|
|
53
|
+
for l in self.spec():
|
|
434
54
|
t_and_w = l.split('^')
|
|
435
55
|
if len(t_and_w) > 1:
|
|
436
|
-
words = t_and_w[1]
|
|
56
|
+
words = t_and_w[1].strip()
|
|
437
57
|
else:
|
|
438
58
|
words = None
|
|
439
59
|
|
|
@@ -451,15 +71,16 @@ class StateMachine:
|
|
|
451
71
|
from_ss_to_add = []
|
|
452
72
|
from_ss.append(tks[0].strip(' '))
|
|
453
73
|
|
|
454
|
-
self.add_transitions(from_ss, tks)
|
|
74
|
+
self.add_transitions(from_ss, tks, words)
|
|
455
75
|
|
|
456
|
-
def add_transitions(self, from_ss: list[str], tks: list[str]):
|
|
76
|
+
def add_transitions(self, from_ss: list[str], tks: list[str], words: str):
|
|
457
77
|
token = tks[1].strip(' ')
|
|
458
78
|
if len(tks) > 2:
|
|
459
79
|
to_s = tks[2].strip(' ')
|
|
460
80
|
for from_s in from_ss:
|
|
461
81
|
self.add_whitespace_transition(from_s, to_s)
|
|
462
82
|
self.add_transition(from_s, token, to_s)
|
|
83
|
+
self.add_incomplete_name_transition(from_s, token, to_s, words)
|
|
463
84
|
elif '<' in tks[0]:
|
|
464
85
|
from_and_token = tks[0].split('<')
|
|
465
86
|
if len(from_and_token) > 1:
|
|
@@ -467,12 +88,22 @@ class StateMachine:
|
|
|
467
88
|
self.add_comeback_transition(from_s, from_and_token[1], tks[1].strip(' '))
|
|
468
89
|
|
|
469
90
|
def add_whitespace_transition(self, from_s: str, to_s: str):
|
|
470
|
-
|
|
471
|
-
if from_s.endswith('_') and not from_s.endswith('_comma_') and not from_s.endswith('_lp_') and not from_s.endswith('_rp_'):
|
|
91
|
+
if self.witespace_transition_condition(from_s, to_s):
|
|
472
92
|
if self.debug:
|
|
473
93
|
print(f'{from_s[:-1]} > _ = {to_s}')
|
|
474
94
|
self.states[f'{from_s[:-1]} > _'] = StateTo(from_s)
|
|
475
95
|
|
|
96
|
+
def witespace_transition_condition(self, from_s: str, to_s: str):
|
|
97
|
+
return from_s.endswith('_')
|
|
98
|
+
|
|
99
|
+
def add_incomplete_name_transition(self, from_s: str, token: str, to_s: str, words: str):
|
|
100
|
+
if tokens := self.incomplete_name_transition_condition(from_s, token, to_s, words):
|
|
101
|
+
self.suggestions[to_s] = words
|
|
102
|
+
for token in tokens:
|
|
103
|
+
if self.debug:
|
|
104
|
+
print(f'{to_s} > {token} = {to_s}')
|
|
105
|
+
self.states[f'{to_s} > {token}'] = StateTo(to_s)
|
|
106
|
+
|
|
476
107
|
def add_transition(self, from_s: str, token: str, to_s: str):
|
|
477
108
|
tokens = [token]
|
|
478
109
|
if '|' in token:
|
|
@@ -496,18 +127,18 @@ class StateMachine:
|
|
|
496
127
|
self.states[key] = orig
|
|
497
128
|
|
|
498
129
|
def traverse_tokens(self, tokens: list[Token], state: StateTo = StateTo('')):
|
|
499
|
-
def
|
|
130
|
+
def handle_push():
|
|
500
131
|
if f'{state.to_s} > {it}' in self.states:
|
|
501
132
|
state_test = self.states[f'{state.to_s} > {it}']
|
|
502
133
|
if state_test.comeback_token:
|
|
503
|
-
self.comebacks[self.
|
|
134
|
+
self.comebacks[self.push_level] = state_test.comeback_state
|
|
504
135
|
|
|
505
|
-
def
|
|
506
|
-
if self.
|
|
136
|
+
def handle_pop():
|
|
137
|
+
if self.push_level in self.comebacks:
|
|
507
138
|
try:
|
|
508
|
-
return StateTo(self.comebacks[self.
|
|
139
|
+
return StateTo(self.comebacks[self.push_level])
|
|
509
140
|
finally:
|
|
510
|
-
del self.comebacks[self.
|
|
141
|
+
del self.comebacks[self.push_level]
|
|
511
142
|
|
|
512
143
|
return None
|
|
513
144
|
|
|
@@ -533,7 +164,7 @@ class StateMachine:
|
|
|
533
164
|
comeback_state = None
|
|
534
165
|
|
|
535
166
|
it = ''
|
|
536
|
-
if (t := token.value.lower()) in self.
|
|
167
|
+
if (t := token.value.lower()) in self.keywords():
|
|
537
168
|
it = t
|
|
538
169
|
elif token.ttype == T.Text.Whitespace:
|
|
539
170
|
it = '_'
|
|
@@ -550,11 +181,11 @@ class StateMachine:
|
|
|
550
181
|
it = token.value
|
|
551
182
|
|
|
552
183
|
if it == '(':
|
|
553
|
-
|
|
554
|
-
self.
|
|
184
|
+
handle_push()
|
|
185
|
+
self.push_level += 1
|
|
555
186
|
elif it == ')':
|
|
556
|
-
self.
|
|
557
|
-
comeback_state =
|
|
187
|
+
self.push_level -= 1
|
|
188
|
+
comeback_state = handle_pop()
|
|
558
189
|
|
|
559
190
|
elif token.ttype == T.Operator.Comparison:
|
|
560
191
|
it = 'comparison'
|
adam/sql/term_completer.py
CHANGED
|
@@ -22,6 +22,9 @@ class TermCompleter(WordCompleter):
|
|
|
22
22
|
) -> None:
|
|
23
23
|
super().__init__(words, ignore_case, display_dict, meta_dict, WORD, sentence, match_middle, pattern)
|
|
24
24
|
|
|
25
|
+
def __str__(self):
|
|
26
|
+
return ','.join(self.words)
|
|
27
|
+
|
|
25
28
|
def get_completions(
|
|
26
29
|
self, document: Document, complete_event: CompleteEvent
|
|
27
30
|
) -> Iterable[Completion]:
|
adam/utils_k8s/pods.py
CHANGED
|
@@ -11,7 +11,7 @@ from kubernetes.stream.ws_client import ERROR_CHANNEL
|
|
|
11
11
|
from adam.config import Config
|
|
12
12
|
from adam.utils_k8s.volumes import ConfigMapMount
|
|
13
13
|
from adam.pod_exec_result import PodExecResult
|
|
14
|
-
from adam.utils import elapsed_time, log2
|
|
14
|
+
from adam.utils import elapsed_time, log2
|
|
15
15
|
from .kube_context import KubeContext
|
|
16
16
|
|
|
17
17
|
T = TypeVar('T')
|
|
@@ -28,7 +28,7 @@ class Pods:
|
|
|
28
28
|
def delete(pod_name: str, namespace: str, grace_period_seconds: int = None):
|
|
29
29
|
try:
|
|
30
30
|
v1 = client.CoreV1Api()
|
|
31
|
-
|
|
31
|
+
v1.delete_namespaced_pod(pod_name, namespace, grace_period_seconds=grace_period_seconds)
|
|
32
32
|
except Exception as e:
|
|
33
33
|
log2("Exception when calling CoreV1Api->delete_namespaced_pod: %s\n" % e)
|
|
34
34
|
|
adam/version.py
CHANGED