-
Notifications
You must be signed in to change notification settings - Fork 141
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1260 from penghuo/hp/2.5-release
* Add BWC tests for running against distribution bundle. (#1209) Signed-off-by: Zelin Hao <[email protected]> * Add Alternate Syntax For Match_Query And Other Functions (#1166) Added Tests And Implementation For Match_Query, Match_Phrase, and Multi_Match Functions Signed-off-by: GabeFernandez310 <[email protected]> Signed-off-by: GabeFernandez310 <[email protected]> Signed-off-by: GabeFernandez310 <[email protected]> * Merge pull request #1241 from Bit-Quill/Failing-CI-Hot-Fix Hot Fix For CI Build (cherry picked from commit aae57a0) Signed-off-by: GabeFernandez310 <[email protected]> * Fixed error with single timestamp query (#1244) (#1246) Signed-off-by: vamsi-amazon <[email protected]> Signed-off-by: vamsi-amazon <[email protected]> (cherry picked from commit ee949cc) Co-authored-by: vamsi-amazon <[email protected]> * Add Second_Of_Minute Function As An Alias Of The Second Function (#1231) (#1237) Added Testing And Implementation For Second_Of_Minute Function Signed-off-by: GabeFernandez310 <[email protected]> Signed-off-by: GabeFernandez310 <[email protected]> (cherry picked from commit dce7d0e) Co-authored-by: GabeFernandez310 <[email protected]> * Add functions `ADDTIME` and `SUBTIME`. (#132) (#1194) (#1252) * Add functions `ADDTIME` and `SUBTIME`. (#132) Signed-off-by: Yury-Fridlyand <[email protected]> (cherry picked from commit 7630f87) Co-authored-by: Yury-Fridlyand <[email protected]> * Add Day_Of_Week Function As An Alias Of DayOfWeek (#190) (#1228) (#1239) Added Implementation And Testing For Day_Of_Week Function Signed-off-by: GabeFernandez310 <[email protected]> Signed-off-by: GabeFernandez310 <[email protected]> (cherry picked from commit bac9c37) Co-authored-by: GabeFernandez310 <[email protected]> * [Backport 2.x] Add Minute_Of_Hour Function As An Alias Of Minute Function (#1253) * Add Minute_Of_Hour Function As An Alias Of Minute Function (#196) (#1230) Added Testing And Implementation For Minute_Of_Hour Function Signed-off-by: GabeFernandez310 <[email protected]> Signed-off-by: GabeFernandez310 <[email protected]> (cherry picked from commit 61e2374) * Added Missing Imports Signed-off-by: GabeFernandez310 <[email protected]> Signed-off-by: GabeFernandez310 <[email protected]> * Add support for long value return for CEIL, CEILING and FLOOR math functions (#1205) (#1255) * Added long fix for CEIL, CEILING and FLOOR functions using LONG instead of INT for RETURN. Signed-off-by: MitchellGale-BitQuill <[email protected]> Signed-off-by: Yury-Fridlyand <[email protected]> Co-authored-by: Yury-Fridlyand <[email protected]> * Support JOIN query on object field with unexpanded name (#1229) (#1250) * Resolve sub object field in search hit source Signed-off-by: Chen Dai <[email protected]> * Rename to unexpanded object Signed-off-by: Chen Dai <[email protected]> * Update IT with where condition Signed-off-by: Chen Dai <[email protected]> * Fix test index mapping Signed-off-by: Chen Dai <[email protected]> Signed-off-by: Chen Dai <[email protected]> (cherry picked from commit 151f4cc) Co-authored-by: Chen Dai <[email protected]> * Remove unnecessary scripts after repo split (#1256) Signed-off-by: Joshua Li <[email protected]> * Add Support For `TIME` Type in "*_OF_YEAR" Functions (#199) (#1223) (#1258) Added Support And Tests For Time Type in day_of_year, week_of_year, month_of_year Functions Signed-off-by: GabeFernandez310 <[email protected]> (cherry picked from commit 6e72f18) Co-authored-by: GabeFernandez310 <[email protected]> Signed-off-by: Zelin Hao <[email protected]> Signed-off-by: GabeFernandez310 <[email protected]> Signed-off-by: GabeFernandez310 <[email protected]> Signed-off-by: MitchellGale-BitQuill <[email protected]> Signed-off-by: Yury-Fridlyand <[email protected]> Signed-off-by: Joshua Li <[email protected]> Co-authored-by: Zelin Hao <[email protected]> Co-authored-by: GabeFernandez310 <[email protected]> Co-authored-by: YANGDB <[email protected]> Co-authored-by: opensearch-trigger-bot[bot] <98922864+opensearch-trigger-bot[bot]@users.noreply.github.com> Co-authored-by: vamsi-amazon <[email protected]> Co-authored-by: Yury-Fridlyand <[email protected]> Co-authored-by: GabeFernandez310 <[email protected]> Co-authored-by: Chen Dai <[email protected]> Co-authored-by: Joshua Li <[email protected]>
- Loading branch information
Showing
46 changed files
with
2,519 additions
and
366 deletions.
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
217 changes: 204 additions & 13 deletions
217
core/src/main/java/org/opensearch/sql/expression/datetime/DateTimeFunction.java
Large diffs are not rendered by default.
Oops, something went wrong.
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
127 changes: 127 additions & 0 deletions
127
core/src/test/java/org/opensearch/sql/expression/datetime/AddTimeAndSubTimeTest.java
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 |
---|---|---|
@@ -0,0 +1,127 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package org.opensearch.sql.expression.datetime; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
import static org.opensearch.sql.data.type.ExprCoreType.DATETIME; | ||
import static org.opensearch.sql.data.type.ExprCoreType.TIME; | ||
|
||
import java.time.Instant; | ||
import java.time.LocalDate; | ||
import java.time.LocalDateTime; | ||
import java.time.LocalTime; | ||
import java.time.temporal.Temporal; | ||
import java.util.stream.Stream; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.params.ParameterizedTest; | ||
import org.junit.jupiter.params.provider.Arguments; | ||
import org.junit.jupiter.params.provider.MethodSource; | ||
|
||
public class AddTimeAndSubTimeTest extends DateTimeTestBase { | ||
|
||
@Test | ||
// (TIME, TIME/DATE/DATETIME/TIMESTAMP) -> TIME | ||
public void return_time_when_first_arg_is_time() { | ||
var res = addtime(LocalTime.of(21, 0), LocalTime.of(0, 5)); | ||
assertEquals(TIME, res.type()); | ||
assertEquals(LocalTime.of(21, 5), res.timeValue()); | ||
|
||
res = subtime(LocalTime.of(21, 0), LocalTime.of(0, 5)); | ||
assertEquals(TIME, res.type()); | ||
assertEquals(LocalTime.of(20, 55), res.timeValue()); | ||
|
||
res = addtime(LocalTime.of(12, 20), Instant.ofEpochSecond(42)); | ||
assertEquals(TIME, res.type()); | ||
assertEquals(LocalTime.of(12, 20, 42), res.timeValue()); | ||
|
||
res = subtime(LocalTime.of(10, 0), Instant.ofEpochSecond(42)); | ||
assertEquals(TIME, res.type()); | ||
assertEquals(LocalTime.of(9, 59, 18), res.timeValue()); | ||
|
||
res = addtime(LocalTime.of(2, 3, 4), LocalDateTime.of(1961, 4, 12, 9, 7)); | ||
assertEquals(TIME, res.type()); | ||
assertEquals(LocalTime.of(11, 10, 4), res.timeValue()); | ||
|
||
res = subtime(LocalTime.of(12, 3, 4), LocalDateTime.of(1961, 4, 12, 9, 7)); | ||
assertEquals(TIME, res.type()); | ||
assertEquals(LocalTime.of(2, 56, 4), res.timeValue()); | ||
|
||
res = addtime(LocalTime.of(9, 7), LocalDate.now()); | ||
assertEquals(TIME, res.type()); | ||
assertEquals(LocalTime.of(9, 7), res.timeValue()); | ||
|
||
res = subtime(LocalTime.of(9, 7), LocalDate.of(1961, 4, 12)); | ||
assertEquals(TIME, res.type()); | ||
assertEquals(LocalTime.of(9, 7), res.timeValue()); | ||
} | ||
|
||
@Test | ||
public void time_limited_by_24_hours() { | ||
var res = addtime(LocalTime.of(21, 0), LocalTime.of(14, 5)); | ||
assertEquals(TIME, res.type()); | ||
assertEquals(LocalTime.of(11, 5), res.timeValue()); | ||
|
||
res = subtime(LocalTime.of(14, 0), LocalTime.of(21, 5)); | ||
assertEquals(TIME, res.type()); | ||
assertEquals(LocalTime.of(16, 55), res.timeValue()); | ||
} | ||
|
||
// Function signature is: | ||
// (DATE/DATETIME/TIMESTAMP, TIME/DATE/DATETIME/TIMESTAMP) -> DATETIME | ||
private static Stream<Arguments> getTestData() { | ||
return Stream.of( | ||
// DATETIME and TIME/DATE/DATETIME/TIMESTAMP | ||
Arguments.of(LocalDateTime.of(1961, 4, 12, 9, 7), LocalTime.of(1, 48), | ||
LocalDateTime.of(1961, 4, 12, 10, 55), LocalDateTime.of(1961, 4, 12, 7, 19)), | ||
Arguments.of(LocalDateTime.of(1961, 4, 12, 9, 7), LocalDate.of(2000, 1, 1), | ||
LocalDateTime.of(1961, 4, 12, 9, 7), LocalDateTime.of(1961, 4, 12, 9, 7)), | ||
Arguments.of(LocalDateTime.of(1961, 4, 12, 9, 7), LocalDateTime.of(1235, 5, 6, 1, 48), | ||
LocalDateTime.of(1961, 4, 12, 10, 55), LocalDateTime.of(1961, 4, 12, 7, 19)), | ||
Arguments.of(LocalDateTime.of(1961, 4, 12, 9, 7), Instant.ofEpochSecond(42), | ||
LocalDateTime.of(1961, 4, 12, 9, 7, 42), LocalDateTime.of(1961, 4, 12, 9, 6, 18)), | ||
// DATE and TIME/DATE/DATETIME/TIMESTAMP | ||
Arguments.of(LocalDate.of(1961, 4, 12), LocalTime.of(9, 7), | ||
LocalDateTime.of(1961, 4, 12, 9, 7), LocalDateTime.of(1961, 4, 11, 14, 53)), | ||
Arguments.of(LocalDate.of(1961, 4, 12), LocalDate.of(2000, 1, 1), | ||
LocalDateTime.of(1961, 4, 12, 0, 0), LocalDateTime.of(1961, 4, 12, 0, 0)), | ||
Arguments.of(LocalDate.of(1961, 4, 12), LocalDateTime.of(1235, 5, 6, 1, 48), | ||
LocalDateTime.of(1961, 4, 12, 1, 48), LocalDateTime.of(1961, 4, 11, 22, 12)), | ||
Arguments.of(LocalDate.of(1961, 4, 12), Instant.ofEpochSecond(42), | ||
LocalDateTime.of(1961, 4, 12, 0, 0, 42), LocalDateTime.of(1961, 4, 11, 23, 59, 18)), | ||
// TIMESTAMP and TIME/DATE/DATETIME/TIMESTAMP | ||
Arguments.of(Instant.ofEpochSecond(42), LocalTime.of(9, 7), | ||
LocalDateTime.of(1970, 1, 1, 9, 7, 42), LocalDateTime.of(1969, 12, 31, 14, 53, 42)), | ||
Arguments.of(Instant.ofEpochSecond(42), LocalDate.of(1961, 4, 12), | ||
LocalDateTime.of(1970, 1, 1, 0, 0, 42), LocalDateTime.of(1970, 1, 1, 0, 0, 42)), | ||
Arguments.of(Instant.ofEpochSecond(42), LocalDateTime.of(1961, 4, 12, 9, 7), | ||
LocalDateTime.of(1970, 1, 1, 9, 7, 42), LocalDateTime.of(1969, 12, 31, 14, 53, 42)), | ||
Arguments.of(Instant.ofEpochSecond(42), Instant.ofEpochMilli(42), | ||
LocalDateTime.of(1970, 1, 1, 0, 0, 42, 42000000), | ||
LocalDateTime.of(1970, 1, 1, 0, 0, 41, 958000000)) | ||
); | ||
} | ||
|
||
/** | ||
* Check that `ADDTIME` and `SUBTIME` functions result value and type. | ||
* @param arg1 First argument. | ||
* @param arg2 Second argument. | ||
* @param addTimeExpectedResult Expected result for `ADDTIME`. | ||
* @param subTimeExpectedResult Expected result for `SUBTIME`. | ||
*/ | ||
@ParameterizedTest | ||
@MethodSource("getTestData") | ||
public void return_datetime_when_first_arg_is_not_time(Temporal arg1, Temporal arg2, | ||
LocalDateTime addTimeExpectedResult, | ||
LocalDateTime subTimeExpectedResult) { | ||
var res = addtime(arg1, arg2); | ||
assertEquals(DATETIME, res.type()); | ||
assertEquals(addTimeExpectedResult, res.datetimeValue()); | ||
|
||
res = subtime(arg1, arg2); | ||
assertEquals(DATETIME, res.type()); | ||
assertEquals(subTimeExpectedResult, res.datetimeValue()); | ||
} | ||
} |
Oops, something went wrong.