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
Implementation UTC_DATE/UTC_TIME/UTC_TIMESTAMP #127
Merged
Merged
Changes from all commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
5107309
Added UTC_DATE, UTC_TIME, UTC_TIMESTAMP implementations.
MitchellGale cc2d186
Added doc tests and fixed java doc description for UTC TIME/DATE/TIME…
MitchellGale cfbfdf2
Fixed some javadocs, and addressed other PR comments.
MitchellGale 7efe2e2
Fixed duplicate UTC functions in parser. Moved tests over to likenow …
MitchellGale fbf30d5
Fixed UTC IT test issues with not using UTC time for functions.
MitchellGale 02a1b40
Switched timestamp return type to be DATETIME not TIMESTAMP.
MitchellGale d9964c8
ADDED IT TESTS TO SQL
MitchellGale 9c3f3a3
Update docs/user/ppl/functions/datetime.rst
MitchellGale 1e85d3b
Update docs/user/ppl/functions/datetime.rst
MitchellGale 648744c
Update core/src/test/java/org/opensearch/sql/expression/datetime/NowL…
MitchellGale 50fdcf3
Update integ-test/src/test/java/org/opensearch/sql/ppl/DateTimeFuncti…
MitchellGale 2a23bf8
Update core/src/main/java/org/opensearch/sql/expression/datetime/Date…
MitchellGale d574625
resolved conflict.
MitchellGale 4f321a1
Removed formatter
MitchellGale 90f4358
Made PR requested changes
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
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 |
---|---|---|
|
@@ -12,12 +12,14 @@ | |
import static org.opensearch.sql.data.type.ExprCoreType.DATE; | ||
import static org.opensearch.sql.data.type.ExprCoreType.DATETIME; | ||
import static org.opensearch.sql.data.type.ExprCoreType.TIME; | ||
import static org.opensearch.sql.data.type.ExprCoreType.TIMESTAMP; | ||
|
||
import java.time.Duration; | ||
import java.time.LocalDate; | ||
import java.time.LocalDateTime; | ||
import java.time.LocalTime; | ||
import java.time.Period; | ||
import java.time.ZoneId; | ||
import java.time.temporal.Temporal; | ||
import java.util.List; | ||
import java.util.function.Function; | ||
|
@@ -55,7 +57,26 @@ private static Stream<Arguments> functionNames() { | |
Arguments.of((Function<Expression[], FunctionExpression>)dsl::curdate, | ||
"curdate", DATE, false, (Supplier<Temporal>)LocalDate::now), | ||
Arguments.of((Function<Expression[], FunctionExpression>)dsl::current_date, | ||
"current_date", DATE, false, (Supplier<Temporal>)LocalDate::now)); | ||
"current_date", DATE, false, (Supplier<Temporal>)LocalDate::now), | ||
Arguments.of((Function<Expression[], FunctionExpression>)dsl::utc_date, | ||
"utc_date", DATE, false, (Supplier<Temporal>)NowLikeFunctionTest::getUtcDateRefValue), | ||
Arguments.of((Function<Expression[], FunctionExpression>)dsl::utc_time, | ||
"utc_time", TIME, false, (Supplier<Temporal>)NowLikeFunctionTest::getUtcTimeRefValue), | ||
Arguments.of((Function<Expression[], FunctionExpression>)dsl::utc_timestamp, | ||
"utc_timestamp", DATETIME, false, | ||
(Supplier<Temporal>)NowLikeFunctionTest::getUtcTimestampRefValue)); | ||
} | ||
|
||
private static LocalDateTime getUtcTimestampRefValue() { | ||
return LocalDateTime.now(ZoneId.of("UTC")); | ||
} | ||
|
||
private static LocalDate getUtcDateRefValue() { | ||
return getUtcTimestampRefValue().toLocalDate(); | ||
} | ||
|
||
private static LocalTime getUtcTimeRefValue() { | ||
return getUtcTimestampRefValue().toLocalTime(); | ||
} | ||
|
||
private Temporal extractValue(FunctionExpression func) { | ||
|
@@ -86,11 +107,11 @@ private long getDiff(Temporal sample, Temporal reference) { | |
@ParameterizedTest(name = "{1}") | ||
@MethodSource("functionNames") | ||
public void test_now_like_functions(Function<Expression[], FunctionExpression> function, | ||
@SuppressWarnings("unused") // Used in the test name above | ||
String name, | ||
ExprCoreType resType, | ||
Boolean hasFsp, | ||
Supplier<Temporal> referenceGetter) { | ||
@SuppressWarnings("unused") // Used in the test name above | ||
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. Was this indentation change needed? |
||
String name, | ||
ExprCoreType resType, | ||
Boolean hasFsp, | ||
Supplier<Temporal> referenceGetter) { | ||
// Check return types: | ||
// `func()` | ||
FunctionExpression expr = function.apply(new Expression[]{}); | ||
|
@@ -113,16 +134,18 @@ public void test_now_like_functions(Function<Expression[], FunctionExpression> f | |
|
||
// Check how calculations are precise: | ||
// `func()` | ||
// 17:59:59.99999 can pass as being equal to 18:00:00 | ||
var delta = resType == DATE ? 0 : 1; | ||
assertTrue(Math.abs(getDiff( | ||
extractValue(function.apply(new Expression[]{})), | ||
referenceGetter.get() | ||
)) <= 1); | ||
extractValue(function.apply(new Expression[]{})), | ||
referenceGetter.get() | ||
)) <= delta); | ||
if (hasFsp) { | ||
// `func(fsp)` | ||
assertTrue(Math.abs(getDiff( | ||
extractValue(function.apply(new Expression[]{DSL.literal(0)})), | ||
referenceGetter.get() | ||
)) <= 1); | ||
extractValue(function.apply(new Expression[]{DSL.literal(0)})), | ||
referenceGetter.get() | ||
)) <= delta); | ||
} | ||
} | ||
} |
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
Oops, something went wrong.
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.
JavaDoc should explain what the return is.
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.
@Yury-Fridlyand any advice on how to address this if not including "yyyy-MM-dd"
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.
You can mention return value type.