kaqing 2.0.55__py3-none-any.whl → 2.0.57__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.
adam/sql/sql_completer.py CHANGED
@@ -7,7 +7,131 @@ from sqlparse import tokens as T
7
7
 
8
8
  from adam.sql.term_completer import TermCompleter
9
9
 
10
+ columns = TermCompleter(['id', 'x.', 'y.', 'z.'])
11
+
10
12
  class SqlCompleter(Completer):
13
+ # <select_statement> ::= SELECT <select_list>
14
+ # FROM <table_expression>
15
+ # [WHERE <search_condition>]
16
+ # [<group_by_clause>]
17
+ # [<having_clause>]
18
+ # [<order_by_clause>]
19
+ # [<limit_clause>]
20
+
21
+ # <search_condition> ::= <boolean_term>
22
+ # | <search_condition> OR <boolean_term>
23
+
24
+ # <boolean_term> ::= <boolean_factor>
25
+ # | <boolean_term> AND <boolean_factor>
26
+
27
+ # <boolean_factor> ::= [NOT] <predicate>
28
+ # | ([NOT] <search_condition>)
29
+
30
+ # <predicate> ::= <comparison_predicate>
31
+ # | <between_predicate>
32
+ # | <in_predicate>
33
+ # | <like_predicate>
34
+ # | <null_predicate>
35
+ # | <exists_predicate>
36
+ # | <quantified_predicate>
37
+ # | <unique_predicate>
38
+ # | <match_predicate>
39
+ # | <overlaps_predicate>
40
+ # | <distinct_predicate>
41
+ # | <member_predicate>
42
+ # | <submultiset_predicate>
43
+ # | <set_predicate>
44
+
45
+ # <comparison_predicate> ::= <row_value_expression> <comparison_operator> <row_value_expression>
46
+ # <comparison_operator> ::= '=' | '<>' | '<' | '<=' | '>' | '>='
47
+
48
+ # <row_value_expression> ::= <value_expression>
49
+ # | (<value_expression> [ { <comma> <value_expression> }... ])
50
+
51
+ # <value_expression> ::= <numeric_value_expression>
52
+ # | <string_value_expression>
53
+ # | <datetime_value_expression>
54
+ # | <interval_value_expression>
55
+ # | <boolean_value_expression>
56
+ # | <user_defined_type_value_expression>
57
+ # | <reference_value_expression>
58
+ # | <collection_value_expression>
59
+ # | <row_value_constructor>
60
+ # | <case_expression>
61
+ # | <cast_expression>
62
+ # | <subquery>
63
+ # | NULL
64
+ # | DEFAULT
65
+ # | <identifier>
66
+ # | <literal>
67
+
68
+ # <insert_statement> ::= INSERT INTO <table_name> [ ( <column_list> ) ]
69
+ # VALUES ( <value_list> )
70
+ # | INSERT INTO <table_name> [ ( <column_list> ) ]
71
+ # <query_expression>
72
+
73
+ # <table_name> ::= <identifier>
74
+
75
+ # <column_list> ::= <column_name> [ , <column_list> ]
76
+
77
+ # <column_name> ::= <identifier>
78
+
79
+ # <value_list> ::= <expression> [ , <value_list> ]
80
+
81
+ # <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> ]
82
+
83
+ # <update_statement> ::= UPDATE <table_name>
84
+ # SET <set_clause_list>
85
+ # [WHERE <search_condition>]
86
+
87
+ # <set_clause_list> ::= <set_clause> { , <set_clause> }
88
+
89
+ # <set_clause> ::= <column_name> = <update_value>
90
+
91
+ # <update_value> ::= <expression> | NULL | DEFAULT
92
+
93
+ # <search_condition> ::= <boolean_expression>
94
+
95
+ # <delete_statement> ::= DELETE FROM <table_name> [ WHERE <search_condition> ]
96
+
97
+ # <table_name> ::= <identifier>
98
+
99
+ # <search_condition> ::= <boolean_expression>
100
+
101
+ # <boolean_expression> ::= <predicate>
102
+ # | <boolean_expression> AND <predicate>
103
+ # | <boolean_expression> OR <predicate>
104
+ # | NOT <predicate>
105
+ # | ( <boolean_expression> )
106
+
107
+ # <predicate> ::= <expression> <comparison_operator> <expression>
108
+ # | <expression> IS NULL
109
+ # | <expression> IS NOT NULL
110
+ # | <expression> LIKE <pattern> [ ESCAPE <escape_character> ]
111
+ # | <expression> IN ( <expression_list> )
112
+ # | EXISTS ( <select_statement> )
113
+ # | ... (other predicates)
114
+
115
+ # <comparison_operator> ::= = | <> | != | > | < | >= | <=
116
+
117
+ # <expression> ::= <literal>
118
+ # | <column_name>
119
+ # | <function_call>
120
+ # | ( <expression> )
121
+ # | <expression> <arithmetic_operator> <expression>
122
+ # | ... (other expressions)
123
+
124
+ # <literal> ::= <numeric_literal> | <string_literal> | <boolean_literal> | <date_literal> | ...
125
+
126
+ # <column_name> ::= <identifier>
127
+
128
+ # <identifier> ::= <letter> { <letter> | <digit> | _ }...
129
+
130
+ # <pattern> ::= <string_literal>
131
+
132
+ # <escape_character> ::= <string_literal> (single character)
133
+
134
+ # <expression_list> ::= <expression> { , <expression> }...
11
135
  def __init__(self, tables: Callable[[], list[str]], dml: str = None, debug = False):
12
136
  super().__init__()
13
137
  self.dml = dml
@@ -42,59 +166,67 @@ class SqlCompleter(Completer):
42
166
  completer = TermCompleter(['*'])
43
167
  elif state == 'select_a_':
44
168
  completer = TermCompleter(['from'])
45
- elif state == "select_a_from_":
169
+ elif state == "select_from_":
46
170
  completer = TermCompleter(self.tables())
47
- elif state == "select_a_from_x_":
171
+ elif state == "select_from_x_":
172
+ completer = TermCompleter(['as', 'where', 'inner', 'left', 'right', 'full', 'group', 'limit'])
173
+ elif state == "select_from_x_as_x_":
48
174
  completer = TermCompleter(['where', 'inner', 'left', 'right', 'full', 'group', 'limit'])
