Skip to content

Commit

Permalink
[CALCITE-6184] Add checkNullTest on SqlOperatorTest
Browse files Browse the repository at this point in the history
  • Loading branch information
caicancai authored and macroguo-ghy committed Jan 6, 2024
1 parent 3c19347 commit 294e42f
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions testkit/src/main/java/org/apache/calcite/test/SqlOperatorTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -440,6 +440,10 @@ protected SqlOperatorFixture fixture() {
false);
f.checkBoolean("x'0A00015A' not between x'0A0001A0' and x'0A0001B0'",
true);
f.checkNull("cast(null as integer) not between -1 and 2");
f.checkNull("1 not between -1 and cast(null as integer)");
f.checkNull("1 not between cast(null as integer) and cast(null as integer)");
f.checkNull("1 not between cast(null as integer) and 1");
}

/** Generates parameters to test both regular and safe cast. */
Expand Down Expand Up @@ -1882,6 +1886,7 @@ void testCastToBoolean(CastType castType, SqlOperatorFixture f) {
"Cannot apply 'CHAR' to arguments of type 'CHAR\\(<DECIMAL\\(3, 1\\)>\\)'\\. "
+ "Supported form\\(s\\): 'CHAR\\(<INTEGER>\\)'",
false);
f.checkNull("char(null)");
}

@Test void testChr() {
Expand Down Expand Up @@ -12247,6 +12252,7 @@ void testTimestampDiff(boolean coercionEnabled) {
f.checkScalar("time_trunc(time '12:34:56', hour)",
"12:00:00", "TIME(0) NOT NULL");
f.checkNull("time_trunc(cast(null as time), second)");
f.checkNull("time_trunc(cast(null as time), minute)");
}

@Test void testTimestampTrunc() {
Expand Down Expand Up @@ -12309,6 +12315,7 @@ void testTimestampDiff(boolean coercionEnabled) {
+ "'TIMESTAMP_TRUNC\\(<TIME\\(0\\)>, <INTERVAL HOUR>\\)'\\. "
+ "Supported form\\(s\\): 'TIMESTAMP_TRUNC\\(<TIMESTAMP>, <DATETIME_INTERVAL>\\)'",
false);
f.checkNull("timestamp_trunc(CAST(NULL AS TIMESTAMP), second)");
}

@Test void testDatetimeTrunc() {
Expand Down Expand Up @@ -12365,6 +12372,7 @@ void testTimestampDiff(boolean coercionEnabled) {
+ "'DATETIME_TRUNC\\(<TIME\\(0\\)>, <INTERVAL HOUR>\\)'\\. "
+ "Supported form\\(s\\): 'DATETIME_TRUNC\\(<TIMESTAMP>, <DATETIME_INTERVAL>\\)'",
false);
f.checkNull("datetime_trunc(CAST(NULL AS TIMESTAMP), second)");
}

@Test void testDateTrunc() {
Expand Down Expand Up @@ -12419,6 +12427,7 @@ void testTimestampDiff(boolean coercionEnabled) {
// The comment above for century applies to millennium too.
f.checkScalar("date_trunc(date '2015-02-19', millennium)",
"2001-01-01", "DATE NOT NULL");
f.checkNull("date_trunc(CAST(NULL AS DATE) , day)");
}

@Test void testFormatTime() {
Expand Down Expand Up @@ -12560,6 +12569,11 @@ void testTimestampDiff(boolean coercionEnabled) {
f.checkScalar("PARSE_DATETIME('%A, %B %e, %Y', 'Wednesday, December 19, 2018')",
"2018-12-19 00:00:00",
"TIMESTAMP(0) NOT NULL");
f.checkNull("PARSE_DATETIME('%a %b %e %I:%M:%S %Y', CAST(NULL AS TIMESTAMP))");
f.checkNull("PARSE_DATETIME('%c', CAST(NULL AS TIMESTAMP))");
f.checkNull("PARSE_DATETIME('%Y-%m-%d %H:%M:%S', CAST(NULL AS TIMESTAMP))");
f.checkNull("PARSE_DATETIME('%m/%d/%Y %I:%M:%S %p', CAST(NULL AS TIMESTAMP))");
f.checkNull("PARSE_DATETIME(NULL, CAST(NULL AS TIMESTAMP))");
}

@Test void testParseTime() {
Expand Down Expand Up @@ -12598,6 +12612,8 @@ void testTimestampDiff(boolean coercionEnabled) {
f.checkScalar("PARSE_TIMESTAMP('%c', 'Thu Dec 25 07:30:00 2008')",
"2008-12-25 07:30:00",
"TIMESTAMP_WITH_LOCAL_TIME_ZONE(0) NOT NULL");
f.checkNull("PARSE_TIME('%a %b %e %I:%M:%S %Y', CAST(NULL AS TIMESTAMP))");
f.checkNull("PARSE_TIMESTAMP(NULL, CAST(NULL AS TIMESTAMP))");
}

@Test void testDenseRankFunc() {
Expand Down

0 comments on commit 294e42f

Please sign in to comment.