Uploaded image for project: 'Phoenix'
  1. Phoenix
  2. PHOENIX-618

Support negative DATE and TIME values

    Details

    • Type: Task
    • Status: Resolved
    • Resolution: Fixed
    • Affects Version/s: 3.0-Release
    • Fix Version/s: None
    • Labels:
    • old issue number:
      487

      Description

      I think there is some general problem with date/time/timestamp datatypes and IllegalDataException, but I manage reliably reproduce only this one.

      Try:
      1. PreparedStatement.setDate("DATE_COLUMN", new java.sql.Date(Long.MIN_VALUE));
      2. ResultSet.getDate("DATE_COLUMN")

      Works fine for TIMESTAMP and TIME, but not for DATE:

      ```
      com.salesforce.phoenix.schema.IllegalDataException
      at com.salesforce.phoenix.schema.PDataType$UnsignedLongCodec.decodeLong(PDataType.java:3836)
      at com.salesforce.phoenix.schema.PDataType$12.toObject(PDataType.java:1794)
      at com.salesforce.phoenix.schema.PDataType.toObject(PDataType.java:4585)
      at com.salesforce.phoenix.schema.PDataType.toObject(PDataType.java:4564)
      at com.salesforce.phoenix.schema.PDataType.toObject(PDataType.java:4573)
      at com.salesforce.phoenix.compile.ExpressionProjector.getValue(ExpressionProjector.java:85)
      at com.salesforce.phoenix.jdbc.PhoenixResultSet.getDate(PhoenixResultSet.java:332)
      at com.salesforce.phoenix.jdbc.DateColumnTest.test(DateColumnTest.java:41)

      ```

      ```java
      package com.salesforce.phoenix.jdbc;

      import java.sql.Connection;
      import java.sql.DriverManager;
      import java.sql.PreparedStatement;
      import java.sql.ResultSet;
      import java.sql.SQLException;
      import java.sql.Statement;

      import org.junit.Test;

      public class DateColumnTest {

      @Test
      public void test() throws SQLException {
      Connection con = null;
      try

      { con = DriverManager.getConnection("jdbc:phoenix:cloudera:2181"); con.setAutoCommit(true); Statement stm = con.createStatement(); stm.execute("DROP TABLE IF EXISTS test.date"); stm.execute("CREATE TABLE test.date(id BIGINT NOT NULL PRIMARY KEY, t DATE NOT NULL)"); stm.execute("DELETE FROM test.date"); stm.close(); long id = 1; PreparedStatement psInsert = con .prepareStatement("UPSERT INTO test.date VALUES(?,?)"); psInsert.setLong(1, id); psInsert.setDate(2, new java.sql.Date(Long.MIN_VALUE)); psInsert.execute(); psInsert.close(); PreparedStatement psSelect = con .prepareStatement("SELECT * FROM test.date WHERE id=?"); psSelect.setLong(1, id); ResultSet rs = psSelect.executeQuery(); rs.next(); rs.getLong(1); rs.getDate(2); rs.close(); psSelect.close(); }

      finally {
      try

      { con.close(); }

      catch (Exception ex) {
      }
      }
      }

      }

      ```

        Attachments

          Activity

            People

            • Assignee:
              Unassigned
              Reporter:
              adenysenko Artur Denysenko
            • Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: