Skip to content

Commit

Permalink
Moved to throwing exception instead of returning null in Date and Tim…
Browse files Browse the repository at this point in the history
…e functions.

Signed-off-by: MitchellGale-BitQuill <[email protected]>
  • Loading branch information
MitchellGale committed Nov 3, 2022
1 parent bc1507c commit ae241b6
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 30 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -652,11 +652,7 @@ private ExprValue exprConvertTZ(ExprValue startingDateTime, ExprValue fromTz, Ex
*/
private ExprValue exprDate(ExprValue exprValue) {
if (exprValue instanceof ExprStringValue) {
try {
return new ExprDateValue(exprValue.stringValue());
} catch (SemanticCheckException e) {
return ExprNullValue.of();
}
return new ExprDateValue(exprValue.stringValue());
} else {
return new ExprDateValue(exprValue.dateValue());
}
Expand Down Expand Up @@ -952,11 +948,7 @@ private ExprValue exprTime(ExprValue exprValue) {
return new ExprTimeValue("00:00:00");
}
if (exprValue instanceof ExprStringValue) {
try {
return new ExprTimeValue(exprValue.stringValue());
} catch (SemanticCheckException e) {
return ExprNullValue.of();
}
return new ExprTimeValue(exprValue.stringValue());
} else {
return new ExprTimeValue(exprValue.timeValue());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -252,8 +252,7 @@ public void date() {
assertEquals(new ExprDateValue("2020-08-17 12:12"), eval(expr));
assertEquals("date(DATE '2020-08-17')", expr.toString());

expr = dsl.date(DSL.literal("2020-02-30"));
assertEquals(nullValue(), expr.valueOf(null));

}

@Test
Expand Down Expand Up @@ -833,9 +832,6 @@ public void time() {
expr = dsl.time(dsl.date(DSL.literal("2020-01-02")));
assertEquals(TIME, expr.type());
assertEquals(new ExprTimeValue("00:00:00"), expr.valueOf(null));

expr = dsl.time(DSL.literal("01:01:01:01"));
assertEquals(nullValue(), expr.valueOf(null));
}

@Test
Expand Down
15 changes: 0 additions & 15 deletions docs/user/ppl/functions/datetime.rst
Original file line number Diff line number Diff line change
Expand Up @@ -323,13 +323,6 @@ Example::
| 2020-08-26 |
+----------------------------+

os> source=people | eval `DATE('2020-02-30 13:49')` = DATE('2020-02-30 13:49') | fields `DATE('2020-02-30 13:49')`
fetched rows / total rows = 1/1
+----------------------------+
| DATE('2020-02-30 13:49') |
|----------------------------|
| null |
+----------------------------+


DATE_ADD
Expand Down Expand Up @@ -1116,14 +1109,6 @@ Example::
| 13:49:00 |
+----------------------------+

os> source=people | eval `TIME('2020-02-30 13:49')` = TIME('2020-02-30 13:49') | fields `TIME('2020-02-30 13:49')`
fetched rows / total rows = 1/1
+----------------------------+
| TIME('2020-02-30 13:49') |
|----------------------------|
| null |
+----------------------------+


TIME_TO_SEC
-----------
Expand Down

0 comments on commit ae241b6

Please sign in to comment.