出现问题
DataX向hive同步数据时Date类型和TimeStamp类型显示ORC does not support type conversion from file type struct<> (2) to reader type date (2)
问题来源
DataX向hive中写入数据时,Date数据类型和TimeStamp数据类型使用java.sql.Timestamp.class和java.sql.Date.class
解决方法
将java.sql.Timestamp.class和java.sql.Date.class类型修改为org.apache.hadoop.hive.common.type.Timestamp.class和org.apache.hadoop.hive.common.type.Date.class类型
在/DataX/hdfswriter/src/main/java/com/alibaba/datax/plugin/writer/hdfswriter/HdfsHelper.java文件的getColumnTypeInspectors()方法中修改
case TIMESTAMP:
objectInspector = //ObjectInspectorFactory.getReflectionObjectInspector(java.sql.Timestamp.class, ObjectInspectorFactory.ObjectInspectorOptions.JAVA);
ObjectInspectorFactory.getReflectionObjectInspector(org.apache.hadoop.hive.common.type.Timestamp.class,ObjectInspectorFactory.ObjectInspectorOptions.JAVA)
break;
case DATE:
objectInspector = ObjectInspectorFactory.getReflectionObjectInspector(org.apache.hadoop.hive.common.type.Date.class, ObjectInspectorFactory.ObjectInspectorOptions.JAVA);
break;
在/DataX/hdfswriter/src/main/java/com/alibaba/datax/plugin/writer/hdfswriter/HdfsHelper.java文件的transportOneRecord()方法中修改
case DATE:
// recordList.add(new java.sql.Date(column.asDate().getTime()));
recordList.add(org.apache.hadoop.hive.common.type.Date.ofEpochMilli(column.asDate().getTime()));
break;
case TIMESTAMP:
// recordList.add(new java.sql.Timestamp(column.asDate().getTime()));
recordList.add(org.apache.hadoop.hive.common.type.Timestamp.ofEpochMilli(column.asDate().getTime()));
break;