kaqing 2.0.14__py3-none-any.whl → 2.0.145__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 (163) hide show
  1. adam/apps.py +2 -2
  2. adam/batch.py +13 -3
  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 +81 -0
  11. adam/commands/app.py +3 -3
  12. adam/commands/app_ping.py +2 -2
  13. adam/commands/audit/audit.py +86 -0
  14. adam/commands/audit/audit_repair_tables.py +77 -0
  15. adam/commands/audit/audit_run.py +58 -0
  16. adam/commands/audit/show_last10.py +51 -0
  17. adam/commands/audit/show_slow10.py +50 -0
  18. adam/commands/audit/show_top10.py +48 -0
  19. adam/commands/audit/utils_show_top10.py +59 -0
  20. adam/commands/bash/__init__.py +0 -0
  21. adam/commands/bash/bash.py +133 -0
  22. adam/commands/bash/bash_completer.py +93 -0
  23. adam/commands/cat.py +56 -0
  24. adam/commands/cd.py +12 -82
  25. adam/commands/check.py +6 -0
  26. adam/commands/cli_commands.py +3 -3
  27. adam/commands/code.py +60 -0
  28. adam/commands/command.py +48 -12
  29. adam/commands/commands_utils.py +4 -5
  30. adam/commands/cql/__init__.py +0 -0
  31. adam/commands/cql/cql_completions.py +28 -0
  32. adam/commands/cql/cql_utils.py +209 -0
  33. adam/commands/{cqlsh.py → cql/cqlsh.py} +15 -10
  34. adam/commands/deploy/code_utils.py +2 -2
  35. adam/commands/deploy/deploy.py +8 -21
  36. adam/commands/deploy/deploy_frontend.py +1 -1
  37. adam/commands/deploy/deploy_pg_agent.py +3 -3
  38. adam/commands/deploy/deploy_pod.py +28 -27
  39. adam/commands/deploy/deploy_utils.py +16 -26
  40. adam/commands/deploy/undeploy.py +8 -21
  41. adam/commands/deploy/undeploy_frontend.py +1 -1
  42. adam/commands/deploy/undeploy_pg_agent.py +5 -3
  43. adam/commands/deploy/undeploy_pod.py +12 -10
  44. adam/commands/devices/__init__.py +0 -0
  45. adam/commands/devices/device.py +27 -0
  46. adam/commands/devices/device_app.py +146 -0
  47. adam/commands/devices/device_auit_log.py +43 -0
  48. adam/commands/devices/device_cass.py +145 -0
  49. adam/commands/devices/device_export.py +86 -0
  50. adam/commands/devices/device_postgres.py +109 -0
  51. adam/commands/devices/devices.py +25 -0
  52. adam/commands/export/__init__.py +0 -0
  53. adam/commands/export/clean_up_export_session.py +53 -0
  54. adam/commands/export/clean_up_export_sessions.py +40 -0
  55. adam/commands/export/drop_export_database.py +58 -0
  56. adam/commands/export/drop_export_databases.py +46 -0
  57. adam/commands/export/export.py +83 -0
  58. adam/commands/export/export_databases.py +170 -0
  59. adam/commands/export/export_select.py +85 -0
  60. adam/commands/export/export_select_x.py +54 -0
  61. adam/commands/export/export_use.py +55 -0
  62. adam/commands/export/exporter.py +364 -0
  63. adam/commands/export/import_session.py +68 -0
  64. adam/commands/export/importer.py +67 -0
  65. adam/commands/export/importer_athena.py +80 -0
  66. adam/commands/export/importer_sqlite.py +47 -0
  67. adam/commands/export/show_column_counts.py +63 -0
  68. adam/commands/export/show_export_databases.py +39 -0
  69. adam/commands/export/show_export_session.py +51 -0
  70. adam/commands/export/show_export_sessions.py +47 -0
  71. adam/commands/export/utils_export.py +291 -0
  72. adam/commands/help.py +12 -7
  73. adam/commands/issues.py +6 -0
  74. adam/commands/kubectl.py +41 -0
  75. adam/commands/login.py +7 -4
  76. adam/commands/logs.py +2 -1
  77. adam/commands/ls.py +4 -107
  78. adam/commands/medusa/medusa.py +2 -26
  79. adam/commands/medusa/medusa_backup.py +2 -2
  80. adam/commands/medusa/medusa_restore.py +3 -4
  81. adam/commands/medusa/medusa_show_backupjobs.py +4 -3
  82. adam/commands/medusa/medusa_show_restorejobs.py +3 -3
  83. adam/commands/nodetool.py +9 -4
  84. adam/commands/param_set.py +1 -1
  85. adam/commands/postgres/postgres.py +42 -43
  86. adam/commands/postgres/{postgres_session.py → postgres_context.py} +43 -42
  87. adam/commands/postgres/postgres_utils.py +31 -0
  88. adam/commands/postgres/psql_completions.py +10 -0
  89. adam/commands/preview_table.py +18 -40
  90. adam/commands/pwd.py +2 -28
  91. adam/commands/reaper/reaper.py +4 -24
  92. adam/commands/reaper/reaper_restart.py +1 -1
  93. adam/commands/reaper/reaper_session.py +2 -2
  94. adam/commands/repair/repair.py +3 -27
  95. adam/commands/repair/repair_log.py +1 -1
  96. adam/commands/repair/repair_run.py +2 -2
  97. adam/commands/repair/repair_scan.py +1 -1
  98. adam/commands/repair/repair_stop.py +1 -1
  99. adam/commands/report.py +6 -0
  100. adam/commands/restart.py +2 -2
  101. adam/commands/rollout.py +1 -1
  102. adam/commands/show/show.py +11 -26
  103. adam/commands/show/show_app_actions.py +3 -0
  104. adam/commands/show/show_app_id.py +1 -1
  105. adam/commands/show/show_app_queues.py +3 -2
  106. adam/commands/show/show_cassandra_status.py +3 -3
  107. adam/commands/show/show_cassandra_version.py +3 -3
  108. adam/commands/show/show_host.py +33 -0
  109. adam/commands/show/show_login.py +3 -0
  110. adam/commands/show/show_processes.py +1 -1
  111. adam/commands/show/show_repairs.py +2 -2
  112. adam/commands/show/show_storage.py +1 -1
  113. adam/commands/watch.py +1 -1
  114. adam/config.py +16 -3
  115. adam/embedded_params.py +1 -1
  116. adam/pod_exec_result.py +10 -2
  117. adam/repl.py +127 -117
  118. adam/repl_commands.py +51 -16
  119. adam/repl_state.py +276 -55
  120. adam/sql/__init__.py +0 -0
  121. adam/sql/sql_completer.py +120 -0
  122. adam/sql/sql_state_machine.py +617 -0
  123. adam/sql/term_completer.py +76 -0
  124. adam/sso/authn_ad.py +1 -1
  125. adam/sso/cred_cache.py +1 -1
  126. adam/sso/idp.py +1 -1
  127. adam/utils.py +83 -2
  128. adam/utils_athena.py +145 -0
  129. adam/utils_audits.py +102 -0
  130. adam/utils_k8s/__init__.py +0 -0
  131. adam/utils_k8s/app_clusters.py +33 -0
  132. adam/utils_k8s/app_pods.py +31 -0
  133. adam/{k8s_utils → utils_k8s}/cassandra_clusters.py +6 -21
  134. adam/{k8s_utils → utils_k8s}/cassandra_nodes.py +12 -5
  135. adam/{k8s_utils → utils_k8s}/deployment.py +2 -2
  136. adam/{k8s_utils → utils_k8s}/kube_context.py +1 -1
  137. adam/{k8s_utils → utils_k8s}/pods.py +119 -26
  138. adam/{k8s_utils → utils_k8s}/secrets.py +4 -0
  139. adam/{k8s_utils → utils_k8s}/statefulsets.py +5 -4
  140. adam/utils_net.py +24 -0
  141. adam/utils_repl/__init__.py +0 -0
  142. adam/utils_repl/automata_completer.py +48 -0
  143. adam/utils_repl/repl_completer.py +46 -0
  144. adam/utils_repl/state_machine.py +173 -0
  145. adam/utils_sqlite.py +101 -0
  146. adam/version.py +1 -1
  147. {kaqing-2.0.14.dist-info → kaqing-2.0.145.dist-info}/METADATA +1 -1
  148. kaqing-2.0.145.dist-info/RECORD +227 -0
  149. adam/commands/bash.py +0 -87
  150. adam/commands/cql_utils.py +0 -53
  151. adam/commands/devices.py +0 -89
  152. kaqing-2.0.14.dist-info/RECORD +0 -167
  153. /adam/{k8s_utils → commands/audit}/__init__.py +0 -0
  154. /adam/{k8s_utils → utils_k8s}/config_maps.py +0 -0
  155. /adam/{k8s_utils → utils_k8s}/custom_resources.py +0 -0
  156. /adam/{k8s_utils → utils_k8s}/ingresses.py +0 -0
  157. /adam/{k8s_utils → utils_k8s}/jobs.py +0 -0
  158. /adam/{k8s_utils → utils_k8s}/service_accounts.py +0 -0
  159. /adam/{k8s_utils → utils_k8s}/services.py +0 -0
  160. /adam/{k8s_utils → utils_k8s}/volumes.py +0 -0
  161. {kaqing-2.0.14.dist-info → kaqing-2.0.145.dist-info}/WHEEL +0 -0
  162. {kaqing-2.0.14.dist-info → kaqing-2.0.145.dist-info}/entry_points.txt +0 -0
  163. {kaqing-2.0.14.dist-info → kaqing-2.0.145.dist-info}/top_level.txt +0 -0
