in odps-sqoop/src/java/org/apache/sqoop/mapreduce/hcat/SqoopHCatExportHelper.java [162:252]
private Object convertToSqoop(Object val,
HCatFieldSchema.Type fieldType, String javaColType,
String hCatTypeString) throws IOException {
if (val == null) {
return null;
}
switch (fieldType) {
case INT:
case TINYINT:
case SMALLINT:
case FLOAT:
case DOUBLE:
val = convertNumberTypes(val, javaColType);
if (val != null) {
return val;
}
break;
case BOOLEAN:
val = convertBooleanTypes(val, javaColType);
if (val != null) {
return val;
}
break;
case BIGINT:
if (javaColType.equals(DATE_TYPE)) {
return new Date((Long) val);
} else if (javaColType.equals(TIME_TYPE)) {
return new Time((Long) val);
} else if (javaColType.equals(TIMESTAMP_TYPE)) {
return new Timestamp((Long) val);
} else {
val = convertNumberTypes(val, javaColType);
if (val != null) {
return val;
}
}
break;
case DATE:
Date date = (Date) val;
if (javaColType.equals(DATE_TYPE)) {
return date;
} else if (javaColType.equals(TIME_TYPE)) {
return new Time(date.getTime());
} else if (javaColType.equals(TIMESTAMP_TYPE)) {
return new Timestamp(date.getTime());
}
break;
case TIMESTAMP:
Timestamp ts = (Timestamp) val;
if (javaColType.equals(DATE_TYPE)) {
return new Date(ts.getTime());
} else if (javaColType.equals(TIME_TYPE)) {
return new Time(ts.getTime());
} else if (javaColType.equals(TIMESTAMP_TYPE)) {
return ts;
}
break;
case STRING:
case VARCHAR:
case CHAR:
val = convertStringTypes(val, javaColType);
if (val != null) {
return val;
}
break;
case BINARY:
val = convertBinaryTypes(val, javaColType);
if (val != null) {
return val;
}
break;
case DECIMAL:
val = convertDecimalTypes(val, javaColType);
if (val != null) {
return val;
}
break;
case ARRAY:
case MAP:
case STRUCT:
default:
throw new IOException("Cannot convert HCatalog type "
+ fieldType);
}
LOG.error("Cannot convert HCatalog object of "
+ " type " + hCatTypeString + " to java object type "
+ javaColType);
return null;
}