49
- elif state == "select_a_from_x,":
175
+ elif state == "select_from_x,":
176
+ completer = TermCompleter(self.tables())
177
+ elif state == "select_from_x_as_":
178
+ completer = TermCompleter(['x', 'y', 'z'])
179
+ elif state == "select_from_x_as_x,":
50
180
  completer = TermCompleter(self.tables())
51
- elif state == "select_a_from_x_where_":
52
- completer = TermCompleter(['id'])
53
- elif state == "select_a_from_x_where_id":
54
- completer = TermCompleter(['=', '<', '<=', '>', '>=', '<>', 'like'])
55
- elif state == "select_a_from_x_where_id=":
181
+ elif state == "select_where_":
182
+ completer = columns
183
+ elif state in ["select_where_a", "select_where_a_"]:
184
+ completer = TermCompleter(['=', '<', '<=', '>', '>=', '<>', 'like', 'not'])
185
+ elif state == "select_where_a_not_":
186
+ completer = TermCompleter(['like', 'in'])
187
+ elif state == "select_where_a_op":
56
188
  completer = TermCompleter(["'"])
57
- elif state == "select_a_from_x_where_id=v_":
189
+ elif state == "select_where_sc_":
58
190
  completer = TermCompleter(['and', 'or', 'group', 'limit'])
59
- elif state == "select_a_from_x_where_id=v_limit_":
191
+ elif state == "select_where_sc_limit_":
60
192
  completer = TermCompleter(['1'])
61
- elif state == "select_a_from_x_group_":
193
+ elif state == "select_from_x_group_":
62
194
  completer = TermCompleter(['by'])
63
- elif state == "select_a_from_x_group_by_":
64
- completer = TermCompleter(['id'])
65
- elif state == "select_a_from_x_group_by_a,":
66
- completer = TermCompleter(['id'])
67
- elif state == "select_a_from_x_group_by_a_":
195
+ elif state == "select_from_x_group_by_":
196
+ completer = columns
197
+ elif state == "select_from_x_group_by_a,":
198
+ completer = columns
199
+ elif state == "select_from_x_group_by_a_":
68
200
  completer = TermCompleter(['limit'])
69
- elif state == "select_a_from_x_group_by_a_limit_":
201
+ elif state == "select_from_x_group_by_a_limit_":
70
202
  completer = TermCompleter(['1'])
71
- elif state == "select_a_from_x_inner_":
203
+ elif state == "select_from_x_inner_":
72
204
  completer = TermCompleter(['join'])
73
- elif state in ["select_a_from_x_inner_join_", "select_a_from_x_left_join_"]:
205
+ elif state in ["select_join_", "select_from_x_left_join_"]:
74
206
  completer = TermCompleter(self.tables())
75
- elif state == "select_a_from_x_inner_join_y,":
207
+ elif state == "select_x_join_y,":
76
208
  completer = TermCompleter(self.tables())
77
- elif state == "select_a_from_x_inner_join_y_":
209
+ elif state == "select_x_join_y_":
78
210
  completer = TermCompleter(['on'])
79
- elif state == "select_a_from_x_inner_join_y_on_":
80
- completer = TermCompleter(['id'])
81
- elif state == "select_a_from_x_inner_join_y_on_a":
211
+ elif state == "select_x_join_y_on_":
212
+ completer = columns
213
+ elif state == "select_x_join_y_on_a":
82
214
  completer = TermCompleter(['='])
83
- elif state == "select_a_from_x_inner_join_y_on_a=":
84
- completer = TermCompleter(['id'])
85
- elif state == "select_a_from_x_inner_join_y_on_a=b_":
215
+ elif state == "select_x_join_y_on_a_op":
216
+ completer = columns
217
+ elif state == "select_x_join_y_on_a_opb_":
86
218
  completer = TermCompleter(['where', 'group', 'limit'])
87
- elif state == "select_a_from_x_left_":
219
+ elif state == "select_from_x_left_":
88
220
  completer = TermCompleter(['outer', 'join'])
89
- elif state == "select_a_from_x_left_outer_":
221
+ elif state == "select_from_x_left_outer_":
90
222
  completer = TermCompleter(['join'])
91
- elif state == "select_a_from_x_right_":
223
+ elif state == "select_from_x_right_":
92
224
  completer = TermCompleter(['outer', 'join'])
93
- elif state == "select_a_from_x_right_outer_":
225
+ elif state == "select_from_x_right_outer_":
94
226
  completer = TermCompleter(['join'])
95
- elif state == "select_a_from_x_full_":
227
+ elif state == "select_from_x_full_":
96
228
  completer = TermCompleter(['outer'])
97
- elif state == "select_a_from_x_full_outer_":
229
+ elif state == "select_from_x_full_outer_":
98
230
  completer = TermCompleter(['join'])
99
231
 
100
232
  elif state == "insert_":
@@ -102,35 +234,35 @@ class SqlCompleter(Completer):
102
234
  elif state == "insert_into_":
103
235
  completer = TermCompleter(self.tables())
104
236
  elif state == "insert_into_x_":
105
- completer = TermCompleter(['values'])
106
- elif state == "insert_into_x(":
107
- completer = TermCompleter(['id'])
108
- elif state == "insert_into_x(a,":
109
- completer = TermCompleter(['id'])
110
- elif state == "insert_into_x(a)_":
111
- completer = TermCompleter(['values('])
112
- elif state == "insert_into_x_values":
237
+ completer = TermCompleter(['values(', 'select'])
238
+ elif state == "insert_into_x_lp_":
239
+ completer = columns
240
+ elif state == "insert_into_x_lp_a,":
241
+ completer = columns
242
+ elif state == "insert_into_x_lp_a_rp_":
243
+ completer = TermCompleter(['values(', 'select'])
244
+ elif state == "insert_values":
113
245
  completer = TermCompleter(['('])
114
- elif state == "insert_into_x_values(":
246
+ elif state == "insert_values_lp_":
115
247
  completer = TermCompleter(["'"])