@@ -0,0 +1,617 @@
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 = {'keyspaces', '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,export,import,drop,clean',
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 ^ keyspaces',
369
+ 'desc_keyspace_k_ > & > desc_keyspace_k_$ ^ &',
370
+ 'desc_schema_ > & > desc_schema_$ ^ &',
371
+
372
+ ' > export > export',
373
+ 'export_ > name > export_table ^ *,tables',
374
+ '- > * > export_all',
375
+ 'export_all_ > in > export_in ^ in,with',
376
+ '- > with > export_with',
377
+ 'export_table > ( > export_table_lp_ ^ (,comma,with,tables',
378
+ '- > , > export_table_comma_',
379
+ '- > . > export_table ^ tables',
380
+ 'export_table_ > ( > export_table_lp_ ^ as,(,comma,with consistency,to',
381
+ '- > , > export_table_comma_',
382
+ '- > as > export_as',
383
+ '- > with > export_with',
384
+ '- > to > export_table_to',
385
+ 'export_table_comma_ > name > export_table ^ tables',
386
+ 'export_table_lp_ > name > export_table_lp_a ^ columns',
387
+ 'export_table_lp_a > , > export_table_lp_a_comma_',
388
+ '- > ) > export_table_lp_a_comma_rp_',
389
+ 'export_table_lp_a_comma_ > name > export_table_lp_a ^ columns',
390
+ 'export_table_lp_a_comma_rp_ > as > export_as ^ as,with consistency',
391
+ '- > , > export ^ with consistency',
392
+ '- > with > export_with',
393
+ 'export_as_ > name > export_as_f',
394
+ 'export_as_f > , > export_table_comma_',
395
+ 'export_as_f_ > , > export_table_comma_ ^ with consistency,to',
396
+ '- > with > export_with',
397
+ '- > to > export_table_to',
398
+ 'export_in_ > name > export_in_k ^ keyspaces',
399
+ 'export_in_k_ > with > export_with ^ with consistency',
400
+ 'export_with_ > consistency > export_with_consistency ^ consistency',
401
+ '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',
402
+ 'export_table_to_ > athena|sqlite|csv > export_table_to$ ^ athena,sqlite,csv',
403
+
404
+ ' > import > import',
405
+ 'import_ > session > import_session ^ session',
406
+ 'import_session_ > name > import_session_s ^ export-sessions-incomplete',
407
+ 'import_session_s_ > to > import_session_to ^ to',
408
+ 'import_session_to_ > athena|sqlite > import_session_to$ ^ athena,sqlite',
409
+
410
+ ' > consistency > consistency',
411
+ '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',
412
+ 'consistency_quorum > ; > ',
413
+
414
+ ' > drop > drop',
415
+ 'drop_ > all > drop_all ^ all export databases,export database',
416
+ '- > export > drop_export',
417
+ 'drop_all_ > export > drop_all_export ^ export databases',
418
+ 'drop_all_export_ > databases > drop_all_dbs ^ databases',
419
+ 'drop_export_ > database > drop_export_db ^ database',
420
+ 'drop_export_db_ > name > drop_export_db$ ^ export-dbs',
421
+
422
+ ' > clean > clean',
423
+ 'clean_ > up > clean_up ^ up all export sessions,up export session',
424
+ 'clean_up_ > all > clean_up_all ^ all export sessions,export session',
425
+ '- > export > clean_up_export',
426
+ 'clean_up_all_ > export > clean_up_all_export ^ export sessions',
427
+ 'clean_up_all_export_ > sessions > clean_up_all_sessions ^ sessions',
428
+ 'clean_up_export_ > session > clean_up_export_session ^ session',
429
+ 'clean_up_export_session_ > name > clean_up_export_session$ ^ export-sessions',
430
+ ]
431
+
432
+ CQL_KEYWORDS = SQL_KEYWORDS + [
433
+ 'schema', 'keyspace', 'keyspaces', 'tables', 'export', 'copy', 'consistency',
434
+ 'quorum', 'all', 'serial', 'one', 'each_quorum', 'local_quorum', 'any', 'local_one', 'two', 'three', 'local_serial', 'to',
435
+ 'database', 'databases', 'session', 'sessions', 'clean', 'up', 'athena', 'sqlite', 'csv', 'import'
436
+ ]
437
+
438
+ CQL_EXPANDABLE_NAMES = EXPANDABLE_NAMES | {
439
+ 'export-dbs', 'export-sessions', 'export-sessions-incomplete'
440
+ }
441
+
442
+ ATHENA_SPEC = SQL_SPEC + [
443
+ ' > select > select ^ select,insert,update,delete,alter,describe,preview,drop',
444
+
445
+ 'alter_table_t_ > add > alter_table_add ^ add partition,drop partition',
446
+ 'alter_table_add_ > partition > alter_partition ^ partition',
447
+ 'alter_table_drop_ > partition > alter_partition ^ partition',
448
+ 'alter_partition > ( > alter_partition_lp ^ (',
449
+ 'alter_partition_lp > name > alter_partition_lp_a ^ partition-columns',
450
+ 'alter_partition_lp_a > comparison > alter_partition_lp_a_op ^ =',
451
+ 'alter_partition_lp_a_op > single > alter_partition_lp_a_op_v ^ single',
452
+ 'alter_partition_lp_a_op_v > , > alter_partition_lp_sc ^ single',
453
+ 'alter_partition_lp_sc > name|) > alter_partition_lp_a ^ partition-columns',
454
+
455
+ ' > describe > describe',
456
+ 'describe_ > name > desc_t ^ tables',
457
+ 'desc_t_ > name > desc_t_',
458
+
459
+ 'repair',
460
+
461
+ ' > drop > drop',
462
+ 'drop_ > all > drop_all ^ all export databases,export database',
463
+ '- > export > drop_export',
464
+ 'drop_all_ > export > drop_all_export ^ export databases',
465
+ 'drop_all_export_ > databases > drop_all_dbs ^ databases',
466
+ 'drop_export_ > database > drop_export_db ^ database',
467
+ 'drop_export_db_ > name > drop_export_db$ ^ export-dbs',
468
+ ]
469
+
470
+ ATHENA_KEYWORDS = SQL_KEYWORDS + [
471
+ 'partition',
472
+ 'database', 'databases', 'session', 'sessions', 'clean', 'up', 'all', 'export'
473
+ ]
474
+
475
+ ATHENA_EXPANDABLE_NAMES = EXPANDABLE_NAMES | {
476
+ 'export-dbs'
477
+ }
478
+
479
+ class SqlStateMachine(StateMachine[Token]):
480
+ def __init__(self, indent=0, push_level = 0, debug = False):
481
+ super().__init__(indent, push_level, debug)
482
+
483
+ def traverse_tokens(self, tokens: list[Token], state: State = State('')):
484
+ def handle_push():
485
+ if f'{state.state} > {it}' in self.states:
486
+ state_test = self.states[f'{state.state} > {it}']
487
+ if state_test.comeback_token:
488
+ self.comebacks[self.push_level] = state_test.comeback_state
489
+
490
+ def handle_pop():
491
+ if self.push_level in self.comebacks:
492
+ try:
493
+ return State(self.comebacks[self.push_level])
494
+ finally:
495
+ del self.comebacks[self.push_level]
496
+
497
+ return None
498
+
499
+ for token in tokens:
500
+ if self.debug:
501
+ if token.ttype == TOKEN.Whitespace:
502
+ print('_ ', end='')
503
+ elif token.ttype in [TOKEN.DML, TOKEN.Wildcard, TOKEN.Punctuation, TOKEN.CTE]:
504
+ print(f'{token.value} ', end='')
505
+ elif token.ttype:
506
+ tks = str(token.ttype).split('.')
507
+ typ = tks[len(tks) - 1]
508
+ if ' ' in token.value:
509
+ print(f'"{token.value}:{typ}" ', end='')
510
+ else:
511
+ print(f'{token.value}:{typ} ', end='')
512
+ # print(" " * self.indent + f"Token: {token.value}, Type: {token.ttype}@{token.ttype.__class__}")
513
+
514
+ last_name = None
515
+ if token.is_group:
516
+ state = self.traverse_tokens(token.tokens, state)
517
+ else:
518
+ comeback_state = None
519
+
520
+ it = ''
521
+ if (t := token.value.lower()) in self.keywords():
522
+ it = t
523
+ elif token.ttype == TOKEN.Text.Whitespace:
524
+ it = '_'
525
+ elif token.ttype == TOKEN.Name:
526
+ it = 'name'
527
+ last_name = token.value
528
+ elif token.ttype == TOKEN.Literal.String.Single:
529
+ it = 'single'
530
+ elif token.ttype in [TOKEN.Literal.Number.Integer, TOKEN.Literal.Number.Float]:
531
+ it = 'num'
532
+ elif token.ttype == TOKEN.Wildcard:
533
+ it = '*'
534
+ elif token.ttype == TOKEN.Punctuation:
535
+ it = token.value
536
+
537
+ if it == '(':
538
+ handle_push()
539
+ self.push_level += 1
540
+ elif it == ')':
541
+ self.push_level -= 1
542
+ comeback_state = handle_pop()
543
+ elif it == '.' and 'last_name' in state.context and (ln := state.context['last_name']):
544
+ state.context['last_namespace'] = ln
545
+
546
+ elif token.ttype == TOKEN.Operator.Comparison:
547
+ it = 'comparison'
548
+
549
+ try:
550
+ # print(f'\n{state.to_s} > {it} > ', end='')
551
+ if comeback_state:
552
+ state = comeback_state
553
+ else:
554
+ context = state.context
555
+ state = self.states[f'{state.state} > {it}']
556
+ state.context = context
557
+
558
+ if last_name:
559
+ state.context['last_name'] = last_name
560
+ except:
561
+ pass
562
+
563
+ return state
564
+
565
+ def spec(self):
566
+ return SQL_SPEC
567
+
568
+ def keywords(self):
569
+ return SQL_KEYWORDS
570
+
571
+ def expandable_names(self):
572
+ return EXPANDABLE_NAMES
573
+
574
+ def witespace_transition_condition(self, from_s: str, to_s: str):
575
+ return from_s.endswith('_') and not from_s.endswith('_comma_') and not from_s.endswith('_lp_') and not from_s.endswith('_rp_')
576
+
577
+ def incomplete_name_transition_condition(self, from_s: str, token: str, to_s: str, suggestions: str):
578
+ if not suggestions:
579
+ return None
580
+
581
+ tokens = [token]
582
+ if '|' in token:
583
+ tokens = token.split('|')
584
+
585
+ if 'name' not in tokens:
586
+ return None
587
+
588
+ if not self.expandable_names().intersection(set(suggestions.split(','))):
589
+ return None
590
+
591
+ return tokens
592
+
593
+ class CqlStateMachine(SqlStateMachine):
594
+ def __init__(self, indent=0, push_level = 0, debug = False):
595
+ super().__init__(indent, push_level, debug)
596
+
597
+ def spec(self):
598
+ return CQL_SPEC
599
+
600
+ def keywords(self):
601
+ return CQL_KEYWORDS
602
+
603
+ def expandable_names(self):
604
+ return CQL_EXPANDABLE_NAMES
605
+
606
+ class AthenaStateMachine(SqlStateMachine):
607
+ def __init__(self, indent=0, push_level = 0, debug = False):
608
+ super().__init__(indent, push_level, debug)
609
+
610
+ def spec(self):
611
+ return ATHENA_SPEC
612
+
613
+ def keywords(self):
614
+ return ATHENA_KEYWORDS
615
+
616
+ def expandable_names(self):
617
+ return ATHENA_EXPANDABLE_NAMES