kaqing 2.0.58__py3-none-any.whl → 2.0.60__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
@@ -9,6 +9,10 @@ from adam.sql.term_completer import TermCompleter
9
9
 
10
10
  columns = TermCompleter(['id', 'x.', 'y.', 'z.'])
11
11
 
12
+ def fr(*args):
13
+ for arg in args:
14
+ pass
15
+
12
16
  class SqlCompleter(Completer):
13
17
  # <select_statement> ::= SELECT <select_list>
14
18
  # FROM <table_expression>
@@ -137,6 +141,7 @@ class SqlCompleter(Completer):
137
141
  self.dml = dml
138
142
  self.tables = tables
139
143
  self.debug = debug
144
+ self.machine = self.automata()
140
145
 
141
146
  def get_completions(
142
147
  self, document: Document, complete_event: CompleteEvent
@@ -155,14 +160,14 @@ class SqlCompleter(Completer):
155
160
  state = self.traverse_tokens(text, statement.tokens)
156
161
  if self.debug:
157
162
  print('\n =>', state)
158
- if state == 'dml_incomplete':
163
+ if state == '':
159
164
  completer = TermCompleter(['select', 'insert', 'delete', 'update'])
160
165
 
161
166
  elif state == 'select_':
162
167
  completer = TermCompleter(['*'])
163
168
  elif state == 'select_a':
164
169
  completer = TermCompleter(['from'])
165
- elif state == 'select_a,':
170
+ elif state == 'select_a_comma_':
166
171
  completer = TermCompleter(['*'])
167
172
  elif state == 'select_a_':
168
173
  completer = TermCompleter(['from'])
@@ -172,11 +177,11 @@ class SqlCompleter(Completer):
172
177
  completer = TermCompleter(['as', 'where', 'inner', 'left', 'right', 'full', 'group', 'limit'])
173
178
  elif state == "select_from_x_as_x_":
174
179
  completer = TermCompleter(['where', 'inner', 'left', 'right', 'full', 'group', 'limit'])
175
- elif state == "select_from_x,":
180
+ elif state == "select_from_x_comma_":
176
181
  completer = TermCompleter(self.tables())
177
182
  elif state == "select_from_x_as_":
178
183
  completer = TermCompleter(['x', 'y', 'z'])
179
- elif state == "select_from_x_as_x,":
184
+ elif state == "select_from_x_as_x_comma_":
180
185
  completer = TermCompleter(self.tables())
181
186
  elif state == "select_where_":
182
187
  completer = columns
@@ -184,21 +189,27 @@ class SqlCompleter(Completer):
184
189
  completer = TermCompleter(['=', '<', '<=', '>', '>=', '<>', 'like', 'not', 'in'])
185
190
  elif state == "select_where_a_not_":
186
191
  completer = TermCompleter(['like', 'in'])
192
+ elif state == "select_where_a_in":
193
+ completer = TermCompleter(['('])
194
+ elif state == "select_where_a_in_lp_":
195
+ completer = TermCompleter(["'", ')'])
196
+ elif state == "select_where_a_in_lp_a_comma_":
197
+ completer = TermCompleter(["'"])
187
198
  elif state == "select_where_a_op":
188
199
  completer = TermCompleter(["'"])
189
200
  elif state == "select_where_sc_":
190
201
  completer = TermCompleter(['and', 'or', 'group', 'limit'])
191
202
  elif state == "select_where_sc_limit_":
192
203
  completer = TermCompleter(['1'])
193
- elif state == "select_from_x_group_":
204
+ elif state == "select_group_":
194
205
  completer = TermCompleter(['by'])
195
- elif state == "select_from_x_group_by_":
206
+ elif state == "select_group_by_":
196
207
  completer = columns
197
- elif state == "select_from_x_group_by_a,":
208
+ elif state == "select_group_by_a_comma_":
198
209
  completer = columns
199
- elif state == "select_from_x_group_by_a_":
210
+ elif state == "select_group_by_a_":
200
211
  completer = TermCompleter(['limit'])
201
- elif state == "select_from_x_group_by_a_limit_":
212
+ elif state == "select_group_by_a_limit_":
202
213
  completer = TermCompleter(['1'])
203
214
  elif state == "select_from_x_inner_":
204
215
  completer = TermCompleter(['join'])
@@ -214,7 +225,7 @@ class SqlCompleter(Completer):
214
225
  completer = TermCompleter(['='])
215
226
  elif state == "select_x_join_y_on_a_op":
216
227
  completer = columns
217
- elif state == "select_x_join_y_on_a_opb_":
228
+ elif state == "select_x_join_y_on_a_op_b_":
218
229
  completer = TermCompleter(['where', 'group', 'limit'])
219
230
  elif state == "select_from_x_left_":
220
231
  completer = TermCompleter(['outer', 'join'])
@@ -237,9 +248,9 @@ class SqlCompleter(Completer):
237
248
  completer = TermCompleter(['values(', 'select'])
238
249
  elif state == "insert_into_x_lp_":
239
250
  completer = columns
240
- elif state == "insert_into_x_lp_a,":
251
+ elif state == "insert_into_x_lp_a_comma_":
241
252
  completer = columns
242
- elif state == "insert_into_x_lp_a_rp_":
253
+ elif state == "insert_into_x_lp_a_rp__":
243
254
  completer = TermCompleter(['values(', 'select'])
244
255
  elif state == "insert_values":
245
256
  completer = TermCompleter(['('])
@@ -250,13 +261,13 @@ class SqlCompleter(Completer):
250
261
  completer = TermCompleter(self.tables())
251
262
  elif state == "update_x_":
252
263
  completer = TermCompleter(['set'])
253
- elif state in ["update_x_set_", "update_x_set_sc,"]:
264
+ elif state in ["update_set_", "update_set_sc_comma_"]:
254
265
  completer = columns
255
- elif state == "update_x_set_a":
266
+ elif state == "update_set_a":
256
267
  completer = TermCompleter(['='])
257
- elif state == "update_x_set_a_op":
268
+ elif state == "update_set_a_op":
258
269
  completer = TermCompleter(["'"])
259
- elif state == "update_x_set_sc_":
270
+ elif state == "update_set_sc_":
260
271
  completer = TermCompleter(['where'])
261
272
  elif state == "update_where_":
262
273
  completer = columns
@@ -284,8 +295,201 @@ class SqlCompleter(Completer):
284
295
  for c in completer.get_completions(document, complete_event):
285
296
  yield c
286
297
 
287
- def traverse_tokens(self, text: str, tokens: list[Token], state: str = None, indent=0):
288
- # state: str = None
298
+ def automata(self):
299
+ y = [
300
+ ' > select > select',
301
+ 'select_ > name|* > select_a',
302
+ 'select_a > , > select_a_comma_',
303
+ 'select_a_comma_ > name|* > select_a',
304
+ 'select_a_ > from > select_from',
305
+ 'select_from_ > name > select_from_x',
306
+ 'select_from_x > , > select_from_x_comma_',
307
+ 'select_from_x_comma_ > name > select_from_x',
308
+ 'select_from_x_',
309
+ 'select_from_x_as_x_ > , > select_from_x_comma_',
310
+ '- > as > select_from_x_as',
311
+ '- > where > select_where',
312
+ '- > limit > select_where_sc_limit',
313
+ '- > group > select_group',
314
+ '- > group by > select_group_by',
315
+ '- > inner > select_from_x_inner',
316
+ '- > inner join > select_join',
317
+ '- > left > select_from_x_left',
318
+ '- > left join > select_join',
319
+ '- > left outer join > select_join',
320
+ '- > right > select_from_x_right',
321
+ '- > right join > select_join',
322
+ '- > right outer join > select_join',
323
+ '- > full > select_from_x_full',
324
+ '- > full outer join > select_join',
325
+ 'select_from_x_as_ > name > select_from_x_as_x',
326
+ 'select_from_x_as_x > , > select_from_x_as_x_comma_',
327
+ 'select_from_x_as_x_comma_ > name > select_from_x_as_x',
328
+ 'select_where_ > name > select_where_a',
329
+ 'select_where_a > comparison > select_where_a_op',
330
+ 'select_where_a_ > comparison > select_where_a_op',
331
+ '- > not > select_where_a_not',
332
+ '- > in > select_where_a_in',
333
+ 'select_where_a_not_ > comparison > select_where_a_not_op',
334
+ '- > in > select_where_a_in',
335
+ 'select_where_a_in > ( > select_where_a_in_lp_',
336
+ 'select_where_a_in_lp_ > name|single > select_where_a_in_lp_a',
337
+ 'select_where_a_in_lp_a > , > select_where_a_in_lp_a_comma_',
338
+ '- > ) > select_where_sc',
339
+ 'select_where_a_in_lp_a_comma_ > name|single > select_where_a_in_lp_a',
340
+ 'select_where_a_not_op > name|single > select_where_sc',
341
+ 'select_where_a_op > name|single > select_where_sc',
342
+ 'select_where_sc_ > and|or > select_where',
343
+ '- > group > select_group',
344
+ '- > group by > select_group_by',
345
+ '- > limit > select_where_sc_limit',
346
+ 'select_group_ > by > select_group_by',
347
+ 'select_group_by_ > name > select_group_by_a',
348
+ 'select_group_by_a > , > select_group_by_a_comma_',
349
+ 'select_group_by_a_comma_ > name > select_group_by_a',
350
+ 'select_group_by_a_ > limit > select_where_sc_limit',
351
+ 'select_where_sc_limit > _ > select_where_sc_limit_',
352
+ 'select_where_x_inner_ > join > select_join',
353
+ 'select_join_ > name > select_x_join_y',
354
+ 'select_from_x_left_ > join > select_join',
355
+ '- > outer > select_from_x_left_outer',
356
+ 'select_from_x_left_outer_ > join > select_join',
357
+ 'select_from_x_ > left outer join > select_join',
358
+ 'select_from_x_right_ > join > select_join',
359
+ '- > outer > select_from_x_right_outer',
360
+ 'select_from_x_right_outer_ > join > select_join',
361
+ 'select_from_x_full_ > join > select_join',
362
+ '- > outer > select_from_x_full_outer',
363
+ 'select_from_x_full_outer_ > join > select_join',
364
+ 'select_x_join_y > , > select_x_join_y_comma_',
365
+ 'select_x_join_y_comma_ > name > select_x_join_y',
366
+ 'select_x_join_y_ > on > select_x_join_y_on',
367
+ 'select_x_join_y_on_ > name > select_x_join_y_on_a',
368
+ 'select_x_join_y_on_a > comparison > select_x_join_y_on_a_op',
369
+ 'select_x_join_y_on_a_op > name|single > select_x_join_y_on_a_op_b',
370
+ 'select_x_join_y_on_a_op_b > , > select_x_join_y_on_',
371
+ 'select_x_join_y_on_a_op_b_ > and|or > select_join',
372
+ '- > where > select_where',
373
+ '- > group > select_group',
374
+ '- > group by > select_group_by',
375
+ '- > limit > select_where_sc_limit',
376
+
377
+
378
+ ' > insert > insert',
379
+ 'insert_ > into > insert_into',
380
+ 'insert_into_ > name > insert_into_x',
381
+ 'insert_into_x > ( > insert_into_x_lp_',
382
+ 'insert_into_x_ > ( > insert_into_x_lp_',
383
+ '- > values > insert_values',
384
+ 'insert_into_x_lp_ > name > insert_into_x_lp_a',
385
+ 'insert_into_x_lp_a > , > insert_into_x_lp_a_comma_',
386
+ '- > ) > insert_into_x_lp_a_rp_',
387
+ 'insert_into_x_lp_a_comma_ > name > insert_into_x_lp_a',
388
+ 'insert_into_x_lp_a_rp__ > values > insert_values',
389
+ '- > select > select',
390
+ 'insert_values > ( > insert_values_lp_',
391
+ 'insert_values_lp_ > name|single > insert_values_lp_v',
392
+ 'insert_values_lp_v > , > insert_values_lp_v_comma_',
393
+ 'insert_values_lp_v_comma_ > name|single > insert_values_lp_v',
394
+
395
+
396
+ ' > update > update',
397
+ 'update_ > name > update_x',
398
+ 'update_x_ > set > update_set',
399
+ 'update_set_ > name > update_set_a',
400
+ 'update_set_a > comparison > update_set_a_op',
401
+ 'update_set_a_op > name|single > update_set_sc',
402
+ 'update_set_sc > , > update_set_sc_comma_',
403
+ 'update_set_sc_comma_ > name > update_set_a',
404
+ 'update_set_sc_ > , > update_set_sc_comma_',
405
+ '- > where > update_where',
406
+ 'update_where_ > name > update_where_a',
407
+ 'update_where_a > comparison > update_where_a_op',
408
+ 'update_where_a_op > name|single > update_where_sc',
409
+ 'update_where_sc_ > and|or > update_where',
410
+
411
+
412
+ ' > delete > delete',
413
+ 'delete_ > from > delete_from',
414
+ 'delete_from_ > name > delete_from_x',
415
+ 'delete_from_x_ > where > delete_where',
416
+ 'delete_where_ > name > delete_where_a',
417
+ 'delete_where_a > comparison > delete_where_a_op',
418
+ 'delete_where_a_op > name|single > delete_where_sc',
419
+ 'delete_where_sc_ > and|or > delete_where',
420
+ ]
421
+
422
+ def add_space_transition(from_s: str):
423
+ # add whitespace transition if a state with trailing whitespace is found from from states, for example, select > _ > select_
424
+ if from_s.endswith('_') and not from_s.endswith('_comma_') and not from_s.endswith('_lp_') and not from_s.endswith('_rp_'):
425
+ if self.debug:
426
+ print(f'{from_s[:-1]} > _ = {to_s}')
427
+ machine[f'{from_s[:-1]} > _'] = from_s
428
+
429
+ machine: dict[str, str] = {}
430
+
431
+ from_ss_to_add = []
432
+ from_ss = ['']
433
+ token = None
434
+ tokens = []
435
+ to_s = None
436
+ for l in y:
437
+ tks = l.split('>')
438
+ if l.startswith('-'):
439
+ token = tks[1].strip(' ')
440
+ if len(tks) > 2:
441
+ to_s = tks[2].strip(' ')
442
+ for from_s in from_ss:
443
+ tokens = [token]
444
+ if '|' in token:
445
+ tokens = token.strip(' ').split('|')
446
+
447
+ for t in tokens:
448
+ if self.debug:
449
+ print(f'{from_s} > {t} = {to_s}')
450
+ machine[f'{from_s} > {t}'] = to_s
451
+ else:
452
+ if len(tks) == 1:
453
+ from_s = tks[0].strip(' ')
454
+ add_space_transition(from_s)
455
+ from_ss_to_add.append(f'{from_s}')
456
+ continue
457
+
458
+ from_ss = []
459
+ from_ss.extend(from_ss_to_add)
460
+ from_ss_to_add = []
461
+ from_ss.append(f'{tks[0].strip(" ")}')
462
+ for from_s in from_ss:
463
+ add_space_transition(from_s)
464
+ token = tks[1].strip(' ')
465
+ tokens = [token]
466
+ if len(tks) > 2:
467
+ to_s = tks[2].strip(' ')
468
+
469
+ if '|' in token:
470
+ tokens = token.split('|')
471
+
472
+ for t in tokens:
473
+ if self.debug:
474
+ print(f'{from_s} > {t} = {to_s}')
475
+ machine[f'{from_s} > {t}'] = to_s
476
+
477
+ return machine
478
+
479
+ def traverse_tokens(self, text: str, tokens: list[Token], state: str = '', indent=0):
480
+ keywords = [
481
+ 'select', 'from', 'as', 'not', 'in', 'where',
482
+ 'and', 'or', 'group', 'by', 'group by', 'limit',
483
+ 'inner join', 'on', 'left', 'right', 'full', 'outer', 'left outer join',
484
+ 'left join', 'right outer join', 'right join', 'full join', 'full outer join',
485
+
486
+ 'insert', 'into', 'values',
487
+
488
+ 'update', 'where', 'set',
489
+
490
+ 'delete'
491
+ ]
492
+
289
493
  for token in tokens:
290
494
  if self.debug:
291
495
  if token.ttype == T.Whitespace:
@@ -300,404 +504,33 @@ class SqlCompleter(Completer):
300
504
  else:
301
505
  print(f'{token.value}:{typ} ', end='')
302
506
  # print(" " * indent + f"Token: {token.value}, Type: {token.ttype}@{token.ttype.__class__}")
303
- node: str = None
507
+
304
508
  if token.is_group:
305
509
  state = self.traverse_tokens(text, token.tokens, state, indent + 1)
306
510
  else:
307
- if not state:
308
- if token.ttype == T.Keyword.DML and token.value.lower() == 'select':
309
- state = 'select'
310
- if token.ttype == T.Keyword.DML and token.value.lower() == 'insert':
311
- state = 'insert'
312
- if token.ttype == T.Keyword.DML and token.value.lower() == 'update':
313
- state = 'update'
314
- if token.ttype == T.Keyword.DML and token.value.lower() == 'delete':
315
- state = 'delete'
316
- elif token.ttype == T.Name:
317
- state = 'dml_incomplete'
318
-
319
- elif state == 'select':
320
- if token.ttype == T.Text.Whitespace:
321
- state = 'select_'
322
- elif state == 'select_':
323
- if token.ttype == T.Name or token.ttype == T.Wildcard:
324
- state = 'select_a'
325
- elif state == 'select_a':
326
- if token.ttype == T.Text.Whitespace:
327
- state = 'select_a_'
328
- elif token.ttype == T.Punctuation and token.value == ',':
329
- state = 'select_a,'
330
- elif state == 'select_a,':
331
- if token.ttype == T.Name or token.ttype == T.Wildcard:
332
- state = 'select_a'
333
- elif state == 'select_a_':
334
- if token.ttype == T.Keyword and token.value.lower() == 'from':
335
- state = 'select_from'
336
- elif state == 'select_from':
337
- if token.ttype == T.Text.Whitespace:
338
- state = 'select_from_'
339
- elif state == 'select_from_':
340
- if token.ttype == T.Name:
341
- state = 'select_from_x'
342
- elif state == 'select_from_x':
343
- if token.ttype == T.Text.Whitespace:
344
- state = 'select_from_x_'
345
- elif token.ttype == T.Punctuation and token.value == ',':
346
- state = 'select_from_x,'
347
- elif state == 'select_from_x,':
348
- if token.ttype == T.Name:
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'
357
- elif token.ttype == T.Keyword and token.value.lower() == 'limit':
358
- state = 'select_where_sc_limit'
359
- elif token.ttype == T.Keyword and token.value.lower() == 'group':
360
- state = 'select_from_x_group'
361
- elif token.ttype == T.Keyword and token.value.lower() == 'group by':
362
- state = 'select_from_x_group_by'
363
- elif token.ttype == T.Keyword and token.value.lower() == 'inner':
364
- state = 'select_from_x_inner'
365
- elif token.ttype == T.Keyword and token.value.lower() == 'inner join':
366
- state = 'select_join'
367
- elif token.ttype == T.Keyword and token.value.lower() == 'left':
368
- state = 'select_from_x_left'
369
- elif token.ttype == T.Keyword and token.value.lower() in ['left join', 'left outer join']:
370
- state = 'select_join'
371
- elif token.ttype == T.Keyword and token.value.lower() == 'right':
372
- state = 'select_from_x_right'
373
- elif token.ttype == T.Keyword and token.value.lower() in ['right join', 'right outer join']:
374
- state = 'select_join'
375
- elif token.ttype == T.Keyword and token.value.lower() == 'full':
376
- state = 'select_from_x_full'
377
- elif token.ttype == T.Keyword and token.value.lower() == 'full outer join':
378
- state = 'select_join'
379
- elif state == 'select_from_x_as':
380
- if token.ttype == T.Text.Whitespace:
381
- state = 'select_from_x_as_'
382
- elif state == 'select_from_x_as_':
383
- if token.ttype == T.Name:
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_':
405
- if token.ttype == T.Operator.Comparison:
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':
419
- if token.ttype in [T.Literal.String.Single, T.Name]:
420
- state = 'select_where_sc'
421
- elif state == 'select_where_sc':
422
- if token.ttype == T.Text.Whitespace:
423
- state = 'select_where_sc_'
424
- elif state == 'select_where_sc_':
425
- if token.ttype == T.Keyword and token.value.lower() in ['and', 'or']:
426
- state = 'select_where'
427
- elif token.ttype == T.Keyword and token.value.lower() == 'group':
428
- state = 'select_from_x_group'
429
- elif token.ttype == T.Keyword and token.value.lower() == 'group by':
430
- state = 'select_from_x_group_by'
431
- elif token.ttype == T.Keyword and token.value.lower() == 'limit':
432
- state = 'select_where_sc_limit'
433
- elif state == 'select_from_x_group':
434
- if token.ttype == T.Text.Whitespace:
435
- state = 'select_from_x_group_'
436
- elif state == 'select_from_x_group_':
437
- if token.ttype == T.Keyword and token.value.lower() == 'by':
438
- state = 'select_from_x_group_by'
439
- elif state == 'select_from_x_group_by':
440
- if token.ttype == T.Text.Whitespace:
441
- state = 'select_from_x_group_by_'
442
- elif state == 'select_from_x_group_by_':
443
- if token.ttype == T.Name:
444
- state = 'select_from_x_group_by_a'
445
- elif state == 'select_from_x_group_by_a':
446
- if token.ttype == T.Text.Whitespace:
447
- state = 'select_from_x_group_by_a_'
448
- elif token.ttype == T.Punctuation and token.value == ',':
449
- state = 'select_from_x_group_by_a,'
450
- elif state == 'select_from_x_group_by_a,':
451
- if token.ttype == T.Name:
452
- state = 'select_from_x_group_by_a'
453
- elif state == 'select_from_x_group_by_a_':
454
- if token.ttype == T.Keyword and token.value.lower() == 'limit':
455
- state = 'select_where_sc_limit'
456
- elif state == 'select_where_sc_limit':
457
- if token.ttype == T.Text.Whitespace:
458
- state = 'select_where_sc_limit_'
459
- elif state == 'select_from_x_inner':
460
- if token.ttype == T.Text.Whitespace:
461
- state = 'select_from_x_inner_'
462
- elif state == 'select_from_x_inner_':
463
- if token.ttype == T.Keyword and token.value.lower() == 'join':
464
- state = 'select_join'
465
- elif state == 'select_join':
466
- if token.ttype == T.Text.Whitespace:
467
- state = 'select_join_'
468
- elif state == 'select_join_':
469
- if token.ttype == T.Name:
470
- state = 'select_x_join_y'
471
-
472
- elif state == 'select_from_x_left':
473
- if token.ttype == T.Text.Whitespace:
474
- state = 'select_from_x_left_'
475
- elif state == 'select_from_x_left_':
476
- if token.ttype == T.Keyword and token.value.lower() == 'join':
477
- state = 'select_join'
478
- elif token.ttype == T.Keyword and token.value.lower() == 'outer':
479
- state = 'select_from_x_left_outer'
480
- elif state == 'select_from_x_left_outer':
481
- if token.ttype == T.Text.Whitespace:
482
- state = 'select_from_x_left_outer_'
483
- elif state == 'select_from_x_left_outer_':
484
- if token.ttype == T.Keyword and token.value.lower() == 'join':
485
- state = 'select_join_'
486
-
487
- elif state == 'select_from_x_right':
488
- if token.ttype == T.Text.Whitespace:
489
- state = 'select_from_x_right_'
490
- elif state == 'select_from_x_right_':
491
- if token.ttype == T.Keyword and token.value.lower() == 'join':
492
- state = 'select_join'
493
- elif token.ttype == T.Keyword and token.value.lower() == 'outer':
494
- state = 'select_from_x_right_outer'
495
- elif state == 'select_from_x_right_outer':
496
- if token.ttype == T.Text.Whitespace:
497
- state = 'select_from_x_right_outer_'
498
- elif state == 'select_from_x_right_outer_':
499
- if token.ttype == T.Keyword and token.value.lower() == 'join':
500
- state = 'select_join_'
501
-
502
- elif state == 'select_from_x_full':
503
- if token.ttype == T.Text.Whitespace:
504
- state = 'select_from_x_full_'
505
- elif state == 'select_from_x_full_':
506
- if token.ttype == T.Keyword and token.value.lower() == 'outer':
507
- state = 'select_from_x_full_outer'
508
- elif state == 'select_from_x_full_outer':
509
- if token.ttype == T.Text.Whitespace:
510
- state = 'select_from_x_full_outer_'
511
- elif state == 'select_from_x_full_outer_':
512
- if token.ttype == T.Keyword and token.value.lower() == 'join':
513
- state = 'select_join_'
514
-
515
- elif state == 'select_x_join_y':
516
- if token.ttype == T.Punctuation and token.value == ',':
517
- state = 'select_x_join_y,'
518
- elif token.ttype == T.Text.Whitespace:
519
- state = 'select_x_join_y_'
520
- elif state == 'select_x_join_y,':
521
- if token.ttype == T.Name:
522
- state = 'select_x_join_y'
523
- elif state == 'select_x_join_y_':
524
- if token.ttype == T.Keyword and token.value.lower() == 'on':
525
- state = 'select_x_join_y_on'
526
- elif state == 'select_x_join_y_on':
527
- if token.ttype == T.Text.Whitespace:
528
- state = 'select_x_join_y_on_'
529
- elif state == 'select_x_join_y_on_':
530
- if token.ttype == T.Name:
531
- state = 'select_x_join_y_on_a'
532
- elif state == 'select_x_join_y_on_a':
533
- if token.ttype == T.Operator.Comparison:
534
- state = 'select_x_join_y_on_a_op'
535
- elif state == 'select_x_join_y_on_a_op':
536
- if token.ttype in [T.Literal.String.Single, T.Name]:
537
- state = 'select_x_join_y_on_a_opb'
538
- elif state == 'select_x_join_y_on_a_opb':
539
- if token.ttype == T.Text.Whitespace:
540
- state = 'select_x_join_y_on_a_opb_'
541
- elif token.ttype == T.Punctuation and token.value == ',':
542
- state = 'select_x_join_y_on_'
543
- elif state == 'select_x_join_y_on_a_opb_':
544
- if token.ttype == T.Keyword and token.value.lower() in ['and', 'or']:
545
- state = 'select_join'
546
- elif token.ttype == T.Keyword and token.value.lower() == 'where':
547
- state = 'select_where'
548
- elif token.ttype == T.Keyword and token.value.lower() == 'group':
549
- state = 'select_from_x_group'
550
- elif token.ttype == T.Keyword and token.value.lower() == 'group by':
551
- state = 'select_from_x_group_by'
552
- elif token.ttype == T.Keyword and token.value.lower() == 'limit':
553
- state = 'select_where_sc_limit'
554
-
555
- elif state == 'insert':
556
- if token.ttype == T.Text.Whitespace:
557
- state = 'insert_'
558
- elif state == 'insert_':
559
- if token.ttype == T.Keyword and token.value.lower() == 'into':
560
- state = 'insert_into'
561
- elif state == 'insert_into':
562
- if token.ttype == T.Text.Whitespace:
563
- state = 'insert_into_'
564
- elif state == 'insert_into_':
565
- if token.ttype == T.Name:
566
- state = 'insert_into_x'
567
- elif state == 'insert_into_x':
568
- if token.ttype == T.Text.Whitespace:
569
- state = 'insert_into_x_'
570
- elif token.ttype == T.Punctuation and token.value == '(':
571
- state = 'insert_into_x_lp_'
572
- elif state == 'insert_into_x_':
573
- if token.ttype == T.Punctuation and token.value == '(':
574
- state = 'insert_into_x_lp_'
575
- elif token.ttype == T.Keyword and token.value.lower() == 'values':
576
- state = 'insert_values'
577
- elif state == 'insert_into_x_lp_':
578
- if token.ttype == T.Name:
579
- state = 'insert_into_x_lp_a'
580
- elif state == 'insert_into_x_lp_a':
581
- if token.ttype == T.Punctuation and token.value == ',':
582
- state = 'insert_into_x_lp_a,'
583
- elif token.ttype == T.Punctuation and token.value == ')':
584
- state = 'insert_into_x_lp_a_rp'
585
- elif state == 'insert_into_x_lp_a,':
586
- if token.ttype == T.Name:
587
- state = 'insert_into_x_lp_a'
588
- elif state == 'insert_into_x_lp_a_rp':
589
- if token.ttype == T.Text.Whitespace:
590
- state = 'insert_into_x_lp_a_rp_'
591
- elif state == 'insert_into_x_lp_a_rp_':
592
- if token.ttype == T.Keyword and token.value.lower() == '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':
597
- if token.ttype == T.Punctuation and token.value == '(':
598
- state = 'insert_values_lp_'
599
- elif state == 'insert_values_lp_':
600
- if token.ttype in [T.Literal.String.Single, T.Name]:
601
- state = 'insert_values_lp_v'
602
- elif state == 'insert_values_lp_v':
603
- if token.ttype == T.Punctuation and token.value == ',':
604
- state = 'insert_values_lp_v,'
605
- elif state == 'insert_values_lp_v,':
606
- if token.ttype in [T.Literal.String.Single, T.Name]:
607
- state = 'insert_values_lp_v'
608
-
609
- elif state == 'update':
610
- if token.ttype == T.Text.Whitespace:
611
- state = 'update_'
612
- elif state == 'update_':
613
- if token.ttype == T.Name:
614
- state = 'update_x'
615
- elif state == 'update_x':
616
- if token.ttype == T.Text.Whitespace:
617
- state = 'update_x_'
618
- elif state == 'update_x_':
619
- if token.ttype == T.Keyword and token.value.lower() == 'set':
620
- state = 'update_x_set'
621
- elif state == 'update_x_set':
622
- if token.ttype == T.Text.Whitespace:
623
- state = 'update_x_set_'
624
- elif state == 'update_x_set_':
625
- if token.ttype == T.Name:
626
- state = 'update_x_set_a'
627
- elif state == 'update_x_set_a':
628
- if token.ttype == T.Operator.Comparison:
629
- state = 'update_x_set_a_op'
630
- elif state == 'update_x_set_a_op':
631
- if token.ttype in [T.Literal.String.Single, T.Name]:
632
- state = 'update_x_set_sc'
633
- elif state == 'update_x_set_sc':
634
- if token.ttype == T.Punctuation and token.value == ',':
635
- state = 'update_x_set_sc,'
636
- elif token.ttype == T.Text.Whitespace:
637
- state = 'update_x_set_sc_'
638
- elif state == 'update_x_set_sc,':
639
- if token.ttype == T.Name:
640
- state = 'update_x_set_a'
641
- elif state == 'update_x_set_sc_':
642
- if token.ttype == T.Punctuation and token.value == ',':
643
- state = 'update_x_set_sc,'
644
- elif token.ttype == T.Keyword and token.value.lower() == 'where':
645
- state = 'update_where'
646
- elif state == 'update_where':
647
- if token.ttype == T.Text.Whitespace:
648
- state = 'update_where_'
649
- elif state == 'update_where_':
650
- if token.ttype == T.Name:
651
- state = 'update_where_a'
652
- elif state == 'update_where_a':
653
- if token.ttype == T.Operator.Comparison:
654
- state = 'update_where_a_op'
655
- elif state == 'update_where_a_op':
656
- if token.ttype in [T.Literal.String.Single, T.Name]:
657
- state = 'update_where_sc'
658
- elif state == 'update_where_sc':
659
- if token.ttype == T.Text.Whitespace:
660
- state = 'update_where_sc_'
661
- elif state == 'update_where_sc_':
662
- if token.ttype == T.Keyword and token.value.lower() in ['and', 'or']:
663
- state = 'update_where'
664
-
665
- elif state == 'delete':
666
- if token.ttype == T.Text.Whitespace:
667
- state = 'delete_'
668
- elif state == 'delete_':
669
- if token.ttype == T.Keyword and token.value.lower() == 'from':
670
- state = 'delete_from'
671
- elif state == 'delete_from':
672
- if token.ttype == T.Text.Whitespace:
673
- state = 'delete_from_'
674
- elif state == 'delete_from_':
675
- if token.ttype == T.Name:
676
- state = 'delete_from_x'
677
- elif state == 'delete_from_x':
678
- if token.ttype == T.Text.Whitespace:
679
- state = 'delete_from_x_'
680
- elif state == 'delete_from_x_':
681
- if token.ttype == T.Keyword and token.value.lower() == 'where':
682
- state = 'delete_where'
683
- elif state == 'delete_where':
684
- if token.ttype == T.Text.Whitespace:
685
- state = 'delete_where_'
686
- elif state == 'delete_where_':
687
- if token.ttype == T.Name:
688
- state = 'delete_where_a'
689
- elif state == 'delete_where_a':
690
- if token.ttype == T.Operator.Comparison:
691
- state = 'delete_where_a_op'
692
- elif state == 'delete_where_a_op':
693
- if token.ttype in [T.Literal.String.Single, T.Name]:
694
- state = 'delete_where_sc'
695
- elif state == 'delete_where_sc':
696
- if token.ttype == T.Text.Whitespace:
697
- state = 'delete_where_sc_'
698
- elif state == 'delete_where_sc_':
699
- if token.ttype == T.Keyword and token.value.lower() in ['and', 'or']:
700
- state = 'delete_where'
511
+ it = ''
512
+ if (t := token.value.lower()) in keywords:
513
+ it = t
514
+ elif token.ttype == T.Text.Whitespace:
515
+ it = '_'
516
+ elif token.ttype in [T.Name, T.Literal.String.Single]:
517
+ it = 'name'
518
+ elif token.ttype == T.Wildcard:
519
+ it = '*'
520
+ elif token.ttype == T.Punctuation:
521
+ if token.value == ',':
522
+ it = ','
523
+ elif token.value == '(':
524
+ it = '('
525
+ elif token.value == ')':
526
+ it = ')'
527
+ elif token.ttype == T.Operator.Comparison:
528
+ it = 'comparison'
529
+
530
+ try:
531
+ state = self.machine[f'{state} > {it}']
532
+ except:
533
+ pass
701
534
 
702
535
  return state
703
536
 
@@ -52,7 +52,7 @@ class TermCompleter(WordCompleter):
52
52
  return word.startswith(word_before_cursor)
53
53
 
54
54
  for a in words:
55
- if word_before_cursor in ['(', ',', '=']:
55
+ if word_before_cursor in ['(', ',', '=', 'in', "',"]:
56
56
  display = self.display_dict.get(a, a)
57
57
  display_meta = self.meta_dict.get(a, "")
58
58
  yield Completion(
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.58" #: the working version
4
+ __version__ = "2.0.60" #: 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.58
3
+ Version: 2.0.60
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=nZO5CucSIGz68f4JreadGphRzMXPUzkTn-4XcoJJOug,8643
16
16
  adam/utils.py,sha256=2DoWsrcaioFFH0-RjT30qelVRPUJqCGTfz_ucfE7F8g,7406
17
- adam/version.py,sha256=sRDlhsVJoL9FZXAovHXEN5knQt5JzVhfRzS7ln7cVCw,139
17
+ adam/version.py,sha256=7RCo3Cs2toI4G2hj9yiTT2E6QyGRwyVOhEKHJscEMPM,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,8 +164,8 @@ adam/k8s_utils/services.py,sha256=EOJJGACVbbRvu5T3rMKqIJqgYic1_MSJ17EA0TJ6UOk,31
164
164
  adam/k8s_utils/statefulsets.py,sha256=5g7KxGRHgEewT8rnZneDTaJDylUf-dHH2edWJEoorr8,4667
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=eYkW0WYV0mEMUgGcKvxTRbI6vO-q3rJ7dUWjqaOGfHc,35888
168
- adam/sql/term_completer.py,sha256=VCCMPUzvh_9lwIOwqQmeijM0V2JPADkBbNV4HQIqDCw,2538
167
+ adam/sql/sql_completer.py,sha256=2TPR618K4qXuucMylYkLL8kK65znReLsG1lK_Kn1FVQ,27188
168
+ adam/sql/term_completer.py,sha256=17fuRyW2Uk-CoKySAh0S_UEzRQu9a-NxWII8jQnpAPU,2550
169
169
  adam/sso/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
170
170
  adam/sso/authenticator.py,sha256=BCm16L9zf5aLU47-sTCnudn2zLPwd8M2wwRminJfsqw,615
171
171
  adam/sso/authn_ad.py,sha256=fDW8UR3WWykny5Awa5dQjjBUSFzIDz4aMn-lwXoABl8,5857
@@ -176,8 +176,8 @@ adam/sso/idp.py,sha256=fvcwUw_URTgsO6ySaqTIw0zQT2qRO1IPSGhf6rPtybo,5804
176
176
  adam/sso/idp_login.py,sha256=QAtCUeDTVWliJy40RK_oac8Vgybr13xH8wzeBoxPaa8,1754
177
177
  adam/sso/idp_session.py,sha256=9BUHNRf70u4rVKrVY1HKPOEmOviXvkjam8WJxmXSKIM,1735
178
178
  adam/sso/sso_config.py,sha256=5N8WZgIJQBtHUy585XLRWKjpU87_v6QluyNK9E27D5s,2459
179
- kaqing-2.0.58.dist-info/METADATA,sha256=xsAw0gTa9oAjL1-qk8Wahz9ZNL-iSMis6RLHaUtwl9o,132
180
- kaqing-2.0.58.dist-info/WHEEL,sha256=tZoeGjtWxWRfdplE7E3d45VPlLNQnvbKiYnx7gwAy8A,92
181
- kaqing-2.0.58.dist-info/entry_points.txt,sha256=SkzhuQJUWsXOzHeZ5TgQ2c3_g53UGK23zzJU_JTZOZI,39
182
- kaqing-2.0.58.dist-info/top_level.txt,sha256=8_2PZkwBb-xDcnc8a2rAbQeJhXKXskc7zTP7pSPa1fw,5
183
- kaqing-2.0.58.dist-info/RECORD,,
179
+ kaqing-2.0.60.dist-info/METADATA,sha256=cnP96Te83vGdPiqpG7o2ODMyH-EoxHfWT-2jjb6BS2Q,132
180
+ kaqing-2.0.60.dist-info/WHEEL,sha256=tZoeGjtWxWRfdplE7E3d45VPlLNQnvbKiYnx7gwAy8A,92
181
+ kaqing-2.0.60.dist-info/entry_points.txt,sha256=SkzhuQJUWsXOzHeZ5TgQ2c3_g53UGK23zzJU_JTZOZI,39
182
+ kaqing-2.0.60.dist-info/top_level.txt,sha256=8_2PZkwBb-xDcnc8a2rAbQeJhXKXskc7zTP7pSPa1fw,5
183
+ kaqing-2.0.60.dist-info/RECORD,,