116
248
 
117
249
  elif state == "update_":
118
250
  completer = TermCompleter(self.tables())
119
251
  elif state == "update_x_":
120
252
  completer = TermCompleter(['set'])
121
- elif state in ["update_x_set_", "update_x_set_a=v,"]:
122
- completer = TermCompleter(['id'])
253
+ elif state in ["update_x_set_", "update_x_set_sc,"]:
254
+ completer = columns
123
255
  elif state == "update_x_set_a":
124
256
  completer = TermCompleter(['='])
125
- elif state == "update_x_set_a=":
257
+ elif state == "update_x_set_a_op":
126
258
  completer = TermCompleter(["'"])
127
- elif state == "update_x_set_a=v_":
259
+ elif state == "update_x_set_sc_":
128
260
  completer = TermCompleter(['where'])
129
- elif state == "update_x_set_a=v_where_":
130
- completer = TermCompleter(['id'])
131
- elif state == "update_x_set_a=v_where_id":
261
+ elif state == "update_where_":
262
+ completer = columns
263
+ elif state == "update_where_a":
132
264
  completer = TermCompleter(['='])
133
- elif state == "update_x_set_a=v_where_id=v_":
265
+ elif state == "update_where_sc_":
134
266
  completer = TermCompleter(['and', 'or'])
135
267
 
136
268
  elif state == "delete_":
@@ -139,13 +271,13 @@ class SqlCompleter(Completer):
139
271
  completer = TermCompleter(self.tables())
140
272
  elif state == "delete_from_x_":
141
273
  completer = TermCompleter(['where'])
142
- elif state == "delete_from_x_where_":
143
- completer = TermCompleter(['id'])
144
- elif state == "delete_from_x_where_id":
274
+ elif state == "delete_where_":
275
+ completer = columns
276
+ elif state == "delete_where_a":
145
277
  completer = TermCompleter(['='])
146
- elif state == "delete_from_x_where_id=":
278
+ elif state == "delete_where_a_op":
147
279
  completer = TermCompleter(["'"])
148
- elif state == "delete_from_x_where_id=v_":
280
+ elif state == "delete_where_sc_":
149
281
  completer = TermCompleter(['and', 'or'])
150
282
 
151
283
  if completer:
@@ -200,191 +332,225 @@ class SqlCompleter(Completer):
200
332
  state = 'select_a'
201
333
  elif state == 'select_a_':
202
334
  if token.ttype == T.Keyword and token.value.lower() == 'from':
203
- state = 'select_a_from'
204
- elif state == 'select_a_from':
335
+ state = 'select_from'
336
+ elif state == 'select_from':
205
337
  if token.ttype == T.Text.Whitespace:
206
- state = 'select_a_from_'
207
- elif state == 'select_a_from_':
338
+ state = 'select_from_'
339
+ elif state == 'select_from_':
208
340
  if token.ttype == T.Name:
209
- state = 'select_a_from_x'
210
- elif state == 'select_a_from_x':
341
+ state = 'select_from_x'
342
+ elif state == 'select_from_x':
211
343
  if token.ttype == T.Text.Whitespace:
212
- state = 'select_a_from_x_'
344
+ state = 'select_from_x_'
213
345
  elif token.ttype == T.Punctuation and token.value == ',':
214
- state = 'select_a_from_x,'
215
- elif state == 'select_a_from_x,':
346
+ state = 'select_from_x,'
347
+ elif state == 'select_from_x,':
216
348
  if token.ttype == T.Name:
217
- state = 'select_a_from_x'
218
- elif state == 'select_a_from_x_':
219
- if token.ttype == T.Keyword and token.value.lower() == 'where':
220
- state = 'select_a_from_x_where'
349
+ state = 'select_from_x'
350
+ elif state in ['select_from_x_', 'select_from_x_as_x_']:
351
+ if token.ttype == T.Punctuation and token.value == ',':
352
+ state = 'select_from_x,'
353
+ elif token.ttype == T.Keyword and token.value.lower() == 'as':
354
+ state = 'select_from_x_as'
355
+ elif token.ttype == T.Keyword and token.value.lower() == 'where':
356
+ state = 'select_where'
221
357
  elif token.ttype == T.Keyword and token.value.lower() == 'limit':
222
- state = 'select_a_from_x_where_id=v_limit'
358
+ state = 'select_where_sc_limit'
223
359
  elif token.ttype == T.Keyword and token.value.lower() == 'group':
224
- state = 'select_a_from_x_group'
360
+ state = 'select_from_x_group'
225
361
  elif token.ttype == T.Keyword and token.value.lower() == 'group by':
226
- state = 'select_a_from_x_group_by'
362
+ state = 'select_from_x_group_by'
227
363
  elif token.ttype == T.Keyword and token.value.lower() == 'inner':
228
- state = 'select_a_from_x_inner'
364
+ state = 'select_from_x_inner'
229
365
  elif token.ttype == T.Keyword and token.value.lower() == 'inner join':
230
- state = 'select_a_from_x_inner_join'
366
+ state = 'select_join'
231
367
  elif token.ttype == T.Keyword and token.value.lower() == 'left':
232
- state = 'select_a_from_x_left'
368
+ state = 'select_from_x_left'
233
369
  elif token.ttype == T.Keyword and token.value.lower() in ['left join', 'left outer join']:
234
- state = 'select_a_from_x_inner_join'
370
+ state = 'select_join'
235
371
  elif token.ttype == T.Keyword and token.value.lower() == 'right':
236
- state = 'select_a_from_x_right'
372
+ state = 'select_from_x_right'
237
373
  elif token.ttype == T.Keyword and token.value.lower() in ['right join', 'right outer join']:
238
- state = 'select_a_from_x_inner_join'
374
+ state = 'select_join'
239
375
  elif token.ttype == T.Keyword and token.value.lower() == 'full':
240
- state = 'select_a_from_x_full'
376
+ state = 'select_from_x_full'
241
377
  elif token.ttype == T.Keyword and token.value.lower() == 'full outer join':
242
- state = 'select_a_from_x_inner_join'
243
- elif state == 'select_a_from_x_where':
378
+ state = 'select_join'
379
+ elif state == 'select_from_x_as':
244
380
  if token.ttype == T.Text.Whitespace:
