Skip to content

Commit 2c5db2a

Browse files
committed
Restrict the format of convert_tz's argument
Signed-off-by: Yuanchun Shen <yuanchu@amazon.com>
1 parent 4a8380e commit 2c5db2a

1 file changed

Lines changed: 8 additions & 2 deletions

File tree

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

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@
8181
import org.opensearch.sql.expression.function.FunctionSignature;
8282
import org.opensearch.sql.expression.function.SerializableFunction;
8383
import org.opensearch.sql.expression.function.SerializableTriFunction;
84+
import org.opensearch.sql.utils.DateTimeFormatters;
8485
import org.opensearch.sql.utils.DateTimeUtils;
8586

8687
/**
@@ -1280,8 +1281,13 @@ public static ExprValue exprConvertTZ(
12801281
ExprValue startingDateTime, ExprValue fromTz, ExprValue toTz) {
12811282
if (startingDateTime.type() == ExprCoreType.STRING) {
12821283
try {
1283-
startingDateTime = new ExprTimestampValue(startingDateTime.stringValue());
1284-
} catch (ExpressionEvaluationException e) {
1284+
// CONVERT_TZ only expects a timestamp in the format "yyyy-MM-dd HH:mm:ss[.SSSSSSSSS]".
1285+
startingDateTime =
1286+
new ExprTimestampValue(
1287+
LocalDateTime.parse(
1288+
startingDateTime.stringValue(),
1289+
DateTimeFormatters.DATE_TIME_FORMATTER_VARIABLE_NANOS));
1290+
} catch (DateTimeParseException e) {
12851291
return ExprNullValue.of();
12861292
}
12871293
}

0 commit comments

Comments
 (0)