forked from opensearch-project/sql
-
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
Merged
MitchellGale
merged 18 commits into
Integ-updateDateFunction
from
dev-updateTimeFunction
Oct 31, 2022
Merged
Changes from all commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
65c34ac
Added test cases and support for strict date validation. Added abilit…
MitchellGale 4a4e425
Update `ExprTimeValue` by `datetimeValue` and other interfaces. Add c…
Yury-Fridlyand da22234
core/src/main/java/org/opensearch/sql/expression/datetime/DateTimeFun…
Yury-Fridlyand e421349
Fix conversion to timestamp.
Yury-Fridlyand 26c1165
Added try catch to return null for invalid date in DATE
MitchellGale be3ea22
Added null test for TIME and DATE
MitchellGale 4f7edd1
Added exprDate to accept time.
MitchellGale a00863c
Accept date time for time and date
MitchellGale 99c98b0
Adding coverage
MitchellGale f9e38e9
Fixed code coverage for time passed to date function case.
MitchellGale 2016222
Adding more test cases for datetime and milliseconds for DATE and TIM…
MitchellGale 4c0928d
Removed unused imports.
MitchellGale 95c5e5c
Removed unused DATETIMEFORMATTERS.
MitchellGale 61289bb
Added support for HH:mm for time/datetime inputs. Removed call for lo…
MitchellGale 310f653
Added more doc tests.
MitchellGale 484b28c
Removed blocks from cherry-picked PR.
MitchellGale 157059f
Reverted change in ExprDateTimeValue
MitchellGale 77bd46e
Reverted reverted changes in ExprDateTimeValue. Reverted change in Ex…
MitchellGale File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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()); | ||
} | ||
|
@@ -943,8 +948,15 @@ private ExprValue exprSubDateInterval(ExprValue date, ExprValue expr) { | |
* @return ExprValue. | ||
*/ | ||
private ExprValue exprTime(ExprValue exprValue) { | ||
if (exprValue.type() == DATE) { | ||
return new ExprTimeValue("00:00:00"); | ||
} | ||
if (exprValue instanceof ExprStringValue) { | ||
return new ExprTimeValue(exprValue.stringValue()); | ||
try { | ||
return new ExprTimeValue(exprValue.stringValue()); | ||
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. why not use a switch on type() here. For TIME, STRING, DATE, and TIMESTAMP? |
||
} catch (SemanticCheckException e) { | ||
return ExprNullValue.of(); | ||
} | ||
} else { | ||
return new ExprTimeValue(exprValue.timeValue()); | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -24,6 +24,7 @@ | |
import static org.opensearch.sql.data.type.ExprCoreType.TIMESTAMP; | ||
|
||
import com.google.common.collect.ImmutableList; | ||
import java.time.LocalDate; | ||
import java.util.List; | ||
import lombok.AllArgsConstructor; | ||
import org.junit.jupiter.api.BeforeEach; | ||
|
@@ -240,6 +241,19 @@ 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()); | ||
|
||
expr = dsl.date(DSL.literal(new ExprDateValue("2020-08-17 12:12"))); | ||
assertEquals(DATE, expr.type()); | ||
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 | ||
|
@@ -795,6 +809,33 @@ 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("01:01"))); | ||
assertEquals(TIME, expr.type()); | ||
assertEquals(new ExprTimeValue("01:01"), eval(expr)); | ||
assertEquals("time(TIME '01:01:00')", expr.toString()); | ||
|
||
expr = dsl.time(DSL.literal(new ExprTimeValue("2019-04-19 01:01:01"))); | ||
assertEquals(TIME, expr.type()); | ||
assertEquals(new ExprTimeValue("2019-04-19 01:01:01"), eval(expr)); | ||
assertEquals("time(TIME '01:01:01')", expr.toString()); | ||
|
||
expr = dsl.time(DSL.literal(new ExprTimeValue("2019-04-19 01:01"))); | ||
assertEquals(TIME, expr.type()); | ||
assertEquals(new ExprTimeValue("2019-04-19 01:01"), eval(expr)); | ||
assertEquals("time(TIME '01:01:00')", expr.toString()); | ||
|
||
expr = dsl.time(DSL.literal(new ExprTimeValue("01:01:01.0123"))); | ||
assertEquals(TIME, expr.type()); | ||
assertEquals(new ExprTimeValue("01:01:01.0123"), eval(expr)); | ||
assertEquals("time(TIME '01:01:01.0123')", expr.toString()); | ||
|
||
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 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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()?