245
- state = 'select_a_from_x_where_'
246
- elif state == 'select_a_from_x_where_':
381
+ state = 'select_from_x_as_'
382
+ elif state == 'select_from_x_as_':
247
383
  if token.ttype == T.Name:
248
- state = 'select_a_from_x_where_id'
249
- elif state == 'select_a_from_x_where_id':
384
+ state = 'select_from_x_as_x'
385
+ elif state == 'select_from_x_as_x':
386
+ if token.ttype == T.Text.Whitespace:
387
+ state = 'select_from_x_as_x_'
388
+ elif token.ttype == T.Punctuation and token.value == ',':
389
+ state = 'select_from_x_as_x,'
390
+ elif state == 'select_from_x_as_x,':
391
+ if token.ttype == T.Name:
392
+ state = 'select_from_x'
393
+ elif state == 'select_where':
394
+ if token.ttype == T.Text.Whitespace:
395
+ state = 'select_where_'
396
+ elif state == 'select_where_':
397
+ if token.ttype == T.Name:
398
+ state = 'select_where_a'
399
+ elif state == 'select_where_a':
400
+ if token.ttype == T.Text.Whitespace:
401
+ state = 'select_where_a_'
402
+ elif token.ttype == T.Operator.Comparison:
403
+ state = 'select_where_a_op'
404
+ elif state == 'select_where_a_':
250
405
  if token.ttype == T.Operator.Comparison:
251
- state = 'select_a_from_x_where_id='
252
- elif state == 'select_a_from_x_where_id=':
406
+ state = 'select_where_a_op'
407
+ elif token.ttype == T.Keyword and token.value.lower() == 'not':
408
+ state = 'select_where_a_not'
409
+ elif state == 'select_where_a_not':
410
+ if token.ttype == T.Text.Whitespace:
411
+ state = 'select_where_a_not_'
412
+ elif state == 'select_where_a_not_':
413
+ if token.ttype == T.Operator.Comparison:
414
+ state = 'select_where_a_not_op'
415
+ elif state == 'select_where_a_not_op':
416
+ if token.ttype in [T.Literal.String.Single, T.Name]:
417
+ state = 'select_where_sc'
418
+ elif state == 'select_where_a_op':
253
419
  if token.ttype in [T.Literal.String.Single, T.Name]:
254
- state = 'select_a_from_x_where_id=v'
255
- elif state == 'select_a_from_x_where_id=v':
420
+ state = 'select_where_sc'
421
+ elif state == 'select_where_sc':
256
422
  if token.ttype == T.Text.Whitespace:
257
- state = 'select_a_from_x_where_id=v_'
258
- elif state == 'select_a_from_x_where_id=v_':
423
+ state = 'select_where_sc_'
424
+ elif state == 'select_where_sc_':
259
425
  if token.ttype == T.Keyword and token.value.lower() in ['and', 'or']:
260
- state = 'select_a_from_x_where'
426
+ state = 'select_where'
261
427
  elif token.ttype == T.Keyword and token.value.lower() == 'group':
262
- state = 'select_a_from_x_group'
428
+ state = 'select_from_x_group'
263
429
  elif token.ttype == T.Keyword and token.value.lower() == 'group by':
264
- state = 'select_a_from_x_group_by'
430
+ state = 'select_from_x_group_by'
265
431
  elif token.ttype == T.Keyword and token.value.lower() == 'limit':
266
- state = 'select_a_from_x_where_id=v_limit'
267
- elif state == 'select_a_from_x_group':
432
+ state = 'select_where_sc_limit'
433
+ elif state == 'select_from_x_group':
268
434
  if token.ttype == T.Text.Whitespace:
269
- state = 'select_a_from_x_group_'
270
- elif state == 'select_a_from_x_group_':
435
+ state = 'select_from_x_group_'
436
+ elif state == 'select_from_x_group_':
271
437
  if token.ttype == T.Keyword and token.value.lower() == 'by':
272
- state = 'select_a_from_x_group_by'
273
- elif state == 'select_a_from_x_group_by':
438
+ state = 'select_from_x_group_by'
439
+ elif state == 'select_from_x_group_by':
274
440
  if token.ttype == T.Text.Whitespace:
275
- state = 'select_a_from_x_group_by_'
276
- elif state == 'select_a_from_x_group_by_':
441
+ state = 'select_from_x_group_by_'
442
+ elif state == 'select_from_x_group_by_':
277
443
  if token.ttype == T.Name:
278
- state = 'select_a_from_x_group_by_a'
279
- elif state == 'select_a_from_x_group_by_a':
444
+ state = 'select_from_x_group_by_a'
445
+ elif state == 'select_from_x_group_by_a':
280
446
  if token.ttype == T.Text.Whitespace:
281
- state = 'select_a_from_x_group_by_a_'
447
+ state = 'select_from_x_group_by_a_'
282
448
  elif token.ttype == T.Punctuation and token.value == ',':
283
- state = 'select_a_from_x_group_by_a,'
284
- elif state == 'select_a_from_x_group_by_a,':
449
+ state = 'select_from_x_group_by_a,'
450
+ elif state == 'select_from_x_group_by_a,':
285
451
  if token.ttype == T.Name:
286
- state = 'select_a_from_x_group_by_a'
287
- elif state == 'select_a_from_x_group_by_a_':
452
+ state = 'select_from_x_group_by_a'
453
+ elif state == 'select_from_x_group_by_a_':
288
454
  if token.ttype == T.Keyword and token.value.lower() == 'limit':
289
- state = 'select_a_from_x_where_id=v_limit'
290
- elif state == 'select_a_from_x_where_id=v_limit':
455
+ state = 'select_where_sc_limit'
456
+ elif state == 'select_where_sc_limit':
291
457
  if token.ttype == T.Text.Whitespace:
292
- state = 'select_a_from_x_where_id=v_limit_'
293
- elif state == 'select_a_from_x_inner':
458
+ state = 'select_where_sc_limit_'
459
+ elif state == 'select_from_x_inner':
294
460
  if token.ttype == T.Text.Whitespace:
