-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Update TIME and DATE functions #134
Changes from 3 commits
65c34ac
4a4e425
da22234
e421349
26c1165
be3ea22
4f7edd1
a00863c
99c98b0
f9e38e9
2016222
4c0928d
95c5e5c
61289bb
310f653
484b28c
157059f
77bd46e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -55,6 +55,7 @@ | |
import org.opensearch.sql.data.model.ExprValue; | ||
import org.opensearch.sql.data.type.ExprCoreType; | ||
import org.opensearch.sql.exception.ExpressionEvaluationException; | ||
import org.opensearch.sql.exception.SemanticCheckException; | ||
import org.opensearch.sql.expression.function.BuiltinFunctionName; | ||
import org.opensearch.sql.expression.function.BuiltinFunctionRepository; | ||
import org.opensearch.sql.expression.function.DefaultFunctionResolver; | ||
|
@@ -651,7 +652,11 @@ private ExprValue exprConvertTZ(ExprValue startingDateTime, ExprValue fromTz, Ex | |
*/ | ||
private ExprValue exprDate(ExprValue exprValue) { | ||
if (exprValue instanceof ExprStringValue) { | ||
return new ExprDateValue(exprValue.stringValue()); | ||
try { | ||
return new ExprDateValue(exprValue.stringValue()); | ||
} catch (SemanticCheckException e) { | ||
return ExprNullValue.of(); | ||
} | ||
} else { | ||
return new ExprDateValue(exprValue.dateValue()); | ||
} | ||
|
@@ -944,6 +949,7 @@ private ExprValue exprSubDateInterval(ExprValue date, ExprValue expr) { | |
*/ | ||
private ExprValue exprTime(ExprValue exprValue) { | ||
if (exprValue instanceof ExprStringValue) { | ||
//try catch | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. todo? |
||
return new ExprTimeValue(exprValue.stringValue()); | ||
} else { | ||
return new ExprTimeValue(exprValue.timeValue()); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -240,6 +240,11 @@ public void date() { | |
assertEquals(DATE, expr.type()); | ||
assertEquals(new ExprDateValue("2020-08-17"), eval(expr)); | ||
assertEquals("date(DATE '2020-08-17')", expr.toString()); | ||
|
||
expr = dsl.date(DSL.literal(new ExprDateValue("2020-08-17 12:12:00"))); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. we should test with nano seconds too |
||
assertEquals(DATE, expr.type()); | ||
assertEquals(new ExprDateValue("2020-08-17 12:12:00"), eval(expr)); | ||
assertEquals("date(DATE '2020-08-17')", expr.toString()); | ||
} | ||
|
||
@Test | ||
|
@@ -795,6 +800,11 @@ public void time() { | |
assertEquals(TIME, expr.type()); | ||
assertEquals(new ExprTimeValue("01:01:01"), eval(expr)); | ||
assertEquals("time(TIME '01:01:01')", expr.toString()); | ||
|
||
expr = dsl.time(DSL.literal(new ExprTimeValue("2020-01-02 01:01:01"))); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. we should test with nano seconds too (separately) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Added case for times < 1.0 seconds. 2016222 |
||
assertEquals(TIME, expr.type()); | ||
assertEquals(new ExprTimeValue("2020-01-02 01:01:01"), eval(expr)); | ||
assertEquals("time(TIME '01:01:01')", expr.toString()); | ||
} | ||
|
||
@Test | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should be able to remove the
if
statement and get the same result. Thetry...catch
will cover both cases.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we still need it because it can be a stringValue or a dateValue.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is there a case where an ExprStringValue doesn't have a stringValue()?