kaqing 2.0.95__py3-none-any.whl → 2.0.115__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 +1 -15
- adam/commands/alter_tables.py +3 -14
- adam/commands/app.py +3 -3
- adam/commands/app_ping.py +2 -2
- adam/commands/audit/audit.py +26 -11
- adam/commands/audit/audit_repair_tables.py +20 -37
- adam/commands/audit/audit_run.py +58 -0
- adam/commands/audit/show_last10.py +51 -0
- adam/commands/audit/show_slow10.py +50 -0
- adam/commands/audit/show_top10.py +49 -0
- adam/commands/audit/utils_show_top10.py +59 -0
- adam/commands/bash/bash.py +124 -0
- adam/commands/bash/bash_completer.py +93 -0
- adam/commands/cat.py +55 -0
- adam/commands/cd.py +23 -11
- adam/commands/check.py +6 -0
- adam/commands/code.py +60 -0
- adam/commands/command.py +9 -4
- adam/commands/commands_utils.py +1 -2
- adam/commands/cql/cql_completions.py +7 -3
- adam/commands/cql/cql_utils.py +100 -8
- adam/commands/cql/cqlsh.py +10 -5
- adam/commands/deploy/deploy.py +7 -1
- adam/commands/deploy/deploy_pg_agent.py +2 -2
- adam/commands/deploy/undeploy.py +7 -1
- adam/commands/deploy/undeploy_pg_agent.py +2 -2
- adam/commands/devices.py +29 -0
- adam/commands/export/__init__.py +0 -0
- adam/commands/export/export.py +60 -0
- adam/commands/export/export_on_x.py +76 -0
- adam/commands/export/export_rmdbs.py +65 -0
- adam/commands/export/export_select.py +68 -0
- adam/commands/export/export_use.py +56 -0
- adam/commands/export/utils_export.py +253 -0
- adam/commands/help.py +9 -5
- adam/commands/issues.py +6 -0
- adam/commands/kubectl.py +41 -0
- adam/commands/login.py +6 -3
- adam/commands/logs.py +1 -0
- adam/commands/ls.py +39 -27
- adam/commands/medusa/medusa_show_backupjobs.py +1 -0
- adam/commands/nodetool.py +5 -2
- adam/commands/postgres/postgres.py +4 -4
- 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 +18 -32
- adam/commands/pwd.py +4 -3
- adam/commands/reaper/reaper.py +3 -0
- adam/commands/repair/repair.py +3 -3
- adam/commands/report.py +6 -0
- adam/commands/show/show.py +3 -1
- adam/commands/show/show_app_actions.py +3 -0
- adam/commands/show/show_app_queues.py +3 -2
- adam/commands/show/show_login.py +3 -0
- adam/config.py +1 -1
- adam/embedded_params.py +1 -1
- adam/pod_exec_result.py +7 -1
- adam/repl.py +121 -97
- adam/repl_commands.py +29 -17
- adam/repl_state.py +224 -44
- adam/sql/sql_completer.py +86 -62
- adam/sql/sql_state_machine.py +563 -0
- adam/sql/term_completer.py +3 -0
- adam/utils_athena.py +108 -74
- adam/utils_audits.py +104 -0
- adam/utils_export.py +42 -0
- adam/utils_k8s/app_clusters.py +33 -0
- adam/utils_k8s/app_pods.py +31 -0
- adam/utils_k8s/cassandra_clusters.py +4 -5
- adam/utils_k8s/cassandra_nodes.py +4 -4
- adam/utils_k8s/pods.py +42 -6
- adam/utils_k8s/statefulsets.py +2 -2
- adam/version.py +1 -1
- {kaqing-2.0.95.dist-info → kaqing-2.0.115.dist-info}/METADATA +1 -1
- {kaqing-2.0.95.dist-info → kaqing-2.0.115.dist-info}/RECORD +80 -67
- adam/commands/bash.py +0 -92
- adam/commands/cql/cql_table_completer.py +0 -8
- adam/commands/describe/describe.py +0 -46
- adam/commands/describe/describe_keyspace.py +0 -60
- adam/commands/describe/describe_keyspaces.py +0 -50
- adam/commands/describe/describe_table.py +0 -60
- adam/commands/describe/describe_tables.py +0 -50
- adam/commands/postgres/psql_table_completer.py +0 -11
- adam/sql/state_machine.py +0 -460
- /adam/commands/{describe → bash}/__init__.py +0 -0
- {kaqing-2.0.95.dist-info → kaqing-2.0.115.dist-info}/WHEEL +0 -0
- {kaqing-2.0.95.dist-info → kaqing-2.0.115.dist-info}/entry_points.txt +0 -0
- {kaqing-2.0.95.dist-info → kaqing-2.0.115.dist-info}/top_level.txt +0 -0
|
@@ -0,0 +1,563 @@
|
|
|
1
|
+
from typing import Callable
|
|
2
|
+
from sqlparse.sql import Token
|
|
3
|
+
from sqlparse import tokens as TOKEN
|
|
4
|
+
|
|
5
|
+
from adam.utils_repl.state_machine import StateMachine, State
|
|
6
|
+
|
|
7
|
+
__all__ = [
|
|
8
|
+
'SqlStateMachine', 'CqlStateMachine', 'AthenaStateMachine'
|
|
9
|
+
]
|
|
10
|
+
|
|
11
|
+
SQL_SPEC = [
|
|
12
|
+
# <select_statement> ::= SELECT <select_list>
|
|
13
|
+
# FROM <table_expression>
|
|
14
|
+
# [WHERE <search_condition>]
|
|
15
|
+
# [<group_by_clause>]
|
|
16
|
+
# [<having_clause>]
|
|
17
|
+
# [<order_by_clause>]
|
|
18
|
+
# [<limit_clause>]
|
|
19
|
+
|
|
20
|
+
# <search_condition> ::= <boolean_term>
|
|
21
|
+
# | <search_condition> OR <boolean_term>
|
|
22
|
+
|
|
23
|
+
# <boolean_term> ::= <boolean_factor>
|
|
24
|
+
# | <boolean_term> AND <boolean_factor>
|
|
25
|
+
|
|
26
|
+
# <boolean_factor> ::= [NOT] <predicate>
|
|
27
|
+
# | ([NOT] <search_condition>)
|
|
28
|
+
|
|
29
|
+
# <predicate> ::= <comparison_predicate>
|
|
30
|
+
# | <between_predicate>
|
|
31
|
+
# | <in_predicate>
|
|
32
|
+
# | <like_predicate>
|
|
33
|
+
# | <null_predicate>
|
|
34
|
+
# | <exists_predicate>
|
|
35
|
+
# | <quantified_predicate>
|
|
36
|
+
# | <unique_predicate>
|
|
37
|
+
# | <match_predicate>
|
|
38
|
+
# | <overlaps_predicate>
|
|
39
|
+
# | <distinct_predicate>
|
|
40
|
+
# | <member_predicate>
|
|
41
|
+
# | <submultiset_predicate>
|
|
42
|
+
# | <set_predicate>
|
|
43
|
+
|
|
44
|
+
# <comparison_predicate> ::= <row_value_expression> <comparison_operator> <row_value_expression>
|
|
45
|
+
# <comparison_operator> ::= '=' | '<>' | '<' | '<=' | '>' | '>='
|
|
46
|
+
|
|
47
|
+
# <row_value_expression> ::= <value_expression>
|
|
48
|
+
# | (<value_expression> [ { <comma> <value_expression> }... ])
|
|
49
|
+
|
|
50
|
+
# <value_expression> ::= <numeric_value_expression>
|
|
51
|
+
# | <string_value_expression>
|
|
52
|
+
# | <datetime_value_expression>
|
|
53
|
+
# | <interval_value_expression>
|
|
54
|
+
# | <boolean_value_expression>
|
|
55
|
+
# | <user_defined_type_value_expression>
|
|
56
|
+
# | <reference_value_expression>
|
|
57
|
+
# | <collection_value_expression>
|
|
58
|
+
# | <row_value_constructor>
|
|
59
|
+
# | <case_expression>
|
|
60
|
+
# | <cast_expression>
|
|
61
|
+
# | <subquery>
|
|
62
|
+
# | NULL
|
|
63
|
+
# | DEFAULT
|
|
64
|
+
# | <identifier>
|
|
65
|
+
# | <literal>
|
|
66
|
+
' > select > select ^ select,insert,update,delete,alter,preview',
|
|
67
|
+
'select_ > name|* > select_a ^ *',
|
|
68
|
+
'select_a > , > select_a_comma_',
|
|
69
|
+
'select_a_comma_ > name|* > select_a ^ *',
|
|
70
|
+
'select_a_ > from > select_from ^ from',
|
|
71
|
+
'select_from_ > name|audit > select_from_x ^ (select,tables',
|
|
72
|
+
'- > ( > select_from_lp_',
|
|
73
|
+
'- < ) > select_from_sq',
|
|
74
|
+
'select_from_lp_ > select > select',
|
|
75
|
+
'select_from_x > , > select_from_x_comma_ ^ (select,tables',
|
|
76
|
+
'- > ; > ',
|
|
77
|
+
'select_from_sq_ > as > select_from_x_as ^ as',
|
|
78
|
+
'select_from_x_comma_ > name|audit > select_from_x ^ tables',
|
|
79
|
+
'select_from_x_ ^ as,where,inner join,left outer join,right outer join,full outer join,group by,order by,limit',
|
|
80
|
+
'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',
|
|
81
|
+
'- > as > select_from_x_as',
|
|
82
|
+
'- > where > select_where',
|
|
83
|
+
'- > order > select_order',
|
|
84
|
+
'- > order by > select_order_by',
|
|
85
|
+
'- > limit > select_where_sc_limit',
|
|
86
|
+
'- > group > select_group',
|
|
87
|
+
'- > group by > select_group_by',
|
|
88
|
+
'- > inner > select_from_x_inner',
|
|
89
|
+
'- > inner join > select_join',
|
|
90
|
+
'- > left > select_from_x_left',
|
|
91
|
+
'- > left join > select_join',
|
|
92
|
+
'- > left outer join > select_join',
|
|
93
|
+
'- > right > select_from_x_right',
|
|
94
|
+
'- > right join > select_join',
|
|
95
|
+
'- > right outer join > select_join',
|
|
96
|
+
'- > full > select_from_x_full',
|
|
97
|
+
'- > full outer join > select_join',
|
|
98
|
+
'- > ; > ',
|
|
99
|
+
'select_from_x_as_ > name > select_from_x_as_x ^ x,y,z',
|
|
100
|
+
'select_from_x_as_x > , > select_from_x_as_x_comma_',
|
|
101
|
+
'- > ; > ',
|
|
102
|
+
'select_from_x_as_x_comma_ > name|audit > select_from_x ^ tables',
|
|
103
|
+
'select_where_ > name > select_where_a ^ columns',
|
|
104
|
+
'select_where_a > name > select_where_a ^ columns,=,<,<=,>,>=,<>',
|
|
105
|
+
'- > comparison > select_where_a_op',
|
|
106
|
+
'select_where_a_ > comparison > select_where_a_op ^ =,<,<=,>,>=,<>,like,not,in',
|
|
107
|
+
'- > not > select_where_a_not',
|
|
108
|
+
'- > in > select_where_a_in',
|
|
109
|
+
'select_where_a_not_ > comparison > select_where_a_not_op ^ like,in',
|
|
110
|
+
'- > in > select_where_a_in',
|
|
111
|
+
'select_where_a_in > ( > select_where_a_in_lp_ ^ (',
|
|
112
|
+
'- < ) > select_where_sc',
|
|
113
|
+
'select_where_a_in_lp_ > name|single|num > select_where_a_in_lp_a ^ single,select',
|
|
114
|
+
'- > select > select_where_a_in_lp_select',
|
|
115
|
+
'select_where_a_in_lp_select_ > name > select_a ^ id',
|
|
116
|
+
'select_where_a_in_lp_a > , > select_where_a_in_lp_a_comma_ ^ comma,)',
|
|
117
|
+
'select_where_a_in_lp_a_comma_ > name|single|num > select_where_a_in_lp_a ^ single',
|
|
118
|
+
'select_where_a_not_op > name|single|num > select_where_sc ^ single',
|
|
119
|
+
'select_where_a_op > name|single|num > select_where_sc ^ single',
|
|
120
|
+
'select_where_sc > ; > ',
|
|
121
|
+
'select_where_sc_ > and|or > select_where ^ and,or,order by,group by,limit',
|
|
122
|
+
'- > group > select_group',
|
|
123
|
+
'- > group by > select_group_by',
|
|
124
|
+
'- > order > select_order',
|
|
125
|
+
'- > order by > select_order_by',
|
|
126
|
+
'- > limit > select_where_sc_limit',
|
|
127
|
+
'- > ; > ',
|
|
128
|
+
'select_group_ > by > select_group_by ^ by',
|
|
129
|
+
'select_group_by_ > name > select_group_by_a ^ columns',
|
|
130
|
+
'select_group_by_a > , > select_group_by_a_comma_ ^ columns',
|
|
131
|
+
'- > ; > ',
|
|
132
|
+
'select_group_by_a_comma_ > name > select_group_by_a ^ columns',
|
|
133
|
+
'select_group_by_a_ > limit > select_where_sc_limit ^ limit,order by',
|
|
134
|
+
'- > order > select_order',
|
|
135
|
+
'- > order by > select_order_by',
|
|
136
|
+
'- > ; > ',
|
|
137
|
+
'select_order_ > by > select_order_by ^ by',
|
|
138
|
+
'select_order_by_ > name > select_order_by_a ^ columns',
|
|
139
|
+
'select_order_by_a > , > select_order_by_a_comma_',
|
|
140
|
+
'- > ; > ',
|
|
141
|
+
'select_order_by_a_comma_ > name > select_order_by_a ^ columns',
|
|
142
|
+
'select_order_by_a_ > desc|asc > select_order_by_a_desc ^ desc,asc,limit',
|
|
143
|
+
'- > limit > select_where_sc_limit',
|
|
144
|
+
'- > ; > ',
|
|
145
|
+
'select_order_by_a_desc > , > select_order_by_a_comma_',
|
|
146
|
+
'- > ; > ',
|
|
147
|
+
'select_order_by_a_desc_ > limit > select_where_sc_limit ^ limit',
|
|
148
|
+
'- > ; > ',
|
|
149
|
+
'select_where_sc_limit_ > num > select_where_sc_limit_num ^ 1',
|
|
150
|
+
'select_where_sc_limit_num > ; > ',
|
|
151
|
+
'select_where_sc_limit_num_rp__ > as > select_from_x_as ^ as',
|
|
152
|
+
'select_where_x_inner_ > join > select_join',
|
|
153
|
+
'select_join_ > name|audit > select_x_join_y ^ tables',
|
|
154
|
+
'select_from_x_left_ > join > select_join ^ outer join',
|
|
155
|
+
'- > outer > select_from_x_left_outer',
|
|
156
|
+
'select_from_x_left_outer_ > join > select_join ^ join',
|
|
157
|
+
'select_from_x_right_ > join > select_join ^ outer join',
|
|
158
|
+
'- > outer > select_from_x_right_outer',
|
|
159
|
+
'select_from_x_right_outer_ > join > select_join ^ join',
|
|
160
|
+
'select_from_x_full_ > join > select_join ^ outer join',
|
|
161
|
+
'- > outer > select_from_x_full_outer',
|
|
162
|
+
'select_from_x_full_outer_ > join > select_join ^ join',
|
|
163
|
+
'select_x_join_y_ > as > select_x_join_y_as ^ as,on',
|
|
164
|
+
'- > on > select_x_join_y_on ^ as,on',
|
|
165
|
+
'select_x_join_y_as_ > name > select_x_join_y_as_y ^ x,y,z',
|
|
166
|
+
'select_x_join_y_as_y_ > on > select_x_join_y_on ^ on',
|
|
167
|
+
'select_x_join_y_on_ > name > select_x_join_y_on_a ^ columns',
|
|
168
|
+
'select_x_join_y_on_a > name > select_x_join_y_on_a ^ columns,=',
|
|
169
|
+
'- > comparison > select_x_join_y_on_a_op',
|
|
170
|
+
'select_x_join_y_on_a_ > comparison > select_x_join_y_on_a_op ^ =',
|
|
171
|
+
'select_x_join_y_on_a_op > name > select_x_join_y_on_a_op_b ^ columns',
|
|
172
|
+
'select_x_join_y_on_a_op_b > _ > select_from_x_as_x_',
|
|
173
|
+
'- > ; > ',
|
|
174
|
+
|
|
175
|
+
# <insert_statement> ::= INSERT INTO <table_name> [ ( <column_list> ) ]
|
|
176
|
+
# VALUES ( <value_list> )
|
|
177
|
+
# | INSERT INTO <table_name> [ ( <column_list> ) ]
|
|
178
|
+
# <query_expression>
|
|
179
|
+
|
|
180
|
+
# <table_name> ::= <identifier>
|
|
181
|
+
|
|
182
|
+
# <column_list> ::= <column_name> [ , <column_list> ]
|
|
183
|
+
|
|
184
|
+
# <column_name> ::= <identifier>
|
|
185
|
+
|
|
186
|
+
# <value_list> ::= <expression> [ , <value_list> ]
|
|
187
|
+
|
|
188
|
+
# <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> ]
|
|
189
|
+
' > insert > insert',
|
|
190
|
+
'insert_ > into > insert_into ^ into',
|
|
191
|
+
'insert_into_ > name|audit > insert_into_x ^ tables',
|
|
192
|
+
'insert_into_x > ( > insert_into_x_lp_',
|
|
193
|
+
'insert_into_x_ > ( > insert_into_x_lp_ ^ (,values(',
|
|
194
|
+
'- > values > insert_values',
|
|
195
|
+
'insert_into_x_lp_ > name > insert_into_x_lp_a ^ id',
|
|
196
|
+
'insert_into_x_lp_a > , > insert_into_x_lp_a_comma_',
|
|
197
|
+
'- > ) > insert_into_x_lp_a_rp_',
|
|
198
|
+
'insert_into_x_lp_a_comma_ > name > insert_into_x_lp_a ^ id',
|
|
199
|
+
'insert_into_x_lp_a_rp__ > values > insert_values ^ values(,select',
|
|
200
|
+
'- > select > select',
|
|
201
|
+
'insert_values > ( > insert_values_lp_',
|
|
202
|
+
'insert_values_lp_ > name|single|num > insert_values_lp_v ^ single',
|
|
203
|
+
'insert_values_lp_v > , > insert_values_lp_v_comma_',
|
|
204
|
+
'insert_values_lp_v_comma_ > name|single|num > insert_values_lp_v',
|
|
205
|
+
|
|
206
|
+
# <update_statement> ::= UPDATE <table_name>
|
|
207
|
+
# SET <set_clause_list>
|
|
208
|
+
# [WHERE <search_condition>]
|
|
209
|
+
|
|
210
|
+
# <set_clause_list> ::= <set_clause> { , <set_clause> }
|
|
211
|
+
|
|
212
|
+
# <set_clause> ::= <column_name> = <update_value>
|
|
213
|
+
|
|
214
|
+
# <update_value> ::= <expression> | NULL | DEFAULT
|
|
215
|
+
|
|
216
|
+
# <search_condition> ::= <boolean_expression>
|
|
217
|
+
' > update > update',
|
|
218
|
+
'update_ > name|audit > update_x ^ tables',
|
|
219
|
+
'update_x_ > set > update_set ^ set',
|
|
220
|
+
'update_set_ > name > update_set_a ^ id',
|
|
221
|
+
'update_set_a > comparison > update_set_a_op',
|
|
222
|
+
'update_set_a_op > name|single|num > update_set_sc ^ single',
|
|
223
|
+
'update_set_sc > , > update_set_sc_comma_',
|
|
224
|
+
'update_set_sc_comma_ > name > update_set_a ^ id',
|
|
225
|
+
'update_set_sc_ > , > update_set_sc_comma_ ^ where',
|
|
226
|
+
'- > where > update_where',
|
|
227
|
+
'update_where_ > name > update_where_a ^ id',
|
|
228
|
+
'update_where_a > comparison > update_where_a_op',
|
|
229
|
+
'update_where_a_ > comparison > update_where_a_op ^ =,<,<=,>,>=,<>,like,not,in',
|
|
230
|
+
'- > not > update_where_a_not',
|
|
231
|
+
'- > in > update_where_a_in',
|
|
232
|
+
'update_where_a_not_ > comparison > update_where_a_not_op ^ like,in',
|
|
233
|
+
'- > in > update_where_a_in',
|
|
234
|
+
'update_where_a_in > ( > update_where_a_in_lp_ ^ (',
|
|
235
|
+
'- < ) > update_where_sc',
|
|
236
|
+
'update_where_a_in_lp_ > name|single|num > update_where_a_in_lp_a ^ single,select',
|
|
237
|
+
'- > select > update_where_a_in_lp_select',
|
|
238
|
+
'update_where_a_in_lp_select_ > name > select_a ^ id',
|
|
239
|
+
'update_where_a_in_lp_a > , > update_where_a_in_lp_a_comma_ ^ comma,)',
|
|
240
|
+
'update_where_a_in_lp_a_comma_ > name|single|num > update_where_a_in_lp_a ^ single',
|
|
241
|
+
'update_where_a_not_op > name|single|num > update_where_sc ^ single',
|
|
242
|
+
'update_where_a_op > name|single|num > update_where_sc ^ single',
|
|
243
|
+
'update_where_sc_ > and|or > update_where ^ and,or',
|
|
244
|
+
|
|
245
|
+
# <delete_statement> ::= DELETE FROM <table_name> [ WHERE <search_condition> ]
|
|
246
|
+
|
|
247
|
+
# <table_name> ::= <identifier>
|
|
248
|
+
|
|
249
|
+
# <search_condition> ::= <boolean_expression>
|
|
250
|
+
|
|
251
|
+
# <boolean_expression> ::= <predicate>
|
|
252
|
+
# | <boolean_expression> AND <predicate>
|
|
253
|
+
# | <boolean_expression> OR <predicate>
|
|
254
|
+
# | NOT <predicate>
|
|
255
|
+
# | ( <boolean_expression> )
|
|
256
|
+
|
|
257
|
+
# <predicate> ::= <expression> <comparison_operator> <expression>
|
|
258
|
+
# | <expression> IS NULL
|
|
259
|
+
# | <expression> IS NOT NULL
|
|
260
|
+
# | <expression> LIKE <pattern> [ ESCAPE <escape_character> ]
|
|
261
|
+
# | <expression> IN ( <expression_list> )
|
|
262
|
+
# | EXISTS ( <select_statement> )
|
|
263
|
+
# | ... (other predicates)
|
|
264
|
+
|
|
265
|
+
# <comparison_operator> ::= = | <> | != | > | < | >= | <=
|
|
266
|
+
|
|
267
|
+
# <expression> ::= <literal>
|
|
268
|
+
# | <column_name>
|
|
269
|
+
# | <function_call>
|
|
270
|
+
# | ( <expression> )
|
|
271
|
+
# | <expression> <arithmetic_operator> <expression>
|
|
272
|
+
# | ... (other expressions)
|
|
273
|
+
|
|
274
|
+
# <literal> ::= <numeric_literal> | <string_literal> | <boolean_literal> | <date_literal> | ...
|
|
275
|
+
|
|
276
|
+
# <column_name> ::= <identifier>
|
|
277
|
+
|
|
278
|
+
# <identifier> ::= <letter> { <letter> | <digit> | _ }...
|
|
279
|
+
|
|
280
|
+
# <pattern> ::= <string_literal>
|
|
281
|
+
|
|
282
|
+
# <escape_character> ::= <string_literal> (single character)
|
|
283
|
+
|
|
284
|
+
# <expression_list> ::= <expression> { , <expression> }...
|
|
285
|
+
' > delete > delete',
|
|
286
|
+
'delete_ > from > delete_from ^ from',
|
|
287
|
+
'delete_from_ > name|audit > delete_from_x ^ tables',
|
|
288
|
+
'delete_from_x_ > where > update_where ^ where',
|
|
289
|
+
|
|
290
|
+
# <alter table action> ::=
|
|
291
|
+
# ADD <column definition>
|
|
292
|
+
# | DROP COLUMN <column name>
|
|
293
|
+
# | MODIFY COLUMN <column name> <column modification>
|
|
294
|
+
# | RENAME TO <new table name>
|
|
295
|
+
# | ADD CONSTRAINT <constraint definition>
|
|
296
|
+
# | DROP CONSTRAINT <constraint name>
|
|
297
|
+
# | ... (other actions like adding/dropping indexes, partitions, etc.)
|
|
298
|
+
|
|
299
|
+
# <column definition> ::= <column name> <data type> [ <column constraint> ... ]
|
|
300
|
+
|
|
301
|
+
# <column modification> ::=
|
|
302
|
+
# SET DATA TYPE <data type>
|
|
303
|
+
# | SET DEFAULT <expression>
|
|
304
|
+
# | DROP DEFAULT
|
|
305
|
+
# | SET NOT NULL
|
|
306
|
+
# | DROP NOT NULL
|
|
307
|
+
# | ...
|
|
308
|
+
|
|
309
|
+
# <constraint definition> ::=
|
|
310
|
+
# PRIMARY KEY ( <column name list> )
|
|
311
|
+
# | UNIQUE ( <column name list> )
|
|
312
|
+
# | FOREIGN KEY ( <column name list> ) REFERENCES <referenced table> ( <referenced column list> )
|
|
313
|
+
# | CHECK ( <search condition> )
|
|
314
|
+
|
|
315
|
+
' > alter > alter',
|
|
316
|
+
'alter_ > table > alter_table ^ table',
|
|
317
|
+
'alter_table_ > name|audit|cluster > alter_table_t ^ tables',
|
|
318
|
+
'alter_table_t_ > add > alter_table_add ^ add,add constraint,drop column,drop constraint,rename to',
|
|
319
|
+
'- > drop > alter_table_drop',
|
|
320
|
+
|
|
321
|
+
' > preview > preview',
|
|
322
|
+
'preview_ > name|audit > preview_t ^ tables',
|
|
323
|
+
]
|
|
324
|
+
|
|
325
|
+
SQL_KEYWORDS = [
|
|
326
|
+
'select', 'from', 'as', 'not', 'in', 'where',
|
|
327
|
+
'and', 'or', 'group', 'by', 'group by', 'order', 'order by', 'limit', 'asc', 'desc',
|
|
328
|
+
'inner join', 'on', 'left', 'right', 'full', 'outer', 'left outer join',
|
|
329
|
+
'left join', 'right outer join', 'right join', 'full join', 'full outer join',
|
|
330
|
+
'insert', 'into', 'values',
|
|
331
|
+
'update', 'where', 'set',
|
|
332
|
+
'delete',
|
|
333
|
+
'audit', 'cluster',
|
|
334
|
+
'alter', 'table', 'tables', 'add', 'drop', 'with',
|
|
335
|
+
'describe', 'preview'
|
|
336
|
+
]
|
|
337
|
+
|
|
338
|
+
EXPANDABLE_NAMES = {'tables', 'columns', 'partition-columns', 'table-props', 'table-props-values'}
|
|
339
|
+
|
|
340
|
+
CQL_SPEC = SQL_SPEC + [
|
|
341
|
+
' > select > select ^ select,insert,update,delete,alter,describe,preview,consistency',
|
|
342
|
+
|
|
343
|
+
# ALTER TABLE [ <keyspace_name> . ] <table_name>
|
|
344
|
+
# ( ALTER <column_name> TYPE <cql_type>
|
|
345
|
+
# | ADD ( <column_definition_list> )
|
|
346
|
+
# | DROP ( <column_list> )
|
|
347
|
+
# | RENAME <column_name> TO <column_name> [ AND <column_name> TO <column_name> ... ]
|
|
348
|
+
# | WITH <table_properties> );
|
|
349
|
+
|
|
350
|
+
'alter_ > table > alter_table ^ table,`tables`',
|
|
351
|
+
'- > tables > alter_tables',
|
|
352
|
+
'alter_tables_ > with > alter_table_with ^ with',
|
|
353
|
+
'alter_table_t_ > with > alter_table_with ^ with,add,drop',
|
|
354
|
+
'alter_table_with_ > name > alter_table_with_p ^ table-props',
|
|
355
|
+
'alter_table_with_p > comparison > alter_table_with_p_op ^ =',
|
|
356
|
+
'alter_table_with_p_op > name|single|num > alter_table_with_p_op_v ^ table-prop-values',
|
|
357
|
+
'alter_table_with_p_op_v_ > --include-reaper > alter_table_with_p_op_v_$ ^ --include-reaper',
|
|
358
|
+
|
|
359
|
+
' > describe > describe',
|
|
360
|
+
'describe_ > table > desc_table ^ table,`tables`,keyspace,keyspaces,schema',
|
|
361
|
+
'- > tables > desc_tables',
|
|
362
|
+
'- > keyspace > desc_keyspace',
|
|
363
|
+
'- > keyspaces > desc_keyspaces',
|
|
364
|
+
'- > schema > desc_schema',
|
|
365
|
+
'desc_table_ > name > desc_table_t ^ tables',
|
|
366
|
+
'desc_table_t_ > & > desc_table_t_$ ^ &',
|
|
367
|
+
'desc_tables_ > & > desc_tables_$ ^ &',
|
|
368
|
+
'desc_keyspace_ > name > desc_keyspace_k',
|
|
369
|
+
'desc_keyspace_k_ > & > desc_keyspace_k_$ ^ &',
|
|
370
|
+
'desc_schema_ > & > desc_schema_$ ^ &',
|
|
371
|
+
|
|
372
|
+
' > export > export',
|
|
373
|
+
'export_ > name > export_table ^ with,tables',
|
|
374
|
+
'- > with > export_with',
|
|
375
|
+
'export_table > ( > export_table_lp_ ^ (,comma,with,tables',
|
|
376
|
+
'- > , > export',
|
|
377
|
+
'- > . > export_table ^ tables',
|
|
378
|
+
'export_table_ > ( > export_table_lp_ ^ as,(,comma,with consistency',
|
|
379
|
+
'- > , > export',
|
|
380
|
+
'- > as > export_as',
|
|
381
|
+
'- > with > export_with',
|
|
382
|
+
'export_table_lp_ > name > export_table_lp_a ^ columns',
|
|
383
|
+
'export_table_lp_a > , > export_table_lp_a_comma_',
|
|
384
|
+
'- > ) > export_table_lp_a_comma_rp_',
|
|
385
|
+
'export_table_lp_a_comma_ > name > export_table_lp_a ^ columns',
|
|
386
|
+
'export_table_lp_a_comma_rp_ > as > export_as ^ as,with consistency',
|
|
387
|
+
'- > , > export ^ with consistency',
|
|
388
|
+
'- > with > export_with',
|
|
389
|
+
'export_as_ > name > export_as_f',
|
|
390
|
+
'export_as_f > , > export',
|
|
391
|
+
'export_as_f_ > , > export ^ with consistency',
|
|
392
|
+
'- > with > export_with',
|
|
393
|
+
'export_with_ > consistency > export_with_consistency ^ consistency',
|
|
394
|
+
'export_with_consistency_ > quorum|all|serial|one|each_quorum|local_quorum|any|local_one|two|three|local_serial > export_with_quorum ^ quorum,all,serial,one,each_quorum,local_quorum,any,local_one,two,three,local_serial',
|
|
395
|
+
|
|
396
|
+
' > consistency > consistency',
|
|
397
|
+
'consistency_ > quorum|all|serial|one|each_quorum|local_quorum|any|local_one|two|three|local_serial > consistency_quorum ^ quorum,all,serial,one,each_quorum,local_quorum,any,local_one,two,three,local_serial',
|
|
398
|
+
'consistency_quorum > ; > '
|
|
399
|
+
]
|
|
400
|
+
|
|
401
|
+
CQL_KEYWORDS = SQL_KEYWORDS + [
|
|
402
|
+
'schema', 'keyspace', 'keyspaces', 'tables', 'export', 'consistency',
|
|
403
|
+
'quorum', 'all', 'serial', 'one', 'each_quorum', 'local_quorum', 'any', 'local_one', 'two', 'three', 'local_serial', 'to'
|
|
404
|
+
]
|
|
405
|
+
|
|
406
|
+
ATHENA_SPEC = SQL_SPEC + [
|
|
407
|
+
' > select > select ^ select,insert,update,delete,alter,describe,preview',
|
|
408
|
+
' > &select > select ^ select,insert,update,delete,alter,describe,preview',
|
|
409
|
+
|
|
410
|
+
'alter_table_t_ > add > alter_table_add ^ add partition,drop partition',
|
|
411
|
+
'alter_table_add_ > partition > alter_partition ^ partition',
|
|
412
|
+
'alter_table_drop_ > partition > alter_partition ^ partition',
|
|
413
|
+
'alter_partition > ( > alter_partition_lp ^ (',
|
|
414
|
+
'alter_partition_lp > name > alter_partition_lp_a ^ partition-columns',
|
|
415
|
+
'alter_partition_lp_a > comparison > alter_partition_lp_a_op ^ =',
|
|
416
|
+
'alter_partition_lp_a_op > single > alter_partition_lp_a_op_v ^ single',
|
|
417
|
+
'alter_partition_lp_a_op_v > , > alter_partition_lp_sc ^ single',
|
|
418
|
+
'alter_partition_lp_sc > name|) > alter_partition_lp_a ^ partition-columns',
|
|
419
|
+
|
|
420
|
+
' > describe > describe',
|
|
421
|
+
'describe_ > name > desc_t ^ tables',
|
|
422
|
+
'desc_t_ > name > desc_t_',
|
|
423
|
+
|
|
424
|
+
'repair'
|
|
425
|
+
]
|
|
426
|
+
|
|
427
|
+
ATHENA_KEYWORDS = SQL_KEYWORDS + [
|
|
428
|
+
'partition', '&select'
|
|
429
|
+
]
|
|
430
|
+
|
|
431
|
+
class SqlStateMachine(StateMachine[Token]):
|
|
432
|
+
def __init__(self, indent=0, push_level = 0, debug = False):
|
|
433
|
+
super().__init__(indent, push_level, debug)
|
|
434
|
+
|
|
435
|
+
def traverse_tokens(self, tokens: list[Token], state: State = State('')):
|
|
436
|
+
def handle_push():
|
|
437
|
+
if f'{state.state} > {it}' in self.states:
|
|
438
|
+
state_test = self.states[f'{state.state} > {it}']
|
|
439
|
+
if state_test.comeback_token:
|
|
440
|
+
self.comebacks[self.push_level] = state_test.comeback_state
|
|
441
|
+
|
|
442
|
+
def handle_pop():
|
|
443
|
+
if self.push_level in self.comebacks:
|
|
444
|
+
try:
|
|
445
|
+
return State(self.comebacks[self.push_level])
|
|
446
|
+
finally:
|
|
447
|
+
del self.comebacks[self.push_level]
|
|
448
|
+
|
|
449
|
+
return None
|
|
450
|
+
|
|
451
|
+
for token in tokens:
|
|
452
|
+
if self.debug:
|
|
453
|
+
if token.ttype == TOKEN.Whitespace:
|
|
454
|
+
print('_ ', end='')
|
|
455
|
+
elif token.ttype in [TOKEN.DML, TOKEN.Wildcard, TOKEN.Punctuation, TOKEN.CTE]:
|
|
456
|
+
print(f'{token.value} ', end='')
|
|
457
|
+
elif token.ttype:
|
|
458
|
+
tks = str(token.ttype).split('.')
|
|
459
|
+
typ = tks[len(tks) - 1]
|
|
460
|
+
if ' ' in token.value:
|
|
461
|
+
print(f'"{token.value}:{typ}" ', end='')
|
|
462
|
+
else:
|
|
463
|
+
print(f'{token.value}:{typ} ', end='')
|
|
464
|
+
# print(" " * self.indent + f"Token: {token.value}, Type: {token.ttype}@{token.ttype.__class__}")
|
|
465
|
+
|
|
466
|
+
last_name = None
|
|
467
|
+
if token.is_group:
|
|
468
|
+
state = self.traverse_tokens(token.tokens, state)
|
|
469
|
+
else:
|
|
470
|
+
comeback_state = None
|
|
471
|
+
|
|
472
|
+
it = ''
|
|
473
|
+
if (t := token.value.lower()) in self.keywords():
|
|
474
|
+
it = t
|
|
475
|
+
elif token.ttype == TOKEN.Text.Whitespace:
|
|
476
|
+
it = '_'
|
|
477
|
+
elif token.ttype == TOKEN.Name:
|
|
478
|
+
it = 'name'
|
|
479
|
+
last_name = token.value
|
|
480
|
+
elif token.ttype == TOKEN.Literal.String.Single:
|
|
481
|
+
it = 'single'
|
|
482
|
+
elif token.ttype in [TOKEN.Literal.Number.Integer, TOKEN.Literal.Number.Float]:
|
|
483
|
+
it = 'num'
|
|
484
|
+
elif token.ttype == TOKEN.Wildcard:
|
|
485
|
+
it = '*'
|
|
486
|
+
elif token.ttype == TOKEN.Punctuation:
|
|
487
|
+
it = token.value
|
|
488
|
+
|
|
489
|
+
if it == '(':
|
|
490
|
+
handle_push()
|
|
491
|
+
self.push_level += 1
|
|
492
|
+
elif it == ')':
|
|
493
|
+
self.push_level -= 1
|
|
494
|
+
comeback_state = handle_pop()
|
|
495
|
+
elif it == '.' and 'last_name' in state.context and (ln := state.context['last_name']):
|
|
496
|
+
state.context['last_namespace'] = ln
|
|
497
|
+
|
|
498
|
+
elif token.ttype == TOKEN.Operator.Comparison:
|
|
499
|
+
it = 'comparison'
|
|
500
|
+
|
|
501
|
+
try:
|
|
502
|
+
# print(f'\n{state.to_s} > {it} > ', end='')
|
|
503
|
+
if comeback_state:
|
|
504
|
+
state = comeback_state
|
|
505
|
+
else:
|
|
506
|
+
context = state.context
|
|
507
|
+
state = self.states[f'{state.state} > {it}']
|
|
508
|
+
state.context = context
|
|
509
|
+
|
|
510
|
+
if last_name:
|
|
511
|
+
state.context['last_name'] = last_name
|
|
512
|
+
except:
|
|
513
|
+
pass
|
|
514
|
+
|
|
515
|
+
return state
|
|
516
|
+
|
|
517
|
+
def spec(self):
|
|
518
|
+
return SQL_SPEC
|
|
519
|
+
|
|
520
|
+
def keywords(self):
|
|
521
|
+
return SQL_KEYWORDS
|
|
522
|
+
|
|
523
|
+
def expandable_names(self):
|
|
524
|
+
return EXPANDABLE_NAMES
|
|
525
|
+
|
|
526
|
+
def witespace_transition_condition(self, from_s: str, to_s: str):
|
|
527
|
+
return from_s.endswith('_') and not from_s.endswith('_comma_') and not from_s.endswith('_lp_') and not from_s.endswith('_rp_')
|
|
528
|
+
|
|
529
|
+
def incomplete_name_transition_condition(self, from_s: str, token: str, to_s: str, suggestions: str):
|
|
530
|
+
if not suggestions:
|
|
531
|
+
return None
|
|
532
|
+
|
|
533
|
+
tokens = [token]
|
|
534
|
+
if '|' in token:
|
|
535
|
+
tokens = token.split('|')
|
|
536
|
+
|
|
537
|
+
if 'name' not in tokens:
|
|
538
|
+
return None
|
|
539
|
+
|
|
540
|
+
if not self.expandable_names().intersection(set(suggestions.split(','))):
|
|
541
|
+
return None
|
|
542
|
+
|
|
543
|
+
return tokens
|
|
544
|
+
|
|
545
|
+
class CqlStateMachine(SqlStateMachine):
|
|
546
|
+
def __init__(self, indent=0, push_level = 0, debug = False):
|
|
547
|
+
super().__init__(indent, push_level, debug)
|
|
548
|
+
|
|
549
|
+
def spec(self):
|
|
550
|
+
return CQL_SPEC
|
|
551
|
+
|
|
552
|
+
def keywords(self):
|
|
553
|
+
return CQL_KEYWORDS
|
|
554
|
+
|
|
555
|
+
class AthenaStateMachine(SqlStateMachine):
|
|
556
|
+
def __init__(self, indent=0, push_level = 0, debug = False):
|
|
557
|
+
super().__init__(indent, push_level, debug)
|
|
558
|
+
|
|
559
|
+
def spec(self):
|
|
560
|
+
return ATHENA_SPEC
|
|
561
|
+
|
|
562
|
+
def keywords(self):
|
|
563
|
+
return ATHENA_KEYWORDS
|
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]:
|