in odpsreader/src/main/java/com/alibaba/datax/plugin/reader/odpsreader/ReaderProxy.java [561:820]
private Map transOdpsMapToJavaMap(Map odpsMap, MapTypeInfo typeInfo) {
TypeInfo keyType = typeInfo.getKeyTypeInfo();
TypeInfo valueType = typeInfo.getValueTypeInfo();
Map result = new HashMap();
Set<Map.Entry> entrySet = null;
switch (valueType.getOdpsType()) {
case BIGINT:
case DOUBLE:
case BOOLEAN:
case STRING:
case DECIMAL:
case TINYINT:
case SMALLINT:
case INT:
case FLOAT:
case CHAR:
case VARCHAR:
case DATE:
case TIMESTAMP:
switch (keyType.getOdpsType()) {
case DATETIME:
entrySet = odpsMap.entrySet();
for (Map.Entry item : entrySet) {
Object value = item.getValue();
result.put(dateFormat.format((Date)item.getKey()), value == null ? NULL_INDICATOR : value.toString());
}
return result;
case BINARY:
entrySet = odpsMap.entrySet();
for (Map.Entry item : entrySet) {
Object value = item.getValue();
result.put(Base64.encodeBase64(((Binary)item.getKey()).data()),
value == null ? NULL_INDICATOR : value.toString());
}
return result;
default:
entrySet = odpsMap.entrySet();
for (Map.Entry item : entrySet) {
Object value = item.getValue();
result.put(item.getKey(), value == null ? NULL_INDICATOR : value.toString());
}
return result;
}
/**
* 日期类型
*/
case DATETIME:
switch (keyType.getOdpsType()) {
case DATETIME:
entrySet = odpsMap.entrySet();
for (Map.Entry item : entrySet) {
Date dateVal = (Date) item.getValue();
result.put(dateFormat.format((Date)item.getKey()),
dateVal == null ? NULL_INDICATOR : dateFormat.format(dateVal));
}
return result;
case BINARY:
entrySet = odpsMap.entrySet();
for (Map.Entry item : entrySet) {
Date dateVal = (Date) item.getValue();
result.put(Base64.encodeBase64(((Binary)item.getKey()).data()),
dateVal == null ? NULL_INDICATOR : dateFormat.format(dateVal));
}
return result;
default:
entrySet = odpsMap.entrySet();
for (Map.Entry item : entrySet) {
Date dateVal = (Date) item.getValue();
result.put(item.getKey(), dateVal == null ? NULL_INDICATOR : dateFormat.format(dateVal));
}
return result;
}
/**
* 字节数组
*/
case BINARY:
switch (keyType.getOdpsType()) {
case DATETIME:
entrySet = odpsMap.entrySet();
for (Map.Entry item : entrySet) {
Binary binaryVal = (Binary) item.getValue();
result.put(dateFormat.format((Date)item.getKey()), binaryVal == null ? NULL_INDICATOR :
Base64.encodeBase64(binaryVal.data()));
}
return result;
case BINARY:
entrySet = odpsMap.entrySet();
for (Map.Entry item : entrySet) {
Binary binaryVal = (Binary) item.getValue();
result.put(Base64.encodeBase64(((Binary)item.getKey()).data()),
binaryVal == null ? NULL_INDICATOR :
Base64.encodeBase64(binaryVal.data()));
}
return result;
default:
entrySet = odpsMap.entrySet();
for (Map.Entry item : entrySet) {
Binary binaryVal = (Binary) item.getValue();
result.put(item.getKey(), binaryVal == null ? NULL_INDICATOR :
Base64.encodeBase64(binaryVal.data()));
}
return result;
}
/**
* 日期间隔
*/
case INTERVAL_DAY_TIME:
switch (keyType.getOdpsType()) {
case DATETIME:
entrySet = odpsMap.entrySet();
for (Map.Entry item : entrySet) {
IntervalDayTime dayTimeVal = (IntervalDayTime) item.getValue();
result.put(dateFormat.format((Date)item.getKey()), dayTimeVal == null ? NULL_INDICATOR :
transIntervalDayTimeToJavaMap(dayTimeVal));
}
return result;
case BINARY:
entrySet = odpsMap.entrySet();
for (Map.Entry item : entrySet) {
IntervalDayTime dayTimeVal = (IntervalDayTime) item.getValue();
result.put(Base64.encodeBase64(((Binary)item.getKey()).data()),
dayTimeVal == null ? NULL_INDICATOR :
transIntervalDayTimeToJavaMap(dayTimeVal));
}
return result;
default:
entrySet = odpsMap.entrySet();
for (Map.Entry item : entrySet) {
IntervalDayTime dayTimeVal = (IntervalDayTime) item.getValue();
result.put(item.getKey(), dayTimeVal == null ? NULL_INDICATOR :
transIntervalDayTimeToJavaMap(dayTimeVal));
}
return result;
}
/**
* 年份间隔
*/
case INTERVAL_YEAR_MONTH:
switch (keyType.getOdpsType()) {
case DATETIME:
entrySet = odpsMap.entrySet();
for (Map.Entry item : entrySet) {
IntervalYearMonth yearMonthVal = (IntervalYearMonth) item.getValue();
result.put(dateFormat.format((Date)item.getKey()), yearMonthVal == null ? NULL_INDICATOR :
transIntervalYearMonthToJavaMap(yearMonthVal));
}
return result;
case BINARY:
entrySet = odpsMap.entrySet();
for (Map.Entry item : entrySet) {
IntervalYearMonth yearMonthVal = (IntervalYearMonth) item.getValue();
result.put(Base64.encodeBase64(((Binary)item.getKey()).data()),
yearMonthVal == null ? NULL_INDICATOR :
transIntervalYearMonthToJavaMap(yearMonthVal));
}
return result;
default:
entrySet = odpsMap.entrySet();
for (Map.Entry item : entrySet) {
IntervalYearMonth yearMonthVal = (IntervalYearMonth) item.getValue();
result.put(item.getKey(), yearMonthVal == null ? NULL_INDICATOR :
transIntervalYearMonthToJavaMap(yearMonthVal));
}
return result;
}
/**
* 结构体
*/
case STRUCT:
switch (keyType.getOdpsType()) {
case DATETIME:
entrySet = odpsMap.entrySet();
for (Map.Entry item : entrySet) {
Struct structVal = (Struct) item.getValue();
result.put(dateFormat.format((Date)item.getKey()), structVal == null ? NULL_INDICATOR :
transOdpsStructToJavaMap(structVal));
}
return result;
case BINARY:
entrySet = odpsMap.entrySet();
for (Map.Entry item : entrySet) {
Struct structVal = (Struct) item.getValue();
result.put(Base64.encodeBase64(((Binary)item.getKey()).data()),
structVal == null ? NULL_INDICATOR :
transOdpsStructToJavaMap(structVal));
}
return result;
default:
entrySet = odpsMap.entrySet();
for (Map.Entry item : entrySet) {
Struct structVal = (Struct) item.getValue();
result.put(item.getKey(), structVal == null ? NULL_INDICATOR :
transOdpsStructToJavaMap(structVal));
}
return result;
}
/**
* MAP类型
*/
case MAP:
switch (keyType.getOdpsType()) {
case DATETIME:
entrySet = odpsMap.entrySet();
for (Map.Entry item : entrySet) {
Map mapVal = (Map) item.getValue();
result.put(dateFormat.format((Date)item.getKey()),mapVal == null ? NULL_INDICATOR :
transOdpsMapToJavaMap(mapVal, (MapTypeInfo) valueType));
}
return result;
case BINARY:
entrySet = odpsMap.entrySet();
for (Map.Entry item : entrySet) {
Map mapVal = (Map) item.getValue();
result.put(Base64.encodeBase64(((Binary)item.getKey()).data()),
mapVal == null ? NULL_INDICATOR : transOdpsMapToJavaMap(mapVal, (MapTypeInfo) valueType));
}
return result;
default:
entrySet = odpsMap.entrySet();
for (Map.Entry item : entrySet) {
Map mapVal = (Map) item.getValue();
result.put(item.getKey(), mapVal == null ? NULL_INDICATOR :
transOdpsMapToJavaMap(mapVal, (MapTypeInfo) valueType));
}
return result;
}
/**
* ARRAY类型
*/
case ARRAY:
switch (keyType.getOdpsType()) {
case DATETIME:
entrySet = odpsMap.entrySet();
for (Map.Entry item : entrySet) {
List arrayVal = (List) item.getValue();
result.put(dateFormat.format((Date)item.getKey()),arrayVal == null ? NULL_INDICATOR :
transOdpsArrayToJavaList(arrayVal, (ArrayTypeInfo) valueType));
}
return result;
case BINARY:
entrySet = odpsMap.entrySet();
for (Map.Entry item : entrySet) {
List arrayVal = (List) item.getValue();
result.put(Base64.encodeBase64(((Binary)item.getKey()).data()),
arrayVal == null ? NULL_INDICATOR : transOdpsArrayToJavaList(arrayVal, (ArrayTypeInfo) valueType));
}
return result;
default:
entrySet = odpsMap.entrySet();
for (Map.Entry item : entrySet) {
List arrayVal = (List) item.getValue();
result.put(item.getKey(), arrayVal == null ? NULL_INDICATOR :
transOdpsArrayToJavaList(arrayVal, (ArrayTypeInfo) valueType));
}
return result;
}
default:
throw new IllegalArgumentException("decode record failed. column type: " + valueType.getTypeName());
}
}