kaqing 2.0.50__py3-none-any.whl → 2.0.110__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.

Files changed (123) hide show
  1. adam/apps.py +2 -2
  2. adam/batch.py +11 -15
  3. adam/checks/check_utils.py +4 -4
  4. adam/checks/compactionstats.py +1 -1
  5. adam/checks/cpu.py +2 -2
  6. adam/checks/disk.py +1 -1
  7. adam/checks/gossip.py +1 -1
  8. adam/checks/memory.py +3 -3
  9. adam/checks/status.py +1 -1
  10. adam/commands/alter_tables.py +3 -14
  11. adam/commands/app.py +2 -2
  12. adam/commands/app_ping.py +2 -2
  13. adam/commands/audit/audit.py +85 -0
  14. adam/commands/audit/audit_repair_tables.py +76 -0
  15. adam/commands/audit/audit_run.py +57 -0
  16. adam/commands/audit/show_last10.py +50 -0
  17. adam/commands/audit/show_slow10.py +49 -0
  18. adam/commands/audit/show_top10.py +48 -0
  19. adam/commands/audit/utils_show_top10.py +59 -0
  20. adam/commands/bash.py +76 -13
  21. adam/commands/cd.py +22 -13
  22. adam/commands/check.py +6 -0
  23. adam/commands/cli_commands.py +3 -3
  24. adam/commands/command.py +15 -11
  25. adam/commands/commands_utils.py +4 -5
  26. adam/commands/cql/cql_completions.py +7 -5
  27. adam/commands/cql/cql_utils.py +13 -10
  28. adam/commands/cql/cqlsh.py +6 -3
  29. adam/commands/deploy/code_utils.py +2 -2
  30. adam/commands/deploy/deploy.py +7 -1
  31. adam/commands/deploy/deploy_pg_agent.py +2 -2
  32. adam/commands/deploy/deploy_pod.py +6 -6
  33. adam/commands/deploy/deploy_utils.py +2 -2
  34. adam/commands/deploy/undeploy.py +7 -1
  35. adam/commands/deploy/undeploy_pg_agent.py +2 -2
  36. adam/commands/deploy/undeploy_pod.py +4 -4
  37. adam/commands/devices.py +29 -0
  38. adam/commands/help.py +10 -7
  39. adam/commands/issues.py +6 -0
  40. adam/commands/login.py +6 -3
  41. adam/commands/logs.py +2 -1
  42. adam/commands/ls.py +30 -24
  43. adam/commands/medusa/medusa_backup.py +2 -2
  44. adam/commands/medusa/medusa_restore.py +2 -2
  45. adam/commands/medusa/medusa_show_backupjobs.py +3 -2
  46. adam/commands/medusa/medusa_show_restorejobs.py +2 -2
  47. adam/commands/nodetool.py +5 -3
  48. adam/commands/postgres/postgres.py +3 -3
  49. adam/commands/postgres/{postgres_session.py → postgres_context.py} +29 -30
  50. adam/commands/postgres/postgres_utils.py +5 -5
  51. adam/commands/postgres/psql_completions.py +2 -3
  52. adam/commands/preview_table.py +17 -32
  53. adam/commands/pwd.py +5 -2
  54. adam/commands/reaper/reaper.py +3 -0
  55. adam/commands/reaper/reaper_restart.py +1 -1
  56. adam/commands/reaper/reaper_session.py +1 -1
  57. adam/commands/repair/repair.py +3 -3
  58. adam/commands/repair/repair_log.py +1 -1
  59. adam/commands/repair/repair_run.py +2 -2
  60. adam/commands/repair/repair_scan.py +1 -1
  61. adam/commands/repair/repair_stop.py +1 -1
  62. adam/commands/report.py +6 -0
  63. adam/commands/restart.py +2 -2
  64. adam/commands/rollout.py +1 -1
  65. adam/commands/show/show.py +5 -2
  66. adam/commands/show/show_app_actions.py +3 -0
  67. adam/commands/show/show_app_id.py +1 -1
  68. adam/commands/show/show_app_queues.py +3 -2
  69. adam/commands/show/show_cassandra_status.py +3 -3
  70. adam/commands/show/show_cassandra_version.py +3 -3
  71. adam/commands/show/show_host.py +33 -0
  72. adam/commands/show/show_login.py +3 -0
  73. adam/commands/show/show_processes.py +1 -1
  74. adam/commands/show/show_repairs.py +2 -2
  75. adam/commands/show/show_storage.py +1 -1
  76. adam/commands/watch.py +1 -1
  77. adam/config.py +2 -1
  78. adam/embedded_params.py +1 -1
  79. adam/pod_exec_result.py +7 -2
  80. adam/repl.py +141 -89
  81. adam/repl_commands.py +21 -20
  82. adam/repl_state.py +167 -39
  83. adam/sql/sql_completer.py +89 -49
  84. adam/sql/sql_state_machine.py +518 -0
  85. adam/sql/term_completer.py +76 -0
  86. adam/sso/cred_cache.py +1 -1
  87. adam/sso/idp.py +1 -1
  88. adam/utils.py +0 -1
  89. adam/utils_audits.py +193 -0
  90. adam/{k8s_utils → utils_k8s}/cassandra_clusters.py +6 -8
  91. adam/{k8s_utils → utils_k8s}/cassandra_nodes.py +11 -4
  92. adam/{k8s_utils → utils_k8s}/deployment.py +2 -2
  93. adam/{k8s_utils → utils_k8s}/pods.py +33 -9
  94. adam/{k8s_utils → utils_k8s}/secrets.py +4 -0
  95. adam/{k8s_utils → utils_k8s}/statefulsets.py +4 -4
  96. adam/utils_net.py +24 -0
  97. adam/version.py +1 -1
  98. {kaqing-2.0.50.dist-info → kaqing-2.0.110.dist-info}/METADATA +1 -1
  99. kaqing-2.0.110.dist-info/RECORD +187 -0
  100. adam/commands/cql/cql_table_completer.py +0 -16
  101. adam/commands/describe/describe.py +0 -46
  102. adam/commands/describe/describe_keyspace.py +0 -60
  103. adam/commands/describe/describe_keyspaces.py +0 -50
  104. adam/commands/describe/describe_table.py +0 -60
  105. adam/commands/describe/describe_tables.py +0 -50
  106. adam/commands/postgres/psql_table_completer.py +0 -18
  107. adam/sql/any_completer.py +0 -84
  108. adam/sql/sql_utils.py +0 -5
  109. adam/sql/table_name_completer.py +0 -17
  110. kaqing-2.0.50.dist-info/RECORD +0 -185
  111. /adam/commands/{describe → audit}/__init__.py +0 -0
  112. /adam/{k8s_utils → utils_k8s}/__init__.py +0 -0
  113. /adam/{k8s_utils → utils_k8s}/config_maps.py +0 -0
  114. /adam/{k8s_utils → utils_k8s}/custom_resources.py +0 -0
  115. /adam/{k8s_utils → utils_k8s}/ingresses.py +0 -0
  116. /adam/{k8s_utils → utils_k8s}/jobs.py +0 -0
  117. /adam/{k8s_utils → utils_k8s}/kube_context.py +0 -0
  118. /adam/{k8s_utils → utils_k8s}/service_accounts.py +0 -0
  119. /adam/{k8s_utils → utils_k8s}/services.py +0 -0
  120. /adam/{k8s_utils → utils_k8s}/volumes.py +0 -0
  121. {kaqing-2.0.50.dist-info → kaqing-2.0.110.dist-info}/WHEEL +0 -0
  122. {kaqing-2.0.50.dist-info → kaqing-2.0.110.dist-info}/entry_points.txt +0 -0
  123. {kaqing-2.0.50.dist-info → kaqing-2.0.110.dist-info}/top_level.txt +0 -0
