[Bugfix](datetime) fix DateLiteral range check is no longer valid (#11917)

* [Bugfix](datetime) fix DateLiteral range check is no longer valid
This commit is contained in:
Zhengguo Yang
2022-08-19 21:27:32 +08:00
committed by GitHub
parent be7a38e170
commit 6ca90afbfa
2 changed files with 10 additions and 0 deletions

View File

@ -432,6 +432,9 @@ public class DateLiteral extends LiteralExpr {
second = getOrDefault(dateTime, ChronoField.SECOND_OF_MINUTE, 0);
microsecond = getOrDefault(dateTime, ChronoField.MICRO_OF_SECOND, 0);
this.type = type;
if (checkRange() || checkDate()) {
throw new AnalysisException("Datetime value is out of range");
}
} catch (Exception ex) {
throw new AnalysisException("date literal [" + s + "] is invalid: " + ex.getMessage());
}

View File

@ -166,6 +166,13 @@ public class DateLiteralTest {
hasException = true;
}
Assert.assertFalse(hasException);
try {
DateLiteral literal = new DateLiteral("10000-10-07", Type.DATE);
Assert.assertEquals(10000, literal.getYear());
Assert.assertTrue(false);
} catch (AnalysisException e) {
// pass
}
}
@Test