Repository navigation
Expand file tree
/
Copy pathstring.py
More file actions
598 lines (373 loc) · 12.3 KB
/
Copy pathstring.py
File metadata and controls
598 lines (373 loc) · 12.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
"""sqlglot expressions - string, encoding, hashing, and regex functions."""
from __future__ import annotations
from sqlglot.expressions.core import Expression, Func, Binary
# String basics
class Ascii(Expression, Func):
pass
class BitLength(Expression, Func):
pass
class ByteLength(Expression, Func):
pass
class Chr(Expression, Func):
arg_types = {"expressions": True, "charset": False}
is_var_len_args = True
_sql_names = ["CHR", "CHAR"]
class Concat(Expression, Func):
arg_types = {"expressions": True, "safe": False, "coalesce": False}
is_var_len_args = True
class ConcatWs(Concat):
_sql_names = ["CONCAT_WS"]
class Contains(Expression, Func):
arg_types = {"this": True, "expression": True, "json_scope": False}
class Elt(Expression, Func):
arg_types = {"this": True, "expressions": True}
is_var_len_args = True
class EndsWith(Expression, Func):
_sql_names = ["ENDS_WITH", "ENDSWITH"]
arg_types = {"this": True, "expression": True}
class Format(Expression, Func):
arg_types = {"this": True, "expressions": False}
is_var_len_args = True
class Initcap(Expression, Func):
arg_types = {"this": True, "expression": False}
class IsAscii(Expression, Func):
pass
class Left(Expression, Func):
arg_types = {"this": True, "expression": True, "negative_length_returns_empty": False}
class Length(Expression, Func):
arg_types = {"this": True, "binary": False, "encoding": False}
_sql_names = ["LENGTH", "LEN", "CHAR_LENGTH", "CHARACTER_LENGTH"]
class Levenshtein(Expression, Func):
arg_types = {
"this": True,
"expression": False,
"ins_cost": False,
"del_cost": False,
"sub_cost": False,
"max_dist": False,
}
class Lower(Expression, Func):
_sql_names = ["LOWER", "LCASE"]
class MatchAgainst(Expression, Func):
arg_types = {"this": True, "expressions": True, "modifier": False}
class Normalize(Expression, Func):
arg_types = {"this": True, "form": False, "is_casefold": False}
class NumberToStr(Expression, Func):
arg_types = {"this": True, "format": True, "culture": False}
class Overlay(Expression, Func):
arg_types = {"this": True, "expression": True, "from_": True, "for_": False}
class Pad(Expression, Func):
arg_types = {"this": True, "expression": True, "fill_pattern": False, "is_left": True}
class Repeat(Expression, Func):
arg_types = {"this": True, "times": True}
class Replace(Expression, Func):
arg_types = {"this": True, "expression": True, "replacement": False}
class Reverse(Expression, Func):
pass
class Right(Expression, Func):
arg_types = {"this": True, "expression": True, "negative_length_returns_empty": False}
class RtrimmedLength(Expression, Func):
pass
class Search(Expression, Func):
arg_types = {
"this": True, # data_to_search / search_data
"expression": True, # search_query / search_string
"json_scope": False, # BigQuery: JSON_VALUES | JSON_KEYS | JSON_KEYS_AND_VALUES
"analyzer": False, # Both: analyzer / ANALYZER
"analyzer_options": False, # BigQuery: analyzer_options_values
"search_mode": False, # Snowflake: OR | AND
}
class SearchIp(Expression, Func):
arg_types = {"this": True, "expression": True}
class Soundex(Expression, Func):
pass
class SoundexP123(Expression, Func):
pass
class Space(Expression, Func):
"""
SPACE(n) → string consisting of n blank characters
"""
pass
class Split(Expression, Func):
arg_types = {
"this": True,
"expression": True,
"limit": False,
"null_returns_null": False,
"empty_delimiter_returns_whole": False,
}
class SplitPart(Expression, Func):
arg_types = {
"this": True,
"delimiter": False,
"part_index": False,
"part_index_zero_as_one": False, # usually part_index is 1-based, however Snowflake allows 0 and treats it as 1
"empty_delimiter_returns_whole": False, # whether the whole input string should be returned if the delimiter string is empty (i.e. Snowflake)
}
class Strtok(Expression, Func):
arg_types = {
"this": True,
"delimiter": False,
"part_index": False,
}
class StartsWith(Expression, Func):
_sql_names = ["STARTS_WITH", "STARTSWITH"]
arg_types = {"this": True, "expression": True}
class StrPosition(Expression, Func):
arg_types = {
"this": True,
"substr": True,
"position": False,
"occurrence": False,
"clamp_position": False,
}
class StrToMap(Expression, Func):
arg_types = {
"this": True,
"pair_delim": False,
"key_value_delim": False,
"duplicate_resolution_callback": False,
}
class String(Expression, Func):
arg_types = {"this": True, "zone": False}
class Stuff(Expression, Func):
_sql_names = ["STUFF", "INSERT"]
arg_types = {"this": True, "start": True, "length": True, "expression": True}
class Substring(Expression, Func):
_sql_names = ["SUBSTRING", "SUBSTR"]
arg_types = {"this": True, "start": False, "length": False, "zero_start": False}
class SubstringIndex(Expression, Func):
"""
SUBSTRING_INDEX(str, delim, count)
*count* > 0 → left slice before the *count*-th delimiter
*count* < 0 → right slice after the |count|-th delimiter
"""
arg_types = {"this": True, "delimiter": True, "count": True}
class Translate(Expression, Func):
arg_types = {"this": True, "from_": True, "to": True}
class Trim(Expression, Func):
arg_types = {
"this": True,
"expression": False,
"position": False,
"collation": False,
}
class Unicode(Expression, Func):
arg_types = {"this": True, "empty_is_zero": False}
class Upper(Expression, Func):
_sql_names = ["UPPER", "UCASE"]
# Encoding / base conversion
class Base64DecodeBinary(Expression, Func):
arg_types = {"this": True, "alphabet": False}
class Base64DecodeString(Expression, Func):
arg_types = {"this": True, "alphabet": False}
class Base64Encode(Expression, Func):
arg_types = {"this": True, "max_line_length": False, "alphabet": False}
class CodePointsToBytes(Expression, Func):
pass
class CodePointsToString(Expression, Func):
pass
class ConvertToCharset(Expression, Func):
arg_types = {"this": True, "dest": True, "source": False}
class Decode(Expression, Func):
arg_types = {"this": True, "charset": True, "replace": False}
class Encode(Expression, Func):
arg_types = {"this": True, "charset": True}
class FromBase(Expression, Func):
arg_types = {"this": True, "expression": True}
class FromBase32(Expression, Func):
pass
class FromBase64(Expression, Func):
pass
class Hex(Expression, Func):
arg_types = {"this": True, "case": False}
class HexDecodeString(Expression, Func):
pass
class LowerHex(Hex):
pass
class SafeConvertBytesToString(Expression, Func):
pass
class ToBase32(Expression, Func):
pass
class ToBase64(Expression, Func):
pass
class ToBinary(Expression, Func):
arg_types = {"this": True, "format": False, "safe": False}
class ToChar(Expression, Func):
arg_types = {
"this": True,
"format": False,
"nlsparam": False,
"is_numeric": False,
}
class ToCodePoints(Expression, Func):
pass
class ToDecfloat(Expression, Func):
arg_types = {
"this": True,
"format": False,
}
class ToDouble(Expression, Func):
arg_types = {
"this": True,
"format": False,
"safe": False,
}
class ToFile(Expression, Func):
arg_types = {
"this": True,
"path": False,
"safe": False,
}
class ToNumber(Expression, Func):
arg_types = {
"this": True,
"format": False,
"nlsparam": False,
"precision": False,
"scale": False,
"safe": False,
"safe_name": False,
"default": False,
}
class TryBase64DecodeBinary(Expression, Func):
arg_types = {"this": True, "alphabet": False}
class TryBase64DecodeString(Expression, Func):
arg_types = {"this": True, "alphabet": False}
class TryHexDecodeBinary(Expression, Func):
pass
class TryHexDecodeString(Expression, Func):
pass
class TryToDecfloat(Expression, Func):
arg_types = {
"this": True,
"format": False,
}
class Unhex(Expression, Func):
arg_types = {"this": True, "expression": False}
# Regex
class RegexpCount(Expression, Func):
arg_types = {
"this": True,
"expression": True,
"position": False,
"parameters": False,
}
class RegexpExtract(Expression, Func):
arg_types = {
"this": True,
"expression": True,
"position": False,
"occurrence": False,
"parameters": False,
"group": False,
"null_if_pos_overflow": False, # for transpilation target behavior
}
class RegexpExtractAll(Expression, Func):
arg_types = {
"this": True,
"expression": True,
"group": False,
"parameters": False,
"position": False,
"occurrence": False,
}
class RegexpFullMatch(Expression, Binary, Func):
arg_types = {"this": True, "expression": True, "options": False}
class RegexpILike(Expression, Binary, Func):
arg_types = {"this": True, "expression": True, "flag": False}
class RegexpInstr(Expression, Func):
arg_types = {
"this": True,
"expression": True,
"position": False,
"occurrence": False,
"option": False,
"parameters": False,
"group": False,
}
class RegexpReplace(Expression, Func):
arg_types = {
"this": True,
"expression": True,
"replacement": False,
"position": False,
"occurrence": False,
"modifiers": False,
"single_replace": False,
}
class RegexpSplit(Expression, Func):
arg_types = {"this": True, "expression": True, "limit": False}
class RegexpSubstr(Expression, Func):
arg_types = {
"this": True,
"expression": True,
"position": False,
"occurrence": False,
"parameters": False,
"group": False,
}
# Hashing / cryptographic
class Compress(Expression, Func):
arg_types = {"this": True, "method": False}
class Decrypt(Expression, Func):
arg_types = {
"this": True,
"passphrase": True,
"aad": False,
"encryption_method": False,
"safe": False,
}
class DecryptRaw(Expression, Func):
arg_types = {
"this": True,
"key": True,
"iv": True,
"aad": False,
"encryption_method": False,
"aead": False,
"safe": False,
}
class DecompressBinary(Expression, Func):
arg_types = {"this": True, "method": True}
class DecompressString(Expression, Func):
arg_types = {"this": True, "method": True}
class Encrypt(Expression, Func):
arg_types = {"this": True, "passphrase": True, "aad": False, "encryption_method": False}
class EncryptRaw(Expression, Func):
arg_types = {"this": True, "key": True, "iv": True, "aad": False, "encryption_method": False}
class CityHash64(Expression, Func):
arg_types = {"expressions": False}
is_var_len_args = True
class FarmFingerprint(Expression, Func):
arg_types = {"expressions": True}
is_var_len_args = True
_sql_names = ["FARM_FINGERPRINT", "FARMFINGERPRINT64"]
class MD5(Expression, Func):
_sql_names = ["MD5"]
class MD5Digest(Expression, Func):
arg_types = {"this": True, "expressions": False}
is_var_len_args = True
_sql_names = ["MD5_DIGEST"]
class MD5NumberLower64(Expression, Func):
pass
class MD5NumberUpper64(Expression, Func):
pass
class SHA(Expression, Func):
_sql_names = ["SHA", "SHA1"]
class SHA1Digest(Expression, Func):
pass
class SHA2(Expression, Func):
_sql_names = ["SHA2"]
arg_types = {"this": True, "length": False}
class SHA2Digest(Expression, Func):
arg_types = {"this": True, "length": False}
class StandardHash(Expression, Func):
arg_types = {"this": True, "expression": False}
# Parse
class ParseBignumeric(Expression, Func):
pass
class ParseNumeric(Expression, Func):
pass
class ParseUrl(Expression, Func):
arg_types = {"this": True, "part_to_extract": False, "key": False, "permissive": False}