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