295
- state = 'select_a_from_x_inner_'
296
- elif state == 'select_a_from_x_inner_':
461
+ state = 'select_from_x_inner_'
462
+ elif state == 'select_from_x_inner_':
297
463
  if token.ttype == T.Keyword and token.value.lower() == 'join':
298
- state = 'select_a_from_x_inner_join'
299
- elif state == 'select_a_from_x_inner_join':
464
+ state = 'select_join'
465
+ elif state == 'select_join':
300
466
  if token.ttype == T.Text.Whitespace:
301
- state = 'select_a_from_x_inner_join_'
302
- elif state == 'select_a_from_x_inner_join_':
467
+ state = 'select_join_'
468
+ elif state == 'select_join_':
303
469
  if token.ttype == T.Name:
304
- state = 'select_a_from_x_inner_join_y'
470
+ state = 'select_x_join_y'
305
471
 
306
- elif state == 'select_a_from_x_left':
472
+ elif state == 'select_from_x_left':
307
473
  if token.ttype == T.Text.Whitespace:
308
- state = 'select_a_from_x_left_'
309
- elif state == 'select_a_from_x_left_':
474
+ state = 'select_from_x_left_'
475
+ elif state == 'select_from_x_left_':
310
476
  if token.ttype == T.Keyword and token.value.lower() == 'join':
311
- state = 'select_a_from_x_inner_join'
477
+ state = 'select_join'
312
478
  elif token.ttype == T.Keyword and token.value.lower() == 'outer':
313
- state = 'select_a_from_x_left_outer'
314
- elif state == 'select_a_from_x_left_outer':
479
+ state = 'select_from_x_left_outer'
480
+ elif state == 'select_from_x_left_outer':
315
481
  if token.ttype == T.Text.Whitespace:
316
- state = 'select_a_from_x_left_outer_'
317
- elif state == 'select_a_from_x_left_outer_':
482
+ state = 'select_from_x_left_outer_'
483
+ elif state == 'select_from_x_left_outer_':
318
484
  if token.ttype == T.Keyword and token.value.lower() == 'join':
319
- state = 'select_a_from_x_inner_join_'
485
+ state = 'select_join_'
320
486
 
321
- elif state == 'select_a_from_x_right':
487
+ elif state == 'select_from_x_right':
322
488
  if token.ttype == T.Text.Whitespace:
323
- state = 'select_a_from_x_right_'
324
- elif state == 'select_a_from_x_right_':
489
+ state = 'select_from_x_right_'
490
+ elif state == 'select_from_x_right_':
325
491
  if token.ttype == T.Keyword and token.value.lower() == 'join':
326
- state = 'select_a_from_x_inner_join'
492
+ state = 'select_join'
327
493
  elif token.ttype == T.Keyword and token.value.lower() == 'outer':
328
- state = 'select_a_from_x_right_outer'
329
- elif state == 'select_a_from_x_right_outer':
494
+ state = 'select_from_x_right_outer'
495
+ elif state == 'select_from_x_right_outer':
330
496
  if token.ttype == T.Text.Whitespace:
331
- state = 'select_a_from_x_right_outer_'
332
- elif state == 'select_a_from_x_right_outer_':
497
+ state = 'select_from_x_right_outer_'
498
+ elif state == 'select_from_x_right_outer_':
333
499
  if token.ttype == T.Keyword and token.value.lower() == 'join':
334
- state = 'select_a_from_x_inner_join_'
500
+ state = 'select_join_'
335
501
 
336
- elif state == 'select_a_from_x_full':
502
+ elif state == 'select_from_x_full':
337
503
  if token.ttype == T.Text.Whitespace:
338
- state = 'select_a_from_x_full_'
339
- elif state == 'select_a_from_x_full_':
504
+ state = 'select_from_x_full_'
505
+ elif state == 'select_from_x_full_':
340
506
  if token.ttype == T.Keyword and token.value.lower() == 'outer':
341
- state = 'select_a_from_x_full_outer'
342
- elif state == 'select_a_from_x_full_outer':
507
+ state = 'select_from_x_full_outer'
508
+ elif state == 'select_from_x_full_outer':
343
509
  if token.ttype == T.Text.Whitespace:
344
- state = 'select_a_from_x_full_outer_'
345
- elif state == 'select_a_from_x_full_outer_':
510
+ state = 'select_from_x_full_outer_'
511
+ elif state == 'select_from_x_full_outer_':
346
512
  if token.ttype == T.Keyword and token.value.lower() == 'join':
347
- state = 'select_a_from_x_inner_join_'
513
+ state = 'select_join_'
348
514
 
349
- elif state == 'select_a_from_x_inner_join_y':
515
+ elif state == 'select_x_join_y':
350
516
  if token.ttype == T.Punctuation and token.value == ',':
351
- state = 'select_a_from_x_inner_join_y,'
517
+ state = 'select_x_join_y,'
352
518
  elif token.ttype == T.Text.Whitespace:
353
- state = 'select_a_from_x_inner_join_y_'
354
- elif state == 'select_a_from_x_inner_join_y,':
519
+ state = 'select_x_join_y_'
520
+ elif state == 'select_x_join_y,':
355
521
  if token.ttype == T.Name:
356
- state = 'select_a_from_x_inner_join_y'
357
- elif state == 'select_a_from_x_inner_join_y_':
522
+ state = 'select_x_join_y'
523
+ elif state == 'select_x_join_y_':
358
524
  if token.ttype == T.Keyword and token.value.lower() == 'on':
359
- state = 'select_a_from_x_inner_join_y_on'
360
- elif state == 'select_a_from_x_inner_join_y_on':
525
+ state = 'select_x_join_y_on'
526
+ elif state == 'select_x_join_y_on':
361
527
  if token.ttype == T.Text.Whitespace:
362
- state = 'select_a_from_x_inner_join_y_on_'
363
- elif state == 'select_a_from_x_inner_join_y_on_':
528
+ state = 'select_x_join_y_on_'
529
+ elif state == 'select_x_join_y_on_':
364
530
  if token.ttype == T.Name:
