if (colType.equalsIgnoreCase(serdeConstants.STRING_TYPE_NAME)) {
// constant string projection Ex: select "hello" from table
if (oi instanceof ConstantObjectInspector) {
ConstantObjectInspector coi = (ConstantObjectInspector) oi;
// if writable constant is null then return size 0
if (coi.getWritableConstantValue() == null) {
return 0;
}
return coi.getWritableConstantValue().toString().length();
} else if (oi instanceof WritableConstantStringObjectInspector) {
// some UDFs return writable constant strings (fixed width)
// Ex: select upper("hello") from table
WritableConstantStringObjectInspector wcsoi = (WritableConstantStringObjectInspector) oi;
return wcsoi.getWritableConstantValue().toString().length();
} else if (oi instanceof WritableStringObjectInspector) {
// some UDFs may emit strings of variable length. like pattern matching
// UDFs. it's hard to find the length of such UDFs.
// return the variable length from config
return configVarLen;
}
} else if (colType.startsWith(serdeConstants.VARCHAR_TYPE_NAME)) {
// constant varchar projection
if (oi instanceof ConstantObjectInspector) {
ConstantObjectInspector coi = (ConstantObjectInspector) oi;
// if writable constant is null then return size 0
if (coi.getWritableConstantValue() == null) {
return 0;
}
return coi.getWritableConstantValue().toString().length();
} else if (oi instanceof WritableConstantHiveVarcharObjectInspector) {
WritableConstantHiveVarcharObjectInspector wcsoi =
(WritableConstantHiveVarcharObjectInspector) oi;
return wcsoi.getWritableConstantValue().toString().length();
} else if (oi instanceof WritableHiveVarcharObjectInspector) {
return ((WritableHiveVarcharObjectInspector) oi).getMaxLength();
}
} else if (colType.startsWith(serdeConstants.CHAR_TYPE_NAME)) {
// constant char projection
if (oi instanceof ConstantObjectInspector) {
ConstantObjectInspector coi = (ConstantObjectInspector) oi;
// if writable constant is null then return size 0
if (coi.getWritableConstantValue() == null) {
return 0;
}
return coi.getWritableConstantValue().toString().length();
} else if (oi instanceof WritableConstantHiveCharObjectInspector) {
WritableConstantHiveCharObjectInspector wcsoi =
(WritableConstantHiveCharObjectInspector) oi;
return wcsoi.getWritableConstantValue().toString().length();
} else if (oi instanceof WritableHiveCharObjectInspector) {
return ((WritableHiveCharObjectInspector) oi).getMaxLength();
}
} else if (colType.equalsIgnoreCase(serdeConstants.BINARY_TYPE_NAME)) {
// constant byte arrays
if (oi instanceof ConstantObjectInspector) {
ConstantObjectInspector coi = (ConstantObjectInspector) oi;
// if writable constant is null then return size 0
if (coi.getWritableConstantValue() == null) {
return 0;
}
BytesWritable bw = ((BytesWritable) coi.getWritableConstantValue());
return bw.getLength();
} else if (oi instanceof WritableConstantBinaryObjectInspector) {
// writable constant byte arrays
WritableConstantBinaryObjectInspector wcboi = (WritableConstantBinaryObjectInspector) oi;