You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@ignite.apache.org by "lowka (via GitHub)" <gi...@apache.org> on 2025/05/08 09:49:50 UTC

[PR] IGNITE-25190 Current timestamp / date adjusted to user time zone when cast to varchar [ignite-3]

lowka opened a new pull request, #5784:
URL: https://github.com/apache/ignite-3/pull/5784

   Updates JDBCResultSet:
   
   - Updates `getString` to return string representation of JDBC data types. 
   - Fixes `getTime`, `getDate` and `getTimestamp` from TIMESTAMP_LTZ to take connection's zoneId into account.
   
   https://issues.apache.org/jira/browse/IGNITE-25190
   
   ---
   
   Thank you for submitting the pull request.
   
   To streamline the review process of the patch and ensure better code quality
   we ask both an author and a reviewer to verify the following:
   
   ### The Review Checklist
   - [ ] **Formal criteria:** TC status, codestyle, mandatory documentation. Also make sure to complete the following:  
   \- There is a single JIRA ticket related to the pull request.  
   \- The web-link to the pull request is attached to the JIRA ticket.  
   \- The JIRA ticket has the Patch Available state.  
   \- The description of the JIRA ticket explains WHAT was made, WHY and HOW.  
   \- The pull request title is treated as the final commit message. The following pattern must be used: IGNITE-XXXX Change summary where XXXX - number of JIRA issue.
   - [ ] **Design:** new code conforms with the design principles of the components it is added to.
   - [ ] **Patch quality:** patch cannot be split into smaller pieces, its size must be reasonable.
   - [ ] **Code quality:** code is clean and readable, necessary developer documentation is added if needed.
   - [ ] **Tests code quality:** test set covers positive/negative scenarios, happy/edge cases. Tests are effective in terms of execution time and resources.
   
   ### Notes
   - [Apache Ignite Coding Guidelines](https://cwiki.apache.org/confluence/display/IGNITE/Java+Code+Style+Guide)


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@ignite.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] IGNITE-25190 Current timestamp / date adjusted to user time zone when cast to varchar [ignite-3]

Posted by "korlov42 (via GitHub)" <gi...@apache.org>.
korlov42 commented on code in PR #5784:
URL: https://github.com/apache/ignite-3/pull/5784#discussion_r2086298482


##########
modules/jdbc/src/integrationTest/java/org/apache/ignite/jdbc/ItJdbcClientTimeZoneTest.java:
##########
@@ -176,25 +180,55 @@ public void dynamicParamRespectsTimeZone() throws SQLException {
                     // Client time zone is "GMT".
                     {
                         assertEquals(timestamp("1970-01-01T00:00:00"), rs.getTimestamp(1));
-                        // Since client time zone is GMT, timestamp will contain original UTC value from store.
+                        assertEquals(LocalTime.of(0, 0, 0), rs.getTime(1).toLocalTime());
+                        assertEquals(LocalDate.of(1970, 1, 1), rs.getDate(1).toLocalDate());
+
                         assertEquals(timestamp("1969-12-31T23:00:00"), rs.getTimestamp(2));
+                        assertEquals(LocalTime.of(23, 0, 0), rs.getTime(2).toLocalTime());
+                        assertEquals(LocalDate.of(1969, 12, 31), rs.getDate(2).toLocalDate());
                     }
+                }
+            }
+        }
+
+        TimeZone.setDefault(TimeZone.getTimeZone("GMT+1"));
+
+        try (Connection conn = DriverManager.getConnection(URL)) {
+            try (Statement stmt = conn.createStatement()) {
+                try (ResultSet rs = stmt.executeQuery("SELECT ts, ts_tz FROM test where id=1")) {
+                    assertTrue(rs.next());
 
                     // Session and client time zone are same ("GMT+1").
                     {
-                        TimeZone.setDefault(TimeZone.getTimeZone("GMT+1"));
-
                         assertEquals(timestamp("1970-01-01T00:00:00"), rs.getTimestamp(1));
+                        assertEquals(LocalTime.of(0, 0, 0), rs.getTime(1).toLocalTime());
+                        assertEquals(LocalDate.of(1970, 1, 1), rs.getDate(1).toLocalDate());
+
                         assertEquals(timestamp("1970-01-01T00:00:00"), rs.getTimestamp(2));
+                        assertEquals(LocalTime.of(0, 0, 0), rs.getTime(2).toLocalTime());
+                        assertEquals(LocalDate.of(1970, 1, 1), rs.getDate(2).toLocalDate());
                     }
+                }
+            }
+        }
+
+        TimeZone.setDefault(TimeZone.getTimeZone("GMT+2"));
+
+        try (Connection conn = DriverManager.getConnection(URL)) {

Review Comment:
   let's have at least one test case where time zones is passed through connection string



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@ignite.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] IGNITE-25190 Current timestamp / date adjusted to user time zone when cast to varchar [ignite-3]

