本文整理汇总了Java中org.apache.hadoop.hive.serde2.objectinspector.ObjectInspector.getTypeName方法的典型用法代码示例。如果您正苦于以下问题:Java ObjectInspector.getTypeName方法的具体用法?Java ObjectInspector.getTypeName怎么用?Java ObjectInspector.getTypeName使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.hadoop.hive.serde2.objectinspector.ObjectInspector
的用法示例。
在下文中一共展示了ObjectInspector.getTypeName方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: isMonarchTypeSupported
import org.apache.hadoop.hive.serde2.objectinspector.ObjectInspector; //导入方法依赖的package包/类
public static boolean isMonarchTypeSupported(final ObjectInspector oi) {
if (ObjectInspector.Category.PRIMITIVE.equals(oi.getCategory())) {
/** handle primitive type definitions like decimal(20,20) or varchar(100) **/
String typeStr = oi.getTypeName();
final int argPos = typeStr.indexOf('(');
if (argPos > 0) {
typeStr = typeStr.substring(0, argPos);
}
return TYPE_HIVE_TO_MONARCH_MAP.containsKey(typeStr);
} else if (oi instanceof ListObjectInspector) {
ListObjectInspector loi = (ListObjectInspector)oi;
return isMonarchTypeSupported(loi.getListElementObjectInspector());
} else if (oi instanceof MapObjectInspector) {
MapObjectInspector moi = (MapObjectInspector)oi;
return isMonarchTypeSupported(moi.getMapKeyObjectInspector()) &&
isMonarchTypeSupported(moi.getMapValueObjectInspector());
} else if (oi instanceof StructObjectInspector) {
return ((StructObjectInspector) oi).getAllStructFieldRefs().stream()
.map(StructField::getFieldObjectInspector)
.allMatch(MonarchPredicateHandler::isMonarchTypeSupported);
} else if (oi instanceof UnionObjectInspector) {
return ((UnionObjectInspector) oi).getObjectInspectors().stream()
.allMatch(MonarchPredicateHandler::isMonarchTypeSupported);
}
return false;
}
示例2: serialize
import org.apache.hadoop.hive.serde2.objectinspector.ObjectInspector; //导入方法依赖的package包/类
@Override
public Writable serialize(Object obj, ObjectInspector objInspector) throws SerDeException {
if (objInspector.getCategory() != ObjectInspector.Category.STRUCT) {
throw new SerDeException(getClass().toString()
+ " can only serialize struct types, but we got: "
+ objInspector.getTypeName());
}
StructObjectInspector soi = (StructObjectInspector) objInspector;
List<? extends StructField> fields = soi.getAllStructFieldRefs();
List<Object> list = soi.getStructFieldsDataAsList(obj);
LazyBinarySerDe.BooleanRef warnedOnceNullMapKey = new LazyBinarySerDe.BooleanRef(false);
serializeStream.reset();
serializedSize = 0;
int streamOffset = 0;
// Serialize each field
for (int i = 0; i < fields.size(); i++) {
// Get the field objectInspector and the field object.
ObjectInspector foi = fields.get(i).getFieldObjectInspector();
Object f = (list == null ? null : list.get(i));
//empty strings are marked by an invalid utf single byte sequence. A valid utf stream cannot
//produce this sequence
if ((f != null) && (foi.getCategory().equals(ObjectInspector.Category.PRIMITIVE))
&& ((PrimitiveObjectInspector) foi).getPrimitiveCategory().equals(
PrimitiveObjectInspector.PrimitiveCategory.STRING)
&& ((StringObjectInspector) foi).getPrimitiveJavaObject(f).length() == 0) {
serializeStream.write(INVALID_UTF__SINGLE_BYTE, 0, 1);
} else {
if (MonarchPredicateHandler.isMonarchTypeSupported(foi)) {
/** wherever possible use our serialization **/
try {
serializeStream.write(objectTypeList.get(i).serialize(convertToJavaObject(foi, f)));
} catch (IOException e) {
logger.error("Failed to serialize Field= {}, Type= {}",
fields.get(i).getFieldName(), foi.getTypeName(), e);
}
} else {
/** for the rest continue to use LazyBinarySerDe as binary/bytes **/
LazyBinarySerDe.serialize(serializeStream, f, foi, true, warnedOnceNullMapKey);
}
}
field[i].set(serializeStream.getData(), streamOffset, serializeStream.getLength() - streamOffset);
streamOffset = serializeStream.getLength();
}
serializedSize = serializeStream.getLength();
lastOperationSerialize = true;
lastOperationDeserialize = false;
return serializeCache;
}