@@ -0,0 +1,518 @@
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
+ 'select_from_sq_ > as > select_from_x_as ^ as',
77
+ 'select_from_x_comma_ > name|audit > select_from_x ^ tables',
78
+ 'select_from_x_ ^ as,where,inner join,left outer join,right outer join,full outer join,group by,order by,limit',
79
+ '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',
80
+ '- > as > select_from_x_as',
81
+ '- > where > select_where',
82
+ '- > order > select_order',
83
+ '- > order by > select_order_by',
84
+ '- > limit > select_where_sc_limit',
85
+ '- > group > select_group',
86
+ '- > group by > select_group_by',
87
+ '- > inner > select_from_x_inner',
88
+ '- > inner join > select_join',
89
+ '- > left > select_from_x_left',
90
+ '- > left join > select_join',
91
+ '- > left outer join > select_join',
92
+ '- > right > select_from_x_right',
93
+ '- > right join > select_join',
94
+ '- > right outer join > select_join',
95
+ '- > full > select_from_x_full',
96
+ '- > full outer join > select_join',
97
+ 'select_from_x_as_ > name > select_from_x_as_x ^ x,y,z',
98
+ 'select_from_x_as_x > , > select_from_x_as_x_comma_',
99
+ 'select_from_x_as_x_comma_ > name|audit > select_from_x ^ tables',
100
+ 'select_where_ > name > select_where_a ^ columns',
101
+ 'select_where_a > name > select_where_a ^ columns,=,<,<=,>,>=,<>',
102
+ '- > comparison > select_where_a_op',
103
+ 'select_where_a_ > comparison > select_where_a_op ^ =,<,<=,>,>=,<>,like,not,in',
104
+ '- > not > select_where_a_not',
105
+ '- > in > select_where_a_in',
106
+ 'select_where_a_not_ > comparison > select_where_a_not_op ^ like,in',
107
+ '- > in > select_where_a_in',
108
+ 'select_where_a_in > ( > select_where_a_in_lp_ ^ (',
109
+ '- < ) > select_where_sc',
110
+ 'select_where_a_in_lp_ > name|single|num > select_where_a_in_lp_a ^ single,select',
111
+ '- > select > select_where_a_in_lp_select',
112
+ 'select_where_a_in_lp_select_ > name > select_a ^ id',
113
+ 'select_where_a_in_lp_a > , > select_where_a_in_lp_a_comma_ ^ comma,)',
114
+ 'select_where_a_in_lp_a_comma_ > name|single|num > select_where_a_in_lp_a ^ single',
115
+ 'select_where_a_not_op > name|single|num > select_where_sc ^ single',
116
+ 'select_where_a_op > name|single|num > select_where_sc ^ single',
117
+ 'select_where_sc_ > and|or > select_where ^ and,or,order by,group by,limit',
118
+ '- > group > select_group',
119
+ '- > group by > select_group_by',
120
+ '- > order > select_order',
121
+ '- > order by > select_order_by',
122
+ '- > limit > select_where_sc_limit',
123
+ 'select_group_ > by > select_group_by ^ by',
124
+ 'select_group_by_ > name > select_group_by_a ^ columns',
125
+ 'select_group_by_a > , > select_group_by_a_comma_ ^ columns',
126
+ 'select_group_by_a_comma_ > name > select_group_by_a ^ columns',
127
+ 'select_group_by_a_ > limit > select_where_sc_limit ^ limit,order by',
128
+ '- > order > select_order',
129
+ '- > order by > select_order_by',
130
+ 'select_order_ > by > select_order_by ^ by',
131
+ 'select_order_by_ > name > select_order_by_a ^ columns',
132
+ 'select_order_by_a > , > 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|audit > 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_ > as > select_x_join_y_as ^ as,on',
152
+ '- > on > select_x_join_y_on ^ as,on',
153
+ 'select_x_join_y_as_ > name > select_x_join_y_as_y ^ x,y,z',
154
+ 'select_x_join_y_as_y_ > on > select_x_join_y_on ^ on',
155
+ 'select_x_join_y_on_ > name > select_x_join_y_on_a ^ columns',
156
+ 'select_x_join_y_on_a > name > select_x_join_y_on_a ^ columns,=',
157
+ '- > comparison > select_x_join_y_on_a_op',
158
+ 'select_x_join_y_on_a_ > comparison > select_x_join_y_on_a_op ^ =',
159
+ 'select_x_join_y_on_a_op > name > select_x_join_y_on_a_op_b ^ columns',
160
+ 'select_x_join_y_on_a_op_b > _ > select_from_x_as_x_',
161
+
162
+ # <insert_statement> ::= INSERT INTO <table_name> [ ( <column_list> ) ]
163
+ # VALUES ( <value_list> )
164
+ # | INSERT INTO <table_name> [ ( <column_list> ) ]
165
+ # <query_expression>
166
+
167
+ # <table_name> ::= <identifier>
168
+
169
+ # <column_list> ::= <column_name> [ , <column_list> ]
170
+
171
+ # <column_name> ::= <identifier>
172
+
173
+ # <value_list> ::= <expression> [ , <value_list> ]
174
+
175
+ # <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> ]
176
+ ' > insert > insert',
177
+ 'insert_ > into > insert_into ^ into',
178
+ 'insert_into_ > name|audit > insert_into_x ^ tables',
179
+ 'insert_into_x > ( > insert_into_x_lp_',
180
+ 'insert_into_x_ > ( > insert_into_x_lp_ ^ (,values(',
181
+ '- > values > insert_values',
182
+ 'insert_into_x_lp_ > name > insert_into_x_lp_a ^ id',
183
+ 'insert_into_x_lp_a > , > insert_into_x_lp_a_comma_',
184
+ '- > ) > insert_into_x_lp_a_rp_',
185
+ 'insert_into_x_lp_a_comma_ > name > insert_into_x_lp_a ^ id',
186
+ 'insert_into_x_lp_a_rp__ > values > insert_values ^ values(,select',
187
+ '- > select > select',
188
+ 'insert_values > ( > insert_values_lp_',
189
+ 'insert_values_lp_ > name|single|num > insert_values_lp_v ^ single',
190
+ 'insert_values_lp_v > , > insert_values_lp_v_comma_',
191
+ 'insert_values_lp_v_comma_ > name|single|num > insert_values_lp_v',
192
+
193
+ # <update_statement> ::= UPDATE <table_name>
194
+ # SET <set_clause_list>
195
+ # [WHERE <search_condition>]
196
+
197
+ # <set_clause_list> ::= <set_clause> { , <set_clause> }
198
+
199
+ # <set_clause> ::= <column_name> = <update_value>
200
+
201
+ # <update_value> ::= <expression> | NULL | DEFAULT
202
+
203
+ # <search_condition> ::= <boolean_expression>
204
+ ' > update > update',
205
+ 'update_ > name|audit > update_x ^ tables',
206
+ 'update_x_ > set > update_set ^ set',
207
+ 'update_set_ > name > update_set_a ^ id',
208
+ 'update_set_a > comparison > update_set_a_op',
209
+ 'update_set_a_op > name|single|num > update_set_sc ^ single',
210
+ 'update_set_sc > , > update_set_sc_comma_',
211
+ 'update_set_sc_comma_ > name > update_set_a ^ id',
212
+ 'update_set_sc_ > , > update_set_sc_comma_ ^ where',
213
+ '- > where > update_where',
214
+ 'update_where_ > name > update_where_a ^ id',
215
+ 'update_where_a > comparison > update_where_a_op',
216
+ 'update_where_a_ > comparison > update_where_a_op ^ =,<,<=,>,>=,<>,like,not,in',
217
+ '- > not > update_where_a_not',
218
+ '- > in > update_where_a_in',
219
+ 'update_where_a_not_ > comparison > update_where_a_not_op ^ like,in',
220
+ '- > in > update_where_a_in',
221
+ 'update_where_a_in > ( > update_where_a_in_lp_ ^ (',
222
+ '- < ) > update_where_sc',
223
+ 'update_where_a_in_lp_ > name|single|num > update_where_a_in_lp_a ^ single,select',
224
+ '- > select > update_where_a_in_lp_select',
225
+ 'update_where_a_in_lp_select_ > name > select_a ^ id',
226
+ 'update_where_a_in_lp_a > , > update_where_a_in_lp_a_comma_ ^ comma,)',
227
+ 'update_where_a_in_lp_a_comma_ > name|single|num > update_where_a_in_lp_a ^ single',
228
+ 'update_where_a_not_op > name|single|num > update_where_sc ^ single',
229
+ 'update_where_a_op > name|single|num > update_where_sc ^ single',
230
+ 'update_where_sc_ > and|or > update_where ^ and,or',
231
+
232
+ # <delete_statement> ::= DELETE FROM <table_name> [ WHERE <search_condition> ]
233
+
234
+ # <table_name> ::= <identifier>
235
+
236
+ # <search_condition> ::= <boolean_expression>
237
+
238
+ # <boolean_expression> ::= <predicate>
239
+ # | <boolean_expression> AND <predicate>
240
+ # | <boolean_expression> OR <predicate>
241
+ # | NOT <predicate>
242
+ # | ( <boolean_expression> )
243
+
244
+ # <predicate> ::= <expression> <comparison_operator> <expression>
245
+ # | <expression> IS NULL
246
+ # | <expression> IS NOT NULL
247
+ # | <expression> LIKE <pattern> [ ESCAPE <escape_character> ]
248
+ # | <expression> IN ( <expression_list> )
249
+ # | EXISTS ( <select_statement> )
250
+ # | ... (other predicates)
251
+
252
+ # <comparison_operator> ::= = | <> | != | > | < | >= | <=
253
+
254
+ # <expression> ::= <literal>
255
+ # | <column_name>
256
+ # | <function_call>
257
+ # | ( <expression> )
258
+ # | <expression> <arithmetic_operator> <expression>
259
+ # | ... (other expressions)
260
+
261
+ # <literal> ::= <numeric_literal> | <string_literal> | <boolean_literal> | <date_literal> | ...
262
+
263
+ # <column_name> ::= <identifier>
264
+
265
+ # <identifier> ::= <letter> { <letter> | <digit> | _ }...
266
+
267
+ # <pattern> ::= <string_literal>
268
+
269
+ # <escape_character> ::= <string_literal> (single character)
270
+
271
+ # <expression_list> ::= <expression> { , <expression> }...
272
+ ' > delete > delete',
273
+ 'delete_ > from > delete_from ^ from',
274
+ 'delete_from_ > name|audit > delete_from_x ^ tables',
275
+ 'delete_from_x_ > where > update_where ^ where',
276
+
277
+ # <alter table action> ::=
278
+ # ADD <column definition>
279
+ # | DROP COLUMN <column name>
280
+ # | MODIFY COLUMN <column name> <column modification>
281
+ # | RENAME TO <new table name>
282
+ # | ADD CONSTRAINT <constraint definition>
283
+ # | DROP CONSTRAINT <constraint name>
284
+ # | ... (other actions like adding/dropping indexes, partitions, etc.)
285
+
286
+ # <column definition> ::= <column name> <data type> [ <column constraint> ... ]
287
+
288
+ # <column modification> ::=
289
+ # SET DATA TYPE <data type>
290
+ # | SET DEFAULT <expression>
291
+ # | DROP DEFAULT
292
+ # | SET NOT NULL
293
+ # | DROP NOT NULL
294
+ # | ...
295
+
296
+ # <constraint definition> ::=
297
+ # PRIMARY KEY ( <column name list> )
298
+ # | UNIQUE ( <column name list> )
299
+ # | FOREIGN KEY ( <column name list> ) REFERENCES <referenced table> ( <referenced column list> )
300
+ # | CHECK ( <search condition> )
301
+
302
+ ' > alter > alter',
303
+ 'alter_ > table > alter_table ^ table',
304
+ 'alter_table_ > name|audit|cluster > alter_table_t ^ tables',
305
+ 'alter_table_t_ > add > alter_table_add ^ add,add constraint,drop column,drop constraint,rename to',
306
+ '- > drop > alter_table_drop',
307
+
308
+ ' > preview > preview',
309
+ 'preview_ > name|audit > preview_t ^ tables',
310
+ ]
311
+
312
+ SQL_KEYWORDS = [
313
+ 'select', 'from', 'as', 'not', 'in', 'where',
314
+ 'and', 'or', 'group', 'by', 'group by', 'order', 'order by', 'limit', 'asc', 'desc',
315
+ 'inner join', 'on', 'left', 'right', 'full', 'outer', 'left outer join',
316
+ 'left join', 'right outer join', 'right join', 'full join', 'full outer join',
317
+ 'insert', 'into', 'values',
318
+ 'update', 'where', 'set',
319
+ 'delete',
320
+ 'audit', 'cluster',
321
+ 'alter', 'table', 'tables', 'add', 'drop', 'with',
322
+ 'describe', 'preview'
323
+ ]
324
+
325
+ EXPANDABLE_NAMES = {'tables', 'columns', 'partition-columns', 'table-props', 'table-props-values'}
326
+
327
+ CQL_SPEC = SQL_SPEC + [
328
+ ' > select > select ^ select,insert,update,delete,alter,describe,preview',
329
+
330
+ # ALTER TABLE [ <keyspace_name> . ] <table_name>
331
+ # ( ALTER <column_name> TYPE <cql_type>
332
+ # | ADD ( <column_definition_list> )
333
+ # | DROP ( <column_list> )
334
+ # | RENAME <column_name> TO <column_name> [ AND <column_name> TO <column_name> ... ]
335
+ # | WITH <table_properties> );
336
+
337
+ 'alter_ > table > alter_table ^ table,`tables`',
338
+ '- > tables > alter_tables',
339
+ 'alter_tables_ > with > alter_table_with ^ with',
340
+ 'alter_table_t_ > with > alter_table_with ^ with,add,drop',
341
+ 'alter_table_with_ > name > alter_table_with_p ^ table-props',
342
+ 'alter_table_with_p > comparison > alter_table_with_p_op ^ =',
343
+ 'alter_table_with_p_op > name|single|num > alter_table_with_p_op_v ^ table-prop-values',
344
+ 'alter_table_with_p_op_v_ > --include-reaper > alter_table_with_p_op_v_$ ^ --include-reaper',
345
+
346
+ ' > describe > describe',
347
+ 'describe_ > table > desc_table ^ table,`tables`,keyspace,keyspaces,schema',
348
+ '- > tables > desc_tables',
349
+ '- > keyspace > desc_keyspace',
350
+ '- > keyspaces > desc_keyspaces',
351
+ '- > schema > desc_schema',
352
+ 'desc_table_ > name > desc_table_t ^ tables',
353
+ 'desc_table_t_ > & > desc_table_t_$ ^ &',
354
+ 'desc_tables_ > & > desc_tables_$ ^ &',
355
+ 'desc_keyspace_ > name > desc_keyspace_k',
356
+ 'desc_keyspace_k_ > & > desc_keyspace_k_$ ^ &',
357
+ 'desc_schema_ > & > desc_schema_$ ^ &',
358
+ ]
359
+
360
+ CQL_KEYWORDS = SQL_KEYWORDS + [
361
+ 'schema', 'keyspace', 'keyspaces', 'tables'
362
+ ]
363
+
364
+ ATHENA_SPEC = SQL_SPEC + [
365
+ ' > select > select ^ select,insert,update,delete,alter,describe,preview',
366
+
367
+ 'alter_table_t_ > add > alter_table_add ^ add partition,drop partition',
368
+ 'alter_table_add_ > partition > alter_partition ^ partition',
369
+ 'alter_table_drop_ > partition > alter_partition ^ partition',
370
+ 'alter_partition > ( > alter_partition_lp ^ (',
371
+ 'alter_partition_lp > name > alter_partition_lp_a ^ partition-columns',
372
+ 'alter_partition_lp_a > comparison > alter_partition_lp_a_op ^ =',
373
+ 'alter_partition_lp_a_op > single > alter_partition_lp_a_op_v ^ single',
374
+ 'alter_partition_lp_a_op_v > , > alter_partition_lp_sc ^ single',
375
+ 'alter_partition_lp_sc > name|) > alter_partition_lp_a ^ partition-columns',
376
+
377
+ ' > describe > describe',
378
+ 'describe_ > name > desc_t ^ tables',
379
+ 'desc_t_ > name > desc_t_',
380
+
381
+ 'repair'
382
+ ]
383
+
384
+ ATHENA_KEYWORDS = SQL_KEYWORDS + [
385
+ 'partition'
386
+ ]
387
+
388
+ class SqlStateMachine(StateMachine[Token]):
389
+ def __init__(self, indent=0, push_level = 0, debug = False):
390
+ super().__init__(indent, push_level, debug)
391
+
392
+ def traverse_tokens(self, tokens: list[Token], state: State = State('')):
393
+ def handle_push():
394
+ if f'{state.state} > {it}' in self.states:
395
+ state_test = self.states[f'{state.state} > {it}']
396
+ if state_test.comeback_token:
397
+ self.comebacks[self.push_level] = state_test.comeback_state
398
+
399
+ def handle_pop():
400
+ if self.push_level in self.comebacks:
401
+ try:
402
+ return State(self.comebacks[self.push_level])
403
+ finally:
404
+ del self.comebacks[self.push_level]
405
+
406
+ return None
407
+
408
+ for token in tokens:
409
+ if self.debug:
410
+ if token.ttype == TOKEN.Whitespace:
411
+ print('_ ', end='')
412
+ elif token.ttype in [TOKEN.DML, TOKEN.Wildcard, TOKEN.Punctuation, TOKEN.CTE]:
413
+ print(f'{token.value} ', end='')
414
+ elif token.ttype:
415
+ tks = str(token.ttype).split('.')
416
+ typ = tks[len(tks) - 1]
417
+ if ' ' in token.value:
418
+ print(f'"{token.value}:{typ}" ', end='')
419
+ else:
420
+ print(f'{token.value}:{typ} ', end='')
421
+ # print(" " * self.indent + f"Token: {token.value}, Type: {token.ttype}@{token.ttype.__class__}")
422
+
423
+ last_name = None
424
+ if token.is_group:
425
+ state = self.traverse_tokens(token.tokens, state)
426
+ else:
427
+ comeback_state = None
428
+
429
+ it = ''
430
+ if (t := token.value.lower()) in self.keywords():
431
+ it = t
432
+ elif token.ttype == TOKEN.Text.Whitespace:
433
+ it = '_'
434
+ elif token.ttype == TOKEN.Name:
435
+ it = 'name'
436
+ last_name = token.value
437
+ elif token.ttype == TOKEN.Literal.String.Single:
438
+ it = 'single'
439
+ elif token.ttype in [TOKEN.Literal.Number.Integer, TOKEN.Literal.Number.Float]:
440
+ it = 'num'
441
+ elif token.ttype == TOKEN.Wildcard:
442
+ it = '*'
443
+ elif token.ttype == TOKEN.Punctuation:
444
+ it = token.value
445
+
446
+ if it == '(':
447
+ handle_push()
448
+ self.push_level += 1
449
+ elif it == ')':
450
+ self.push_level -= 1
451
+ comeback_state = handle_pop()
452
+
453
+ elif token.ttype == TOKEN.Operator.Comparison:
454
+ it = 'comparison'
455
+
456
+ try:
457
+ # print(f'\n{state.to_s} > {it} > ', end='')
458
+ if comeback_state:
459
+ state = comeback_state
460
+ else:
461
+ context = state.context
462
+ state = self.states[f'{state.state} > {it}']
463
+ state.context = context
464
+
465
+ if last_name:
466
+ state.context['last_name'] = last_name
467
+ except:
468
+ pass
469
+
470
+ return state
471
+
472
+ def spec(self):
473
+ return SQL_SPEC
474
+
475
+ def keywords(self):
476
+ return SQL_KEYWORDS
477
+
478
+ def expandable_names(self):
479
+ return EXPANDABLE_NAMES
480
+
481
+ def witespace_transition_condition(self, from_s: str, to_s: str):
482
+ return from_s.endswith('_') and not from_s.endswith('_comma_') and not from_s.endswith('_lp_') and not from_s.endswith('_rp_')
483
+
484
+ def incomplete_name_transition_condition(self, from_s: str, token: str, to_s: str, suggestions: str):
485
+ if not suggestions:
486
+ return None
487
+
488
+ tokens = [token]
489
+ if '|' in token:
490
+ tokens = token.split('|')
491
+
492
+ if 'name' not in tokens:
493
+ return None
494
+
495
+ if not self.expandable_names().intersection(set(suggestions.split(','))):
496
+ return None
497
+
498
+ return tokens
499
+
500
+ class CqlStateMachine(SqlStateMachine):
501
+ def __init__(self, indent=0, push_level = 0, debug = False):
502
+ super().__init__(indent, push_level, debug)
503
+
504
+ def spec(self):
505
+ return CQL_SPEC
506
+
507
+ def keywords(self):
508
+ return CQL_KEYWORDS
509
+
510
+ class AthenaStateMachine(SqlStateMachine):
511
+ def __init__(self, indent=0, push_level = 0, debug = False):
512
+ super().__init__(indent, push_level, debug)
513
+
514
+ def spec(self):
515
+ return ATHENA_SPEC
516
+
517
+ def keywords(self):
518
+ return ATHENA_KEYWORDS
@@ -0,0 +1,76 @@
1
+ from typing import Callable, Iterable, List, Mapping, Optional, Pattern, Union
2
+
3
+ from prompt_toolkit.completion import CompleteEvent, Completion, WordCompleter
4
+ from prompt_toolkit.document import Document
5
+ from prompt_toolkit.formatted_text import AnyFormattedText
6
+
7
+ __all__ = [
8
+ "TermCompleter",
9
+ ]
10
+
11
+ class TermCompleter(WordCompleter):
12
+ def __init__(
13
+ self,
14
+ words: Union[List[str], Callable[[], List[str]]],
15
+ ignore_case: bool = False,
16
+ display_dict: Optional[Mapping[str, AnyFormattedText]] = None,
17
+ meta_dict: Optional[Mapping[str, AnyFormattedText]] = None,
18
+ WORD: bool = False,
19
+ sentence: bool = False,
20
+ match_middle: bool = False,
21
+ pattern: Optional[Pattern[str]] = None,
22
+ ) -> None:
23
+ super().__init__(words, ignore_case, display_dict, meta_dict, WORD, sentence, match_middle, pattern)
24
+
25
+ def __str__(self):
26
+ return ','.join(self.words)
27
+
28
+ def get_completions(
29
+ self, document: Document, complete_event: CompleteEvent
30
+ ) -> Iterable[Completion]:
31
+ # Get list of words.
32
+ words = self.words
33
+ if callable(words):
34
+ words = words()
35
+
36
+ # Get word/text before cursor.
37
+ if self.sentence:
38
+ word_before_cursor = document.text_before_cursor
39
+ else:
40
+ word_before_cursor = document.get_word_before_cursor(
41
+ WORD=self.WORD, pattern=self.pattern
42
+ )
43
+
44
+ if self.ignore_case:
45
+ word_before_cursor = word_before_cursor.lower()
46
+
47
+ def word_matches(word: str) -> bool:
48
+ """True when the word before the cursor matches."""
49
+ if self.ignore_case:
50
+ word = word.lower()
51
+
52
+ if self.match_middle:
53
+ return word_before_cursor in word
54
+ else:
55
+ return word.startswith(word_before_cursor)
56
+
57
+ for a in words:
58
+ if word_before_cursor in ['(', ',', '=', 'in', "',"]:
59
+ display = self.display_dict.get(a, a)
60
+ display_meta = self.meta_dict.get(a, "")
61
+ yield Completion(
62
+ a,
63
+ 0,
64
+ display=display,
65
+ display_meta=display_meta,
66
+ )
67
+
68
+ if word_matches(a):
69
+ display = self.display_dict.get(a, a)
70
+ display_meta = self.meta_dict.get(a, "")
71
+ yield Completion(
72
+ a,
73
+ -len(word_before_cursor),
74
+ display=display,
75
+ display_meta=display_meta,
76
+ )
adam/sso/cred_cache.py CHANGED
@@ -4,7 +4,7 @@ import traceback
4
4
  from dotenv import load_dotenv
5
5
 
6
6
  from adam.config import Config
7
- from adam.k8s_utils.kube_context import KubeContext
7
+ from adam.utils_k8s.kube_context import KubeContext
8
8
 
9
9
  class CredCache:
10
10
  # the singleton pattern
adam/sso/idp.py CHANGED
@@ -9,7 +9,7 @@ import requests
9
9
  from kubernetes import config
10
10
  import yaml
11
11
 
12
- from adam.k8s_utils.secrets import Secrets
12
+ from adam.utils_k8s.secrets import Secrets
13
13
 
14
14
  from .cred_cache import CredCache
15
15
  from .idp_session import IdpSession
adam/utils.py CHANGED
@@ -9,7 +9,6 @@ import os
9
9
  from pathlib import Path
10
10
  import random
11
11
  import string
12
- from typing import cast
13
12
  from dateutil import parser
14
13
  import subprocess
15
14
  import sys