Posted by "korlov42 (via GitHub)" <gi...@apache.org>.
korlov42 commented on code in PR #5784:
URL: https://github.com/apache/ignite-3/pull/5784#discussion_r2086715367


##########
modules/jdbc/src/integrationTest/java/org/apache/ignite/jdbc/ItJdbcClientTimeZoneTest.java:
##########
@@ -176,25 +180,98 @@ public void dynamicParamRespectsTimeZone() throws SQLException {
                     // Client time zone is "GMT".

Review Comment:
   considering the very first lines of this method, "session" time zone refers to time zone of the connection, while "client" tz refers to time zone of the JVM. Let's change all comments accordingly, because after your changes they are no longer correct in certain places.



##########
modules/jdbc/src/integrationTest/java/org/apache/ignite/jdbc/ItJdbcClientTimeZoneTest.java:
##########
@@ -176,25 +180,98 @@ public void dynamicParamRespectsTimeZone() throws SQLException {
                     // Client time zone is "GMT".
                     {
                         assertEquals(timestamp("1970-01-01T00:00:00"), rs.getTimestamp(1));
-                        // Since client time zone is GMT, timestamp will contain original UTC value from store.
+                        assertEquals(LocalTime.of(0, 0, 0), rs.getTime(1).toLocalTime());
+                        assertEquals(LocalDate.of(1970, 1, 1), rs.getDate(1).toLocalDate());
+
                         assertEquals(timestamp("1969-12-31T23:00:00"), rs.getTimestamp(2));
+                        assertEquals(LocalTime.of(23, 0, 0), rs.getTime(2).toLocalTime());
+                        assertEquals(LocalDate.of(1969, 12, 31), rs.getDate(2).toLocalDate());
                     }
+                }
+            }
+        }
+
+        TimeZone.setDefault(TimeZone.getTimeZone("GMT+1"));
+
+        try (Connection conn = DriverManager.getConnection(URL)) {
+            try (Statement stmt = conn.createStatement()) {
+                try (ResultSet rs = stmt.executeQuery("SELECT ts, ts_tz FROM test where id=1")) {
+                    assertTrue(rs.next());
 
                     // Session and client time zone are same ("GMT+1").
                     {
-                        TimeZone.setDefault(TimeZone.getTimeZone("GMT+1"));
+                        assertEquals(timestamp("1970-01-01T00:00:00"), rs.getTimestamp(1));
+                        assertEquals(LocalTime.of(0, 0, 0), rs.getTime(1).toLocalTime());
+                        assertEquals(LocalDate.of(1970, 1, 1), rs.getDate(1).toLocalDate());
 
+                        assertEquals(timestamp("1970-01-01T00:00:00"), rs.getTimestamp(2));
+                        assertEquals(LocalTime.of(0, 0, 0), rs.getTime(2).toLocalTime());
+                        assertEquals(LocalDate.of(1970, 1, 1), rs.getDate(2).toLocalDate());
+                    }
+                }
+            }
+        }
+
+        TimeZone.setDefault(TimeZone.getTimeZone(origin));
+
+        try (Connection conn = DriverManager.getConnection(URL + "?connectionTimeZone=GMT+1")) {
+            try (Statement stmt = conn.createStatement()) {
+                try (ResultSet rs = stmt.executeQuery("SELECT ts, ts_tz FROM test where id=1")) {
+                    assertTrue(rs.next());
+
+                    // Session and client time zone are same ("GMT+1").

Review Comment:
   you've changed time zone of the JVM to "origin", which is differs from environment to environment. It's better to avoid tests whose results may be affected by environment



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@ignite.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] IGNITE-25190 Current timestamp / date adjusted to user time zone when cast to varchar [ignite-3]

Posted by "korlov42 (via GitHub)" <gi...@apache.org>.
korlov42 merged PR #5784:
URL: https://github.com/apache/ignite-3/pull/5784


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@ignite.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] IGNITE-25190 Current timestamp / date adjusted to user time zone when cast to varchar [ignite-3]

Posted by "ygerzhedovich (via GitHub)" <gi...@apache.org>.
ygerzhedovich commented on code in PR #5784:
URL: https://github.com/apache/ignite-3/pull/5784#discussion_r2079672237


##########
modules/jdbc/src/main/java/org/apache/ignite/internal/jdbc/JdbcResultSet.java:
##########
@@ -385,9 +387,14 @@ public boolean wasNull() throws SQLException {
     /** {@inheritDoc} */
     @Override
     public String getString(int colIdx) throws SQLException {
-        Object val = getValue(colIdx);
-
-        return val == null ? null : String.valueOf(val);
+        Object val = getJdbcValue(colIdx);
+        if (val == null) {
+            return null;
+        } else if (val instanceof byte[]) {
+            return StringUtils.toHexString((byte[]) val);

Review Comment:
   I think will be better to have some limit on generated string here



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@ignite.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] IGNITE-25190 Current timestamp / date adjusted to user time zone when cast to varchar [ignite-3]

Posted by "lowka (via GitHub)" <gi...@apache.org>.
lowka commented on code in PR #5784:
URL: https://github.com/apache/ignite-3/pull/5784#discussion_r2086725786


##########
modules/jdbc/src/integrationTest/java/org/apache/ignite/jdbc/ItJdbcClientTimeZoneTest.java:
##########
@@ -176,25 +180,98 @@ public void dynamicParamRespectsTimeZone() throws SQLException {
                     // Client time zone is "GMT".
                     {
                         assertEquals(timestamp("1970-01-01T00:00:00"), rs.getTimestamp(1));
-                        // Since client time zone is GMT, timestamp will contain original UTC value from store.
+                        assertEquals(LocalTime.of(0, 0, 0), rs.getTime(1).toLocalTime());
+                        assertEquals(LocalDate.of(1970, 1, 1), rs.getDate(1).toLocalDate());
+
                         assertEquals(timestamp("1969-12-31T23:00:00"), rs.getTimestamp(2));
+                        assertEquals(LocalTime.of(23, 0, 0), rs.getTime(2).toLocalTime());
+                        assertEquals(LocalDate.of(1969, 12, 31), rs.getDate(2).toLocalDate());
                     }
+                }
+            }
+        }
+
+        TimeZone.setDefault(TimeZone.getTimeZone("GMT+1"));
+
+        try (Connection conn = DriverManager.getConnection(URL)) {
+            try (Statement stmt = conn.createStatement()) {
+                try (ResultSet rs = stmt.executeQuery("SELECT ts, ts_tz FROM test where id=1")) {
+                    assertTrue(rs.next());
 
                     // Session and client time zone are same ("GMT+1").
                     {
-                        TimeZone.setDefault(TimeZone.getTimeZone("GMT+1"));
+                        assertEquals(timestamp("1970-01-01T00:00:00"), rs.getTimestamp(1));
+                        assertEquals(LocalTime.of(0, 0, 0), rs.getTime(1).toLocalTime());
+                        assertEquals(LocalDate.of(1970, 1, 1), rs.getDate(1).toLocalDate());
 
+                        assertEquals(timestamp("1970-01-01T00:00:00"), rs.getTimestamp(2));
+                        assertEquals(LocalTime.of(0, 0, 0), rs.getTime(2).toLocalTime());
+                        assertEquals(LocalDate.of(1970, 1, 1), rs.getDate(2).toLocalDate());
+                    }
+                }
+            }
+        }
+
+        TimeZone.setDefault(TimeZone.getTimeZone(origin));
+
+        try (Connection conn = DriverManager.getConnection(URL + "?connectionTimeZone=GMT+1")) {
+            try (Statement stmt = conn.createStatement()) {
+                try (ResultSet rs = stmt.executeQuery("SELECT ts, ts_tz FROM test where id=1")) {
+                    assertTrue(rs.next());
+
+                    // Session and client time zone are same ("GMT+1").

Review Comment:
   These tests restore default timezone after each run.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@ignite.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org