You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@hive.apache.org by "ASF GitHub Bot (Jira)" <ji...@apache.org> on 2020/05/17 19:19:00 UTC

[jira] [Work logged] (HIVE-22368) Hive JDBC Storage Handler: some mysql data type can not be cast to hive data type

     [ https://issues.apache.org/jira/browse/HIVE-22368?focusedWorklogId=434235&page=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-434235 ]

ASF GitHub Bot logged work on HIVE-22368:
-----------------------------------------

                Author: ASF GitHub Bot
            Created on: 17/May/20 19:18
            Start Date: 17/May/20 19:18
    Worklog Time Spent: 10m 
      Work Description: ches commented on a change in pull request #822:
URL: https://github.com/apache/hive/pull/822#discussion_r426294836



##########
File path: serde/src/java/org/apache/hadoop/hive/serde2/objectinspector/primitive/JavaDateObjectInspector.java
##########
@@ -38,7 +38,7 @@ public DateWritableV2 getPrimitiveWritableObject(Object o) {
 
   @Override
   public Date getPrimitiveJavaObject(Object o) {
-    return o == null ? null : (Date) o;
+    return o == null ? null : Date.valueOf(o.toString());

Review comment:
       If this is the correct fix, I believe it's also needed on the `new DateWritableV2((Date) o)` in the method above. I'm having code break there on a write path.




----------------------------------------------------------------
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.

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


Issue Time Tracking
-------------------

    Worklog Id:     (was: 434235)
    Time Spent: 20m  (was: 10m)

> Hive JDBC Storage Handler: some mysql data type can not be cast to hive data type
> ---------------------------------------------------------------------------------
>
>                 Key: HIVE-22368
>                 URL: https://issues.apache.org/jira/browse/HIVE-22368
>             Project: Hive
>          Issue Type: Bug
>    Affects Versions: 3.1.0, 4.0.0, 3.1.1
>            Reporter: zhangbutao
>            Assignee: zhangbutao
>            Priority: Major
>              Labels: pull-request-available
>             Fix For: 4.0.0
>
>         Attachments: HIVE-22368.01.patch
>
>          Time Spent: 20m
>  Remaining Estimate: 0h
>
> Mysql data type(date、timestamp、decimal)can not be cast to hive data type(date、timestamp、decimal)。
> step to repo(take date type for example):
> {code:java}
> //MySQL table:
> create table testdate(id date);
> //Hive table:
> CREATE EXTERNAL TABLE `hive_date`(               
>       id date )    
>     ROW FORMAT SERDE                                   
>       'org.apache.hive.storage.jdbc.JdbcSerDe'         
>     STORED BY                                          
>       'org.apache.hive.storage.jdbc.JdbcStorageHandler'                       
>     TBLPROPERTIES (                                                            
>       'hive.sql.database.type'='MYSQL',                                  
>       'hive.sql.dbcp.password'='hive',             
>       'hive.sql.dbcp.username'='hive',             
>       'hive.sql.jdbc.driver'='com.mysql.jdbc.Driver',  
>       'hive.sql.jdbc.url'='jdbc:mysql://hadoop/test',  
>       'hive.sql.table'='testdate');
> //Hive query:
> select * from hive_date;
> Error: java.io.IOException: org.apache.hadoop.hive.ql.metadata.HiveException: java.lang.ClassCastException: java.sql.Date cannot be cast to org.apache.hadoop.hive.common.type.Date (state=,code=0)
> //Error stack trace
> Caused by: java.lang.ClassCastException: java.sql.Date cannot be cast to org.apache.hadoop.hive.common.type.Date
>         at org.apache.hadoop.hive.serde2.objectinspector.primitive.JavaDateObjectInspector.getPrimitiveJavaObject(JavaDateObjectInspector.java:41) ~[hive-exec-3.1.0-bc3.0.1.jar:3.1.0-bc3.0.1]
>         at org.apache.hadoop.hive.serde2.objectinspector.primitive.JavaDateObjectInspector.getPrimitiveJavaObject(JavaDateObjectInspector.java:27) ~[hive-exec-3.1.0-bc3.0.1.jar:3.1.0-bc3.0.1]
>         at org.apache.hadoop.hive.serde2.objectinspector.ObjectInspectorUtils.copyToStandardObject(ObjectInspectorUtils.java:422) ~[hive-exec-3.1.0-bc3.0.1.jar:3.1.0-bc3.0.1]
>         at org.apache.hadoop.hive.serde2.SerDeUtils.toThriftPayload(SerDeUtils.java:173) ~[hive-exec-3.1.0-bc3.0.1.jar:3.1.0-bc3.0.1]
>         at org.apache.hadoop.hive.serde2.thrift.ThriftFormatter.convert(ThriftFormatter.java:49) ~[hive-exec-3.1.0-bc3.0.1.jar:3.1.0-bc3.0.1]
>         at org.apache.hadoop.hive.ql.exec.ListSinkOperator.process(ListSinkOperator.java:94) ~[hive-exec-3.1.0-bc3.0.1.jar:3.1.0-bc3.0.1]
>         at org.apache.hadoop.hive.ql.exec.Operator.baseForward(Operator.java:995) ~[hive-exec-3.1.0-bc3.0.1.jar:3.1.0-bc3.0.1]
>         at org.apache.hadoop.hive.ql.exec.Operator.forward(Operator.java:941) ~[hive-exec-3.1.0-bc3.0.1.jar:3.1.0-bc3.0.1]
>         at org.apache.hadoop.hive.ql.exec.Operator.forward(Operator.java:928) ~[hive-exec-3.1.0-bc3.0.1.jar:3.1.0-bc3.0.1]
>         at org.apache.hadoop.hive.ql.exec.SelectOperator.process(SelectOperator.java:95) ~[hive-exec-3.1.0-bc3.0.1.jar:3.1.0-bc3.0.1]
>         at org.apache.hadoop.hive.ql.exec.Operator.baseForward(Operator.java:995) ~[hive-exec-3.1.0-bc3.0.1.jar:3.1.0-bc3.0.1]
>         at org.apache.hadoop.hive.ql.exec.Operator.forward(Operator.java:941) ~[hive-exec-3.1.0-bc3.0.1.jar:3.1.0-bc3.0.1]
>         at org.apache.hadoop.hive.ql.exec.TableScanOperator.process(TableScanOperator.java:125) ~[hive-exec-3.1.0-bc3.0.1.jar:3.1.0-bc3.0.1]
>         at org.apache.hadoop.hive.ql.exec.FetchOperator.pushRow(FetchOperator.java:519) ~[hive-exec-3.1.0-bc3.0.1.jar:3.1.0-bc3.0.1]
>         at org.apache.hadoop.hive.ql.exec.FetchOperator.pushRow(FetchOperator.java:511) ~[hive-exec-3.1.0-bc3.0.1.jar:3.1.0-bc3.0.1]
>         at org.apache.hadoop.hive.ql.exec.FetchTask.fetch(FetchTask.java:146) ~[hive-exec-3.1.0-bc3.0.1.jar:3.1.0-bc3.0.1]
>         at org.apache.hadoop.hive.ql.Driver.getResults(Driver.java:2706) ~[hive-exec-3.1.0-bc3.0.1.jar:3.1.0-bc3.0.1]
>         at org.apache.hadoop.hive.ql.reexec.ReExecDriver.getResults(ReExecDriver.java:229) ~[hive-exec-3.1.0-bc3.0.1.jar:3.1.0-bc3.0.1]
>         at org.apache.hive.service.cli.operation.SQLOperation.getNextRowSet(SQLOperation.java:460) ~[hive-service-3.1.0-bc3.0.1.jar:3.1.0-bc3.0.1]
>         ... 25 more
> {code}



--
This message was sent by Atlassian Jira
(v8.3.4#803005)