Skip to content

Commit

Permalink
[CALCITE-5921] SqlOperatorFixture.checkFails and checkAggFails don't …
Browse files Browse the repository at this point in the history
…check runtime failure (follow-up)
  • Loading branch information
rubenada committed Oct 25, 2023
1 parent 0bec957 commit 6d1d87a
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,11 @@ String rewrite(String sql) throws SqlParseException {
}
}

@Override @Disabled("Runtime error message differs after parsing and unparsing")
void testBitAndFuncRuntimeFails() {
super.testContainsSubstrFunc();
}

// Every test that is Disabled below corresponds to a bug.
// These tests should just be deleted when the corresponding bugs are fixed.

Expand Down
43 changes: 33 additions & 10 deletions testkit/src/main/java/org/apache/calcite/test/SqlOperatorTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -919,8 +919,8 @@ void testCastIntervalToInterval(CastType castType, SqlOperatorFixture f) {
void testCastWithRoundingToScalar(CastType castType, SqlOperatorFixture f) {
f.setFor(SqlStdOperatorTable.CAST, VmName.EXPAND);

f.checkFails("cast(1.25 as int)", "INTEGER", true);
f.checkFails("cast(1.25E0 as int)", "INTEGER", true);
f.checkScalar("cast(1.25 as int)", 1, "INTEGER NOT NULL");
f.checkScalar("cast(1.25E0 as int)", 1, "INTEGER NOT NULL");
if (!f.brokenTestsEnabled()) {
return;
}
Expand Down Expand Up @@ -960,8 +960,8 @@ void testCastWithRoundingToScalar(CastType castType, SqlOperatorFixture f) {
void testCastDecimalToDoubleToInteger(CastType castType, SqlOperatorFixture f) {
f.setFor(SqlStdOperatorTable.CAST, VmName.EXPAND);

f.checkFails("cast( cast(1.25 as double) as integer)", OUT_OF_RANGE_MESSAGE, true);
f.checkFails("cast( cast(-1.25 as double) as integer)", OUT_OF_RANGE_MESSAGE, true);
f.checkScalar("cast( cast(1.25 as double) as integer)", 1, "INTEGER NOT NULL");
f.checkScalar("cast( cast(-1.25 as double) as integer)", -1, "INTEGER NOT NULL");
if (!f.brokenTestsEnabled()) {
return;
}
Expand Down Expand Up @@ -1222,7 +1222,11 @@ void testCastStringToDateTime(CastType castType, SqlOperatorFixture f) {
"12:42:25.34", "TIME(2) NOT NULL");
}

f.checkFails("cast('nottime' as TIME)", BAD_DATETIME_MESSAGE, true);
if (castType == CastType.CAST) {
f.checkFails("cast('nottime' as TIME)", BAD_DATETIME_MESSAGE, true);
} else {
f.checkNull("cast('nottime' as TIME)");
}
f.checkScalar("cast('1241241' as TIME)", "72:40:12", "TIME(0) NOT NULL");
f.checkScalar("cast('12:54:78' as TIME)", "12:55:18", "TIME(0) NOT NULL");
f.checkScalar("cast('12:34:5' as TIME)", "12:34:05", "TIME(0) NOT NULL");
Expand Down Expand Up @@ -1287,7 +1291,11 @@ void testCastStringToDateTime(CastType castType, SqlOperatorFixture f) {
f.checkScalar("cast('1945-1-24 12:23:34.454' as TIMESTAMP)",
"1945-01-24 12:23:34", "TIMESTAMP(0) NOT NULL");
}
f.checkFails("cast('nottime' as TIMESTAMP)", BAD_DATETIME_MESSAGE, true);
if (castType == CastType.CAST) {
f.checkFails("cast('nottime' as TIMESTAMP)", BAD_DATETIME_MESSAGE, true);
} else {
f.checkNull("cast('nottime' as TIMESTAMP)");
}

// date <-> string
f.checkCastToString("DATE '1945-02-24'", null, "1945-02-24", castType);
Expand All @@ -1297,7 +1305,11 @@ void testCastStringToDateTime(CastType castType, SqlOperatorFixture f) {
f.checkScalar("cast(' 1945-2-4 ' as DATE)", "1945-02-04", "DATE NOT NULL");
f.checkScalar("cast(' 1945-02-24 ' as DATE)",
"1945-02-24", "DATE NOT NULL");
f.checkFails("cast('notdate' as DATE)", BAD_DATETIME_MESSAGE, true);
if (castType == CastType.CAST) {
f.checkFails("cast('notdate' as DATE)", BAD_DATETIME_MESSAGE, true);
} else {
f.checkNull("cast('notdate' as DATE)");
}

f.checkScalar("cast('52534253' as DATE)", "7368-10-13", "DATE NOT NULL");
f.checkScalar("cast('1945-30-24' as DATE)", "1947-06-26", "DATE NOT NULL");
Expand Down Expand Up @@ -1407,12 +1419,20 @@ void testCastToBoolean(CastType castType, SqlOperatorFixture f) {
f.checkBoolean("cast(' trUe' as boolean)", true);
f.checkBoolean("cast(' tr' || 'Ue' as boolean)", true);
f.checkBoolean("cast(' fALse' as boolean)", false);
f.checkFails("cast('unknown' as boolean)", INVALID_CHAR_MESSAGE, true);
if (castType == CastType.CAST) {
f.checkFails("cast('unknown' as boolean)", INVALID_CHAR_MESSAGE, true);
} else {
f.checkNull("cast('unknown' as boolean)");
}

f.checkBoolean("cast(cast('true' as varchar(10)) as boolean)", true);
f.checkBoolean("cast(cast('false' as varchar(10)) as boolean)", false);
f.checkFails("cast(cast('blah' as varchar(10)) as boolean)",
INVALID_CHAR_MESSAGE, true);
if (castType == CastType.CAST) {
f.checkFails("cast(cast('blah' as varchar(10)) as boolean)",
INVALID_CHAR_MESSAGE, true);
} else {
f.checkNull("cast(cast('blah' as varchar(10)) as boolean)");
}
}

@Test void testCastRowType() {
Expand Down Expand Up @@ -12913,7 +12933,10 @@ private static void checkLogicalOrFunc(SqlOperatorFixture f) {
"cast(null AS BINARY)"};
f.checkAgg("bit_and(x)", binaryValues, isSingle("02"));
f.checkAgg("bit_and(x)", new String[]{"CAST(x'02' AS BINARY)"}, isSingle("02"));
}

@Test void testBitAndFuncRuntimeFails() {
final SqlOperatorFixture f = fixture();
f.checkAggFails("bit_and(x)",
new String[]{"CAST(x'0201' AS VARBINARY)", "CAST(x'02' AS VARBINARY)"},
"Error while executing SQL"
Expand Down

0 comments on commit 6d1d87a

Please sign in to comment.