@@ -43,11 +43,12 @@ public class TestExpressionUtil {
43
43
Types .NestedField .required (2 , "val" , Types .IntegerType .get ()),
44
44
Types .NestedField .required (3 , "val2" , Types .IntegerType .get ()),
45
45
Types .NestedField .required (4 , "ts" , Types .TimestampType .microsWithoutZone ()),
46
- Types .NestedField .required (5 , "date" , Types .DateType .get ()),
47
- Types .NestedField .required (6 , "time" , Types .DateType .get ()),
48
- Types .NestedField .optional (7 , "data" , Types .StringType .get ()),
49
- Types .NestedField .optional (8 , "measurement" , Types .DoubleType .get ()),
50
- Types .NestedField .optional (9 , "test" , Types .IntegerType .get ()));
46
+ Types .NestedField .required (5 , "tsns" , Types .TimestampType .nanosWithoutZone ()),
47
+ Types .NestedField .required (6 , "date" , Types .DateType .get ()),
48
+ Types .NestedField .required (7 , "time" , Types .DateType .get ()),
49
+ Types .NestedField .optional (8 , "data" , Types .StringType .get ()),
50
+ Types .NestedField .optional (9 , "measurement" , Types .DoubleType .get ()),
51
+ Types .NestedField .optional (10 , "test" , Types .IntegerType .get ()));
51
52
52
53
private static final Types .StructType STRUCT = SCHEMA .asStruct ();
53
54
@@ -461,7 +462,9 @@ public void testSanitizeTimestamp() {
461
462
"2022-04-29T23:49:51" ,
462
463
"2022-04-29T23:49:51.123456" ,
463
464
"2022-04-29T23:49:51-07:00" ,
464
- "2022-04-29T23:49:51.123456+01:00" )) {
465
+ "2022-04-29T23:49:51.123456+01:00" ,
466
+ "2022-04-29T23:49:51.123456789" ,
467
+ "2022-04-29T23:49:51.123456789+01:00" )) {
465
468
assertEquals (
466
469
Expressions .equal ("test" , "(timestamp)" ),
467
470
ExpressionUtil .sanitize (Expressions .equal ("test" , timestamp )));
@@ -497,6 +500,13 @@ public void testSanitizeTimestampAboutNow() {
497
500
Expression .Operation .EQ ,
498
501
"test" ,
499
502
Literal .of (nowLocal ).to (Types .TimestampType .microsWithoutZone ()))));
503
+ assertEquals (
504
+ Expressions .equal ("test" , "(timestamp-about-now)" ),
505
+ ExpressionUtil .sanitize (
506
+ Expressions .predicate (
507
+ Expression .Operation .EQ ,
508
+ "test" ,
509
+ Literal .of (nowLocal ).to (Types .TimestampType .nanosWithoutZone ()))));
500
510
501
511
assertThat (ExpressionUtil .toSanitizedString (Expressions .equal ("test" , nowLocal )))
502
512
.as ("Sanitized string should be identical except for descriptive literal" )
@@ -523,6 +533,13 @@ public void testSanitizeTimestampPast() {
523
533
Expression .Operation .EQ ,
524
534
"test" ,
525
535
Literal .of (ninetyMinutesAgoLocal ).to (Types .TimestampType .microsWithoutZone ()))));
536
+ assertEquals (
537
+ Expressions .equal ("test" , "(timestamp-1-hours-ago)" ),
538
+ ExpressionUtil .sanitize (
539
+ Expressions .predicate (
540
+ Expression .Operation .EQ ,
541
+ "test" ,
542
+ Literal .of (ninetyMinutesAgoLocal ).to (Types .TimestampType .nanosWithoutZone ()))));
526
543
527
544
assertThat (ExpressionUtil .toSanitizedString (Expressions .equal ("test" , ninetyMinutesAgoLocal )))
528
545
.as ("Sanitized string should be identical except for descriptive literal" )
@@ -549,6 +566,13 @@ public void testSanitizeTimestampLastWeek() {
549
566
Expression .Operation .EQ ,
550
567
"test" ,
551
568
Literal .of (lastWeekLocal ).to (Types .TimestampType .microsWithoutZone ()))));
569
+ assertEquals (
570
+ Expressions .equal ("test" , "(timestamp-7-days-ago)" ),
571
+ ExpressionUtil .sanitize (
572
+ Expressions .predicate (
573
+ Expression .Operation .EQ ,
574
+ "test" ,
575
+ Literal .of (lastWeekLocal ).to (Types .TimestampType .nanosWithoutZone ()))));
552
576
553
577
assertThat (ExpressionUtil .toSanitizedString (Expressions .equal ("test" , lastWeekLocal )))
554
578
.as ("Sanitized string should be identical except for descriptive literal" )
@@ -576,6 +600,13 @@ public void testSanitizeTimestampFuture() {
576
600
"test" ,
577
601
Literal .of (ninetyMinutesFromNowLocal )
578
602
.to (Types .TimestampType .microsWithoutZone ()))));
603
+ assertEquals (
604
+ Expressions .equal ("test" , "(timestamp-1-hours-from-now)" ),
605
+ ExpressionUtil .sanitize (
606
+ Expressions .predicate (
607
+ Expression .Operation .EQ ,
608
+ "test" ,
609
+ Literal .of (ninetyMinutesFromNowLocal ).to (Types .TimestampType .nanosWithoutZone ()))));
579
610
580
611
assertThat (
581
612
ExpressionUtil .toSanitizedString (Expressions .equal ("test" , ninetyMinutesFromNowLocal )))
@@ -599,6 +630,13 @@ public void testSanitizeTimestamptzAboutNow() {
599
630
Expression .Operation .EQ ,
600
631
"test" ,
601
632
Literal .of (nowUtc ).to (Types .TimestampType .microsWithZone ()))));
633
+ assertEquals (
634
+ Expressions .equal ("test" , "(timestamp-about-now)" ),
635
+ ExpressionUtil .sanitize (
636
+ Expressions .predicate (
637
+ Expression .Operation .EQ ,
638
+ "test" ,
639
+ Literal .of (nowUtc ).to (Types .TimestampType .nanosWithZone ()))));
602
640
603
641
assertThat (ExpressionUtil .toSanitizedString (Expressions .equal ("test" , nowUtc )))
604
642
.as ("Sanitized string should be identical except for descriptive literal" )
@@ -620,6 +658,13 @@ public void testSanitizeTimestamptzPast() {
620
658
Expression .Operation .EQ ,
621
659
"test" ,
622
660
Literal .of (ninetyMinutesAgoUtc ).to (Types .TimestampType .microsWithZone ()))));
661
+ assertEquals (
662
+ Expressions .equal ("test" , "(timestamp-1-hours-ago)" ),
663
+ ExpressionUtil .sanitize (
664
+ Expressions .predicate (
665
+ Expression .Operation .EQ ,
666
+ "test" ,
667
+ Literal .of (ninetyMinutesAgoUtc ).to (Types .TimestampType .nanosWithZone ()))));
623
668
624
669
assertThat (ExpressionUtil .toSanitizedString (Expressions .equal ("test" , ninetyMinutesAgoUtc )))
625
670
.as ("Sanitized string should be identical except for descriptive literal" )
@@ -641,6 +686,13 @@ public void testSanitizeTimestamptzLastWeek() {
641
686
Expression .Operation .EQ ,
642
687
"test" ,
643
688
Literal .of (lastWeekUtc ).to (Types .TimestampType .microsWithZone ()))));
689
+ assertEquals (
690
+ Expressions .equal ("test" , "(timestamp-7-days-ago)" ),
691
+ ExpressionUtil .sanitize (
692
+ Expressions .predicate (
693
+ Expression .Operation .EQ ,
694
+ "test" ,
695
+ Literal .of (lastWeekUtc ).to (Types .TimestampType .nanosWithZone ()))));
644
696
645
697
assertThat (ExpressionUtil .toSanitizedString (Expressions .equal ("test" , lastWeekUtc )))
646
698
.as ("Sanitized string should be identical except for descriptive literal" )
@@ -662,6 +714,13 @@ public void testSanitizeTimestamptzFuture() {
662
714
Expression .Operation .EQ ,
663
715
"test" ,
664
716
Literal .of (ninetyMinutesFromNowUtc ).to (Types .TimestampType .microsWithZone ()))));
717
+ assertEquals (
718
+ Expressions .equal ("test" , "(timestamp-1-hours-from-now)" ),
719
+ ExpressionUtil .sanitize (
720
+ Expressions .predicate (
721
+ Expression .Operation .EQ ,
722
+ "test" ,
723
+ Literal .of (ninetyMinutesFromNowUtc ).to (Types .TimestampType .nanosWithZone ()))));
665
724
666
725
assertThat (ExpressionUtil .toSanitizedString (Expressions .equal ("test" , ninetyMinutesFromNowUtc )))
667
726
.as ("Sanitized string should be identical except for descriptive literal" )
0 commit comments