Skip to content

Commit cf24dab

Browse files
committed
Revert "Convert string inputs to timestamp when fed to unix_timestamp function"
This reverts commit 6937c9b. Signed-off-by: Yuanchun Shen <yuanchu@amazon.com>
1 parent 461b566 commit cf24dab

3 files changed

Lines changed: 2 additions & 21 deletions

File tree

core/src/main/java/org/opensearch/sql/expression/datetime/DateTimeFunctions.java

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2164,21 +2164,14 @@ public static Double transferUnixTimeStampFromDoubleInput(Double value) {
21642164
}
21652165
}
21662166

2167-
private static double getUnixTimestampAsDouble(ExprTimestampValue value) {
2168-
return value.timestampValue().getEpochSecond() + value.timestampValue().getNano() / 1E9;
2169-
}
2170-
21712167
private Double unixTimeStampOfImpl(ExprValue value) {
21722168
// Also, according to MySQL documentation:
21732169
// The date argument may be a DATE, DATETIME, or TIMESTAMP ...
21742170
switch ((ExprCoreType) value.type()) {
21752171
case DATE:
21762172
return value.dateValue().toEpochSecond(LocalTime.MIN, ZoneOffset.UTC) + 0d;
21772173
case TIMESTAMP:
2178-
return getUnixTimestampAsDouble((ExprTimestampValue) value);
2179-
case STRING:
2180-
ExprTimestampValue timestampValue = new ExprTimestampValue(value.stringValue());
2181-
return getUnixTimestampAsDouble(timestampValue);
2174+
return value.timestampValue().getEpochSecond() + value.timestampValue().getNano() / 1E9;
21822175
default:
21832176
// ... or a number in YYMMDD, YYMMDDhhmmss, YYYYMMDD, or YYYYMMDDhhmmss format.
21842177
// If the argument includes a time part, it may optionally include a fractional

docs/user/ppl/functions/datetime.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1899,7 +1899,7 @@ The date argument may be a DATE, or TIMESTAMP string, or a number in YYMMDD, YYM
18991899
If argument is in invalid format or outside of range 1970-01-01 00:00:00 - 3001-01-18 23:59:59.999999 (0 to 32536771199.999999 epoch time), function returns NULL.
19001900
You can use `FROM_UNIXTIME`_ to do reverse conversion.
19011901

1902-
Argument type: <NONE>/DOUBLE/DATE/TIMESTAMP/STRING
1902+
Argument type: <NONE>/DOUBLE/DATE/TIMESTAMP
19031903

19041904
Return type: DOUBLE
19051905

integ-test/src/test/java/org/opensearch/sql/calcite/standalone/CalcitePPLDateTimeBuiltinFunctionIT.java

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -383,18 +383,6 @@ public void testUnixTimestamp() {
383383
verifyDataRows(actual, closeTo(1220249547.0, 3404817525.0, 1.220249547123456E9));
384384
}
385385

386-
@Test
387-
public void testUnixTimestampWithString() {
388-
JSONObject actual =
389-
executeQuery(
390-
String.format(
391-
"source=%s | head 1 | eval t = UNIX_TIMESTAMP('2008-09-01 06:12:27.123456') |"
392-
+ " fields t",
393-
TEST_INDEX_DATE_FORMATS));
394-
verifySchema(actual, schema("t", "double"));
395-
verifyDataRows(actual, closeTo(1.220249547123456E9));
396-
}
397-
398386
@Test
399387
public void testWeekAndWeekOfYear() {
400388
JSONObject actual =

0 commit comments

Comments
 (0)