365
- state = 'select_a_from_x_inner_join_y_on_a'
366
- elif state == 'select_a_from_x_inner_join_y_on_a':
531
+ state = 'select_x_join_y_on_a'
532
+ elif state == 'select_x_join_y_on_a':
367
533
  if token.ttype == T.Operator.Comparison:
368
- state = 'select_a_from_x_inner_join_y_on_a='
369
- elif state == 'select_a_from_x_inner_join_y_on_a=':
534
+ state = 'select_x_join_y_on_a_op'
535
+ elif state == 'select_x_join_y_on_a_op':
370
536
  if token.ttype in [T.Literal.String.Single, T.Name]:
371
- state = 'select_a_from_x_inner_join_y_on_a=b'
372
- elif state == 'select_a_from_x_inner_join_y_on_a=b':
537
+ state = 'select_x_join_y_on_a_opb'
538
+ elif state == 'select_x_join_y_on_a_opb':
373
539
  if token.ttype == T.Text.Whitespace:
374
- state = 'select_a_from_x_inner_join_y_on_a=b_'
540
+ state = 'select_x_join_y_on_a_opb_'
375
541
  elif token.ttype == T.Punctuation and token.value == ',':
376
- state = 'select_a_from_x_inner_join_y_on_'
377
- elif state == 'select_a_from_x_inner_join_y_on_a=b_':
542
+ state = 'select_x_join_y_on_'
543
+ elif state == 'select_x_join_y_on_a_opb_':
378
544
  if token.ttype == T.Keyword and token.value.lower() in ['and', 'or']:
379
- state = 'select_a_from_x_inner_join'
545
+ state = 'select_join'
380
546
  elif token.ttype == T.Keyword and token.value.lower() == 'where':
381
- state = 'select_a_from_x_where'
547
+ state = 'select_where'
382
548
  elif token.ttype == T.Keyword and token.value.lower() == 'group':
383
- state = 'select_a_from_x_group'
549
+ state = 'select_from_x_group'
384
550
  elif token.ttype == T.Keyword and token.value.lower() == 'group by':
385
- state = 'select_a_from_x_group_by'
551
+ state = 'select_from_x_group_by'
386
552
  elif token.ttype == T.Keyword and token.value.lower() == 'limit':
387
- state = 'select_a_from_x_where_id=v_limit'
553
+ state = 'select_where_sc_limit'
388
554
 
389
555
  elif state == 'insert':
390
556
  if token.ttype == T.Text.Whitespace:
@@ -402,43 +568,43 @@ class SqlCompleter(Completer):
402
568
  if token.ttype == T.Text.Whitespace:
403
569
  state = 'insert_into_x_'
404
570
  elif token.ttype == T.Punctuation and token.value == '(':
405
- state = 'insert_into_x('
571
+ state = 'insert_into_x_lp_'
406
572
  elif state == 'insert_into_x_':
407
573
  if token.ttype == T.Punctuation and token.value == '(':
408
- state = 'insert_into_x('
574
+ state = 'insert_into_x_lp_'
409
575
  elif token.ttype == T.Keyword and token.value.lower() == 'values':
410
- state = 'insert_into_x_values'
411
- elif state == 'insert_into_x(':
576
+ state = 'insert_values'
577
+ elif state == 'insert_into_x_lp_':
412
578
  if token.ttype == T.Name:
413
- state = 'insert_into_x(a'
414
- elif state == 'insert_into_x(a':
579
+ state = 'insert_into_x_lp_a'
580
+ elif state == 'insert_into_x_lp_a':
415
581
  if token.ttype == T.Punctuation and token.value == ',':
416
- state = 'insert_into_x(a,'
582
+ state = 'insert_into_x_lp_a,'
417
583
  elif token.ttype == T.Punctuation and token.value == ')':
418
- state = 'insert_into_x(a)'
419
- elif state == 'insert_into_x(a,':
584
+ state = 'insert_into_x_lp_a_rp'
585
+ elif state == 'insert_into_x_lp_a,':
420
586
  if token.ttype == T.Name:
421
- state = 'insert_into_x(a'
422
- elif state == 'insert_into_x(a)':
587
+ state = 'insert_into_x_lp_a'
588
+ elif state == 'insert_into_x_lp_a_rp':
423
589
  if token.ttype == T.Text.Whitespace:
424
- state = 'insert_into_x(a)_'
425
- elif state == 'insert_into_x(a)_':
590
+ state = 'insert_into_x_lp_a_rp_'
591
+ elif state == 'insert_into_x_lp_a_rp_':
426
592
  if token.ttype == T.Keyword and token.value.lower() == 'values':
427
- state = 'insert_into_x_values'
428
- elif state == 'insert_into_x_values':
593
+ state = 'insert_values'
594
+ elif token.ttype == T.Keyword.DML and token.value.lower() == 'select':
595
+ state = 'select_'
596
+ elif state == 'insert_values':
429
597
  if token.ttype == T.Punctuation and token.value == '(':
430
- state = 'insert_into_x_values('
431
- elif state == 'insert_into_x_values(':
598
+ state = 'insert_values_lp_'
599
+ elif state == 'insert_values_lp_':
432
600
  if token.ttype in [T.Literal.String.Single, T.Name]:
433
- state = 'insert_into_x_values(v'
434
- elif state == 'insert_into_x_values(v':
601
+ state = 'insert_values_lp_v'
602
+ elif state == 'insert_values_lp_v':
435
603
  if token.ttype == T.Punctuation and token.value == ',':
436
- state = 'insert_into_x_values(v,'
437
- elif token.ttype == T.Punctuation and token.value == ')':
438
- state = 'insert_into_x_values(v)'
439
- elif state == 'insert_into_x_values(v,':
604
+ state = 'insert_values_lp_v,'
605
+ elif state == 'insert_values_lp_v,':
440
606
  if token.ttype in [T.Literal.String.Single, T.Name]:
441
- state = 'insert_into_x_values(v'
607
+ state = 'insert_values_lp_v'
442
608
 
443
609
  elif state == 'update':
444
610
  if token.ttype == T.Text.Whitespace:
@@ -460,41 +626,41 @@ class SqlCompleter(Completer):
460
626
  state = 'update_x_set_a'
