[ 
https://issues.apache.org/jira/browse/PHOENIX-261?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
 ]

Gabriel Reid resolved PHOENIX-261.
----------------------------------

    Resolution: Fixed

Bulk resolve of closed issues imported from GitHub. This status was reached by 
first re-opening all closed imported issues and then resolving them in bulk.

> PDataType.DATE should handle conversions (toObject) for TIME and TIMESTAMP 
> differently
> --------------------------------------------------------------------------------------
>
>                 Key: PHOENIX-261
>                 URL: https://issues.apache.org/jira/browse/PHOENIX-261
>             Project: Phoenix
>          Issue Type: Task
>            Reporter: prashantkommireddi
>
> Currently, PDataType.Date.toObject(Object o, PDataType actualType) defaults 
> conversion of both TIME and TIMESTAMP to java.sql.Time. This causes a problem 
> in the following scanario:
> 1. Convert DATE to TIMESTAMP (results in a Time object)
> 2. Make a call to PhoenixPreparedStatement.setObject(int parameterIndex, 
> Object o, int targetSqlType) with targetSqlType as Timestamp
> This will fail as the PreparedStatement implementation calls toObject on 
> target type (Timestamp) which tries to cast java.sql.Time object created in 
> Step 1 above to java.sql.Date (ClassCastException).
> Instead, DATE to TIME and TIMESTAMP conversions should be handled 
> differently. I made a simple fix which should probably be the behavior?
> public static Object toObject(Object object, PDataType actualType) {
>         if (object == null) {
>             return null;
>         }
>         switch (actualType) {
>         case TIME:
>               return new Time(((Date)object).getTime());
>         case TIMESTAMP:
>             return new Timestamp(((Date)object).getTime());
>         case DATE:
>             return object;
>       default:
>               return super.toObject(object, actualType);
>         }
>     }
> }



--
This message was sent by Atlassian JIRA
(v6.2#6252)

Reply via email to