@@ -239,6 +239,26 @@ def _(op: ops.base_ops.UnaryOp, expr: TypedExpr) -> sge.Expression:
239
239
return sge .Floor (this = expr .expr )
240
240
241
241
242
+ @UNARY_OP_REGISTRATION .register (ops .geo_area_op )
243
+ def _ (op : ops .base_ops .UnaryOp , expr : TypedExpr ) -> sge .Expression :
244
+ return sge .func ("ST_AREA" , expr .expr )
245
+
246
+
247
+ @UNARY_OP_REGISTRATION .register (ops .geo_st_astext_op )
248
+ def _ (op : ops .base_ops .UnaryOp , expr : TypedExpr ) -> sge .Expression :
249
+ return sge .func ("ST_ASTEXT" , expr .expr )
250
+
251
+
252
+ @UNARY_OP_REGISTRATION .register (ops .geo_x_op )
253
+ def _ (op : ops .base_ops .UnaryOp , expr : TypedExpr ) -> sge .Expression :
254
+ return sge .func ("SAFE.ST_X" , expr .expr )
255
+
256
+
257
+ @UNARY_OP_REGISTRATION .register (ops .geo_y_op )
258
+ def _ (op : ops .base_ops .UnaryOp , expr : TypedExpr ) -> sge .Expression :
259
+ return sge .func ("SAFE.ST_Y" , expr .expr )
260
+
261
+
242
262
@UNARY_OP_REGISTRATION .register (ops .hash_op )
243
263
def _ (op : ops .base_ops .UnaryOp , expr : TypedExpr ) -> sge .Expression :
244
264
return sge .func ("FARM_FINGERPRINT" , expr .expr )
@@ -361,6 +381,16 @@ def _(op: ops.base_ops.UnaryOp, expr: TypedExpr) -> sge.Expression:
361
381
return sge .Lower (this = expr .expr )
362
382
363
383
384
+ @UNARY_OP_REGISTRATION .register (ops .minute_op )
385
+ def _ (op : ops .base_ops .UnaryOp , expr : TypedExpr ) -> sge .Expression :
386
+ return sge .Extract (this = sge .Identifier (this = "MINUTE" ), expression = expr .expr )
387
+
388
+
389
+ @UNARY_OP_REGISTRATION .register (ops .month_op )
390
+ def _ (op : ops .base_ops .UnaryOp , expr : TypedExpr ) -> sge .Expression :
391
+ return sge .Extract (this = sge .Identifier (this = "MONTH" ), expression = expr .expr )
392
+
393
+
364
394
@UNARY_OP_REGISTRATION .register (ops .StrLstripOp )
365
395
def _ (op : ops .StrLstripOp , expr : TypedExpr ) -> sge .Expression :
366
396
return sge .Trim (this = expr .expr , expression = sge .convert (op .to_strip ), side = "LEFT" )
@@ -371,16 +401,31 @@ def _(op: ops.base_ops.UnaryOp, expr: TypedExpr) -> sge.Expression:
371
401
return sge .Neg (this = expr .expr )
372
402
373
403
404
+ @UNARY_OP_REGISTRATION .register (ops .normalize_op )
405
+ def _ (op : ops .base_ops .UnaryOp , expr : TypedExpr ) -> sge .Expression :
406
+ return sge .TimestampTrunc (this = expr .expr , unit = sge .Identifier (this = "DAY" ))
407
+
408
+
374
409
@UNARY_OP_REGISTRATION .register (ops .pos_op )
375
410
def _ (op : ops .base_ops .UnaryOp , expr : TypedExpr ) -> sge .Expression :
376
411
return expr .expr
377
412
378
413
414
+ @UNARY_OP_REGISTRATION .register (ops .quarter_op )
415
+ def _ (op : ops .base_ops .UnaryOp , expr : TypedExpr ) -> sge .Expression :
416
+ return sge .Extract (this = sge .Identifier (this = "QUARTER" ), expression = expr .expr )
417
+
418
+
379
419
@UNARY_OP_REGISTRATION .register (ops .reverse_op )
380
420
def _ (op : ops .base_ops .UnaryOp , expr : TypedExpr ) -> sge .Expression :
381
421
return sge .func ("REVERSE" , expr .expr )
382
422
383
423
424
+ @UNARY_OP_REGISTRATION .register (ops .second_op )
425
+ def _ (op : ops .base_ops .UnaryOp , expr : TypedExpr ) -> sge .Expression :
426
+ return sge .Extract (this = sge .Identifier (this = "SECOND" ), expression = expr .expr )
427
+
428
+
384
429
@UNARY_OP_REGISTRATION .register (ops .StrRstripOp )
385
430
def _ (op : ops .StrRstripOp , expr : TypedExpr ) -> sge .Expression :
386
431
return sge .Trim (this = expr .expr , expression = sge .convert (op .to_strip ), side = "RIGHT" )
@@ -414,6 +459,11 @@ def _(op: ops.base_ops.UnaryOp, expr: TypedExpr) -> sge.Expression:
414
459
return sge .Extract (this = sge .Identifier (this = "ISOWEEK" ), expression = expr .expr )
415
460
416
461
462
+ @UNARY_OP_REGISTRATION .register (ops .iso_year_op )
463
+ def _ (op : ops .base_ops .UnaryOp , expr : TypedExpr ) -> sge .Expression :
464
+ return sge .Extract (this = sge .Identifier (this = "ISOYEAR" ), expression = expr .expr )
465
+
466
+
417
467
@UNARY_OP_REGISTRATION .register (ops .isnull_op )
418
468
def _ (op : ops .base_ops .UnaryOp , expr : TypedExpr ) -> sge .Expression :
419
469
return sge .Is (this = expr .expr , expression = sge .Null ())
@@ -442,6 +492,31 @@ def _(op: ops.base_ops.UnaryOp, expr: TypedExpr) -> sge.Expression:
442
492
)
443
493
444
494
495
+ @UNARY_OP_REGISTRATION .register (ops .StrGetOp )
496
+ def _ (op : ops .StrGetOp , expr : TypedExpr ) -> sge .Expression :
497
+ return sge .Substring (
498
+ this = expr .expr ,
499
+ start = sge .convert (op .i + 1 ),
500
+ length = sge .convert (1 ),
501
+ )
502
+
503
+
504
+ @UNARY_OP_REGISTRATION .register (ops .StrSliceOp )
505
+ def _ (op : ops .StrSliceOp , expr : TypedExpr ) -> sge .Expression :
506
+ start = op .start + 1 if op .start is not None else None
507
+ if op .end is None :
508
+ length = None
509
+ elif op .start is None :
510
+ length = op .end
511
+ else :
512
+ length = op .end - op .start
513
+ return sge .Substring (
514
+ this = expr .expr ,
515
+ start = sge .convert (start ) if start is not None else None ,
516
+ length = sge .convert (length ) if length is not None else None ,
517
+ )
518
+
519
+
445
520
@UNARY_OP_REGISTRATION .register (ops .tan_op )
446
521
def _ (op : ops .base_ops .UnaryOp , expr : TypedExpr ) -> sge .Expression :
447
522
return sge .func ("TAN" , expr .expr )
@@ -452,6 +527,16 @@ def _(op: ops.base_ops.UnaryOp, expr: TypedExpr) -> sge.Expression:
452
527
return sge .func ("TANH" , expr .expr )
453
528
454
529
530
+ @UNARY_OP_REGISTRATION .register (ops .time_op )
531
+ def _ (op : ops .base_ops .UnaryOp , expr : TypedExpr ) -> sge .Expression :
532
+ return sge .func ("TIME" , expr .expr )
533
+
534
+
535
+ @UNARY_OP_REGISTRATION .register (ops .timedelta_floor_op )
536
+ def _ (op : ops .base_ops .UnaryOp , expr : TypedExpr ) -> sge .Expression :
537
+ return sge .Floor (this = expr .expr )
538
+
539
+
455
540
# JSON Ops
456
541
@UNARY_OP_REGISTRATION .register (ops .JSONExtract )
457
542
def _ (op : ops .JSONExtract , expr : TypedExpr ) -> sge .Expression :
@@ -501,3 +586,8 @@ def _(op: ops.ToJSONString, expr: TypedExpr) -> sge.Expression:
501
586
@UNARY_OP_REGISTRATION .register (ops .upper_op )
502
587
def _ (op : ops .base_ops .UnaryOp , expr : TypedExpr ) -> sge .Expression :
503
588
return sge .Upper (this = expr .expr )
589
+
590
+
591
+ @UNARY_OP_REGISTRATION .register (ops .year_op )
592
+ def _ (op : ops .base_ops .UnaryOp , expr : TypedExpr ) -> sge .Expression :
593
+ return sge .Extract (this = sge .Identifier (this = "YEAR" ), expression = expr .expr )
0 commit comments