461
627
  elif state == 'update_x_set_a':
462
628
  if token.ttype == T.Operator.Comparison:
463
- state = 'update_x_set_a='
464
- elif state == 'update_x_set_a=':
629
+ state = 'update_x_set_a_op'
630
+ elif state == 'update_x_set_a_op':
465
631
  if token.ttype in [T.Literal.String.Single, T.Name]:
466
- state = 'update_x_set_a=v'
467
- elif state == 'update_x_set_a=v':
632
+ state = 'update_x_set_sc'
633
+ elif state == 'update_x_set_sc':
468
634
  if token.ttype == T.Punctuation and token.value == ',':
469
- state = 'update_x_set_a=v,'
635
+ state = 'update_x_set_sc,'
470
636
  elif token.ttype == T.Text.Whitespace:
471
- state = 'update_x_set_a=v_'
472
- elif state == 'update_x_set_a=v,':
637
+ state = 'update_x_set_sc_'
638
+ elif state == 'update_x_set_sc,':
473
639
  if token.ttype == T.Name:
474
640
  state = 'update_x_set_a'
475
- elif state == 'update_x_set_a=v_':
641
+ elif state == 'update_x_set_sc_':
476
642
  if token.ttype == T.Punctuation and token.value == ',':
477
- state = 'update_x_set_a=v,'
643
+ state = 'update_x_set_sc,'
478
644
  elif token.ttype == T.Keyword and token.value.lower() == 'where':
479
- state = 'update_x_set_a=v_where'
480
- elif state == 'update_x_set_a=v_where':
645
+ state = 'update_where'
646
+ elif state == 'update_where':
481
647
  if token.ttype == T.Text.Whitespace:
482
- state = 'update_x_set_a=v_where_'
483
- elif state == 'update_x_set_a=v_where_':
648
+ state = 'update_where_'
649
+ elif state == 'update_where_':
484
650
  if token.ttype == T.Name:
485
- state = 'update_x_set_a=v_where_id'
486
- elif state == 'update_x_set_a=v_where_id':
651
+ state = 'update_where_a'
652
+ elif state == 'update_where_a':
487
653
  if token.ttype == T.Operator.Comparison:
488
- state = 'update_x_set_a=v_where_id='
489
- elif state == 'update_x_set_a=v_where_id=':
654
+ state = 'update_where_a_op'
655
+ elif state == 'update_where_a_op':
490
656
  if token.ttype in [T.Literal.String.Single, T.Name]:
491
- state = 'update_x_set_a=v_where_id=v'
492
- elif state == 'update_x_set_a=v_where_id=v':
657
+ state = 'update_where_sc'
658
+ elif state == 'update_where_sc':
493
659
  if token.ttype == T.Text.Whitespace:
494
- state = 'update_x_set_a=v_where_id=v_'
495
- elif state == 'update_x_set_a=v_where_id=v_':
660
+ state = 'update_where_sc_'
661
+ elif state == 'update_where_sc_':
496
662
  if token.ttype == T.Keyword and token.value.lower() in ['and', 'or']:
497
- state = 'update_x_set_a=v_where'
663
+ state = 'update_where'
498
664
 
499
665
  elif state == 'delete':
500
666
  if token.ttype == T.Text.Whitespace:
@@ -513,25 +679,25 @@ class SqlCompleter(Completer):
513
679
  state = 'delete_from_x_'
514
680
  elif state == 'delete_from_x_':
515
681
  if token.ttype == T.Keyword and token.value.lower() == 'where':
516
- state = 'delete_from_x_where'
517
- elif state == 'delete_from_x_where':
682
+ state = 'delete_where'
683
+ elif state == 'delete_where':
518
684
  if token.ttype == T.Text.Whitespace:
519
- state = 'delete_from_x_where_'
520
- elif state == 'delete_from_x_where_':
685
+ state = 'delete_where_'
686
+ elif state == 'delete_where_':
521
687
  if token.ttype == T.Name:
522
- state = 'delete_from_x_where_id'
523
- elif state == 'delete_from_x_where_id':
688
+ state = 'delete_where_a'
689
+ elif state == 'delete_where_a':
524
690
  if token.ttype == T.Operator.Comparison:
525
- state = 'delete_from_x_where_id='
526
- elif state == 'delete_from_x_where_id=':
691
+ state = 'delete_where_a_op'
692
+ elif state == 'delete_where_a_op':
527
693
  if token.ttype in [T.Literal.String.Single, T.Name]:
528
- state = 'delete_from_x_where_id=v'
529
- elif state == 'delete_from_x_where_id=v':
694
+ state = 'delete_where_sc'
695
+ elif state == 'delete_where_sc':
530
696
  if token.ttype == T.Text.Whitespace:
531
- state = 'delete_from_x_where_id=v_'
532
- elif state == 'delete_from_x_where_id=v_':
697
+ state = 'delete_where_sc_'
698
+ elif state == 'delete_where_sc_':
533
699
  if token.ttype == T.Keyword and token.value.lower() in ['and', 'or']:
534
- state = 'delete_from_x_where'
700
+ state = 'delete_where'
535
701
 
536
702
  return state
537
703
 
@@ -46,15 +46,22 @@ class TermCompleter(WordCompleter):
46
46
  if self.ignore_case:
47
47
  word = word.lower()
48
48
 
49
- if word_before_cursor in ['(', ',', '=']:
50
- return True
51
-
52
49
  if self.match_middle:
53
50
  return word_before_cursor in word
54
51
  else:
55
52
  return word.startswith(word_before_cursor)
56
53
 
57
54
  for a in words:
55
+ if word_before_cursor in ['(', ',', '=']:
56
+ display = self.display_dict.get(a, a)
57
+ display_meta = self.meta_dict.get(a, "")
58
+ yield Completion(
59
+ a,
60
+ 0,
61
+ display=display,
62
+ display_meta=display_meta,
63
+ )
64
+
58
65
  if word_matches(a):
59
66
  display = self.display_dict.get(a, a)
60
67
  display_meta = self.meta_dict.get(a, "")
adam/version.py CHANGED
@@ -1,5 +1,5 @@
1
1
  #!/usr/bin/env python
