[
https://issues.apache.org/jira/browse/CALCITE-7170?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=18019218#comment-18019218
]
Sanskriti Bora commented on CALCITE-7170:
-----------------------------------------
Thank you for raising this important point.
If I plan to update toTimeStamp() function like the below:
{code:java}
private static Timestamp toTimestamp(Object x) {
if (x instanceof String) {
String s = (String) x;
try {
Instant instant = Instant.parse(s);
LocalDateTime ldt = LocalDateTime.ofInstant(instant,
ZoneId.systemDefault());
return Timestamp.valueOf(ldt);
} catch (DateTimeParseException e) {
try {
OffsetDateTime odt = OffsetDateTime.parse(s);
LocalDateTime ldt =
odt.toInstant().atZone(ZoneId.systemDefault()).toLocalDateTime();
return Timestamp.valueOf(ldt);
} catch (DateTimeParseException e2) {
try {
return Timestamp.valueOf(LocalDateTime.parse(s));
} catch (DateTimeParseException e3) {
return Timestamp.valueOf(s);
}
}
}
}
return new Timestamp(toLong(x));
}{code}
With the updated implementation, if the input string is an instant (e.g.,
"2025-08-14T15:53:00.000Z"), we first convert it to a local date-time in the
JVM's default time zone before creating the SQL {{{}Timestamp{}}}. This means
that the same instant will be mapped to different local TIMESTAMP values
depending on the JVM time zone.
For example, if two users in different time zones run the same script, the
wall-clock value stored in the database will reflect their respective JVM
default time zones, and thus may differ. This is consistent with SQL semantics,
where TIMESTAMP is a local date-time without time zone information.
Can you suggest if this is a good way to go about it or have something to add
helping me solve this issue?
> Support ISO String Binding for Date/Time/Timestamp in Avatica
> -------------------------------------------------------------
>
> Key: CALCITE-7170
> URL: https://issues.apache.org/jira/browse/CALCITE-7170
> Project: Calcite
> Issue Type: Improvement
> Components: avatica
> Reporter: Sanskriti Bora
> Priority: Critical
> Labels: pull-request-available
>
> I would like to propose adding support for binding ISO-formatted string
> values to date, time, and timestamp types in Avatica. Currently, Avatica only
> supports binding these types using Java objects (such as java.sql.Date,
> java.sql.Time, and java.sql.Timestamp), which can be limiting for clients
> that work with standard string representations.
> Adding ISO string binding would improve interoperability and make it easier
> to work with standard date/time formats across different clients and
> languages.
> Example
> {code:java}
> insertStatement.setString(1, "2025-08-14T15:53:00.000Z");
> insertStatement.setString(2, "2025-04-01");
> insertStatement.setString(3, "21:39:50");{code}
--
This message was sent by Atlassian Jira
(v8.20.10#820010)