Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SNOW-1714049: getTime losing nanosecond values from 3.13.31 #1908

Closed
akanimesh7 opened this issue Oct 4, 2024 · 3 comments
Closed

SNOW-1714049: getTime losing nanosecond values from 3.13.31 #1908

akanimesh7 opened this issue Oct 4, 2024 · 3 comments
Assignees
Labels
invalid status-triage_done Initial triage done, will be further handled by the driver team

Comments

@akanimesh7
Copy link

akanimesh7 commented Oct 4, 2024

Please answer these questions before submitting your issue.
In order to accurately debug the issue this information is required. Thanks!

  1. What version of JDBC driver are you using?

3.13.30 and 3.13.31

  1. What operating system and processor architecture are you using?
    macOS, arm64

  2. What version of Java are you using?
    openjdk version "17.0.5" 2022-10-18

  3. What did you do?

   Connection conn = getConnection();
    Statement stmt = conn.createStatement();
    stmt.executeQuery("ALTER SESSION SET JDBC_QUERY_RESULT_FORMAT='JSON'");
    stmt.executeQuery("CREATE OR REPLACE TABLE TEST_TIME(TIME_COL TIME)");
    stmt.executeQuery("INSERT INTO TEST_TIME VALUES ('12:34:56.123456789')");
    ResultSet rs = stmt.executeQuery("SELECT * FROM TEST_TIME");
    ResultSetMetaData rsmd = rs.getMetaData();
    System.out.println(rsmd.getColumnClassName(1));
    while (rs.next()) {
      System.out.println(rs.getObject(1).getClass());
      System.out.println(((SnowflakeTimeWithTimezone)rs.getObject(1)).getNano());
      System.out.println(rs.getTime(1));
    }
    rs.close();
    stmt.close();
    conn.close();
  1. What did you expect to see?

In 3.13.0, this returns

java.sql.Time
class net.snowflake.client.jdbc.SnowflakeTimeWithTimezone
123456789
12:34:56

While in 3.13.1
This returns

java.sql.Time
class java.sql.Time
Exception in thread "main" java.lang.ClassCastException: class java.sql.Time cannot be cast to class net.snowflake.client.jdbc.SnowflakeTimeWithTimezone (java.sql.Time is in module java.sql of loader 'platform'; net.snowflake.client.jdbc.SnowflakeTimeWithTimezone is in unnamed module of loader 'app')
	at io.animesh.snowflake.SnowflakeExample.issueCode(SnowflakeExample.java:43)
	at io.animesh.snowflake.SnowflakeExample.main(SnowflakeExample.java:29)

What this means is now instead of SnowflakeTimeWithTimezone which contained info about nanos, java.sql.Time is being used, which on the other hand only stores upto seconds granularity.

The reason for this seems to be this PR -- #1383

@akanimesh7 akanimesh7 added the bug label Oct 4, 2024
@github-actions github-actions bot changed the title getTime losing nanosecond values from 3.13.31 SNOW-1714049: getTime losing nanosecond values from 3.13.31 Oct 4, 2024
@sfc-gh-wfateem sfc-gh-wfateem self-assigned this Oct 4, 2024
@sfc-gh-wfateem sfc-gh-wfateem added the status-triage Issue is under initial triage label Oct 4, 2024
@akanimesh7
Copy link
Author

@sfc-gh-wfateem Any updates on this ?

@sfc-gh-wfateem sfc-gh-wfateem added invalid status-triage_done Initial triage done, will be further handled by the driver team and removed status-triage Issue is under initial triage bug labels Dec 16, 2024
@sfc-gh-wfateem
Copy link
Collaborator

@akanimesh7 sorry for the delay in getting back to you on this.

Yes, there was a change, but that's on purpose to address a different issue, and the new behavior you're seeing is the expected outcome. The getTime() method is supposed to strictly return a data type of java.sql.Time which is why the getObject() is returning what you're seeing given that the column in Snowflake is of type TIME. As you pointed out, java.sql.Time doesn't store nanoseconds, so if you need to preserve nanoseconds then you should use getTimestamp() instead. That will return java.sql.Timestamp which has nanoseconds precision.

@sfc-gh-wfateem
Copy link
Collaborator

@akanimesh7 in addition to the information I provided, I think what you might be interested in is the following:
#1494

I'll go ahead and close this off, but please feel free to open this again if you still have any questions.

@sfc-gh-wfateem sfc-gh-wfateem closed this as not planned Won't fix, can't repro, duplicate, stale Dec 17, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
invalid status-triage_done Initial triage done, will be further handled by the driver team
Projects
None yet
Development

No branches or pull requests

2 participants