2
2
  # -*- coding: utf-8 -*-
3
3
 
4
- __version__ = "2.0.55" #: the working version
4
+ __version__ = "2.0.57" #: the working version
5
5
  __release__ = "1.0.0" #: the release version
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: kaqing
3
- Version: 2.0.55
3
+ Version: 2.0.57
4
4
  Summary: UNKNOWN
5
5
  Home-page: UNKNOWN
6
6
  License: UNKNOWN
@@ -14,7 +14,7 @@ adam/repl_commands.py,sha256=WA90Rl27Juctzr3U3kfCDk5N-oYMKlfWbZeafUgk7k0,4723
14
14
  adam/repl_session.py,sha256=uIogcvWBh7wd8QQ-p_JgLsyJ8YJgINw5vOd6JIsd7Vo,472
15
15
  adam/repl_state.py,sha256=591d7gV6uQSFtm7IWdlIYAHjfAzs9bdvIkwlIAeKddE,7540
16
16
  adam/utils.py,sha256=2DoWsrcaioFFH0-RjT30qelVRPUJqCGTfz_ucfE7F8g,7406
17
- adam/version.py,sha256=1igvrn67AjTOcviySrpDWebyfe7wHN1EWQt56kFGM58,139
17
+ adam/version.py,sha256=kXINOe-uvId2Kbv9pAAleFVyJC-tHoAx6EmOAUzCUjY,139
18
18
  adam/checks/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
19
19
  adam/checks/check.py,sha256=Qopr3huYcMu2bzQgb99dEUYjFzkjKHRI76S6KA9b9Rk,702
20
20
  adam/checks/check_context.py,sha256=FEHkQ32jY1EDopQ2uYWqy9v7aEEX1orLpJWhopwAlh4,402
@@ -164,9 +164,8 @@ adam/k8s_utils/services.py,sha256=EOJJGACVbbRvu5T3rMKqIJqgYic1_MSJ17EA0TJ6UOk,31
164
164
  adam/k8s_utils/statefulsets.py,sha256=hiBOmJZ3KTI6_naAFzNoW1NoYnnBG35BZ7RMdPhNC6o,4664
165
165
  adam/k8s_utils/volumes.py,sha256=RIBmlOSWM3V3QVXLCFT0owVOyh4rGG1ETp521a-6ndo,1137
166
166
  adam/sql/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
167
- adam/sql/sql_completer.py,sha256=rl7UlL5kthXOmcPBK3LFD1H0S2yDZMIQPbov1x8Wo9w,29819
168
- adam/sql/sql_utils.py,sha256=MLoxB9h22WZiANu0SZzmBJcY2gtb6f_D4jnoJEjLgPc,171
169
- adam/sql/term_completer.py,sha256=O-sUxFVc1DJmPQCdT-XPK2SSkUe4AL1dw8ZPXXicATY,2273
167
+ adam/sql/sql_completer.py,sha256=BAg1Ogn_q1JSjpQhN-2jVzIuMoH1FpFzn_xpMRvB-TQ,35882
168
+ adam/sql/term_completer.py,sha256=VCCMPUzvh_9lwIOwqQmeijM0V2JPADkBbNV4HQIqDCw,2538
170
169
  adam/sso/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
171
170
  adam/sso/authenticator.py,sha256=BCm16L9zf5aLU47-sTCnudn2zLPwd8M2wwRminJfsqw,615
172
171
  adam/sso/authn_ad.py,sha256=fDW8UR3WWykny5Awa5dQjjBUSFzIDz4aMn-lwXoABl8,5857
@@ -177,8 +176,8 @@ adam/sso/idp.py,sha256=fvcwUw_URTgsO6ySaqTIw0zQT2qRO1IPSGhf6rPtybo,5804
177
176
  adam/sso/idp_login.py,sha256=QAtCUeDTVWliJy40RK_oac8Vgybr13xH8wzeBoxPaa8,1754
178
177
  adam/sso/idp_session.py,sha256=9BUHNRf70u4rVKrVY1HKPOEmOviXvkjam8WJxmXSKIM,1735
179
178
  adam/sso/sso_config.py,sha256=5N8WZgIJQBtHUy585XLRWKjpU87_v6QluyNK9E27D5s,2459
180
- kaqing-2.0.55.dist-info/METADATA,sha256=3kKBRQ9yQ_KbdoGuD42fhkxDprEvWUEsRe5UO67FhvA,132
181
- kaqing-2.0.55.dist-info/WHEEL,sha256=tZoeGjtWxWRfdplE7E3d45VPlLNQnvbKiYnx7gwAy8A,92
182
- kaqing-2.0.55.dist-info/entry_points.txt,sha256=SkzhuQJUWsXOzHeZ5TgQ2c3_g53UGK23zzJU_JTZOZI,39
183
- kaqing-2.0.55.dist-info/top_level.txt,sha256=8_2PZkwBb-xDcnc8a2rAbQeJhXKXskc7zTP7pSPa1fw,5
184
- kaqing-2.0.55.dist-info/RECORD,,
179
+ kaqing-2.0.57.dist-info/METADATA,sha256=AJUgGbSTZ4aZy5vdBdNW076Iv-L5SKzR00IFzWOtDUk,132
180
+ kaqing-2.0.57.dist-info/WHEEL,sha256=tZoeGjtWxWRfdplE7E3d45VPlLNQnvbKiYnx7gwAy8A,92
181
+ kaqing-2.0.57.dist-info/entry_points.txt,sha256=SkzhuQJUWsXOzHeZ5TgQ2c3_g53UGK23zzJU_JTZOZI,39
182
+ kaqing-2.0.57.dist-info/top_level.txt,sha256=8_2PZkwBb-xDcnc8a2rAbQeJhXKXskc7zTP7pSPa1fw,5
183
+ kaqing-2.0.57.dist-info/RECORD,,
adam/sql/sql_utils.py DELETED
@@ -1,5 +0,0 @@
1
- import re
2
-
3
- def safe_terms(text: str):
4
- tokens = re.findall(r'"[^"]+"|\b\w+\b|\S', text)
5
- return tokens, len(tokens) > 1 or text.startswith(' ') or text.endswith(' ')