Created
June 29, 2012 01:30
-
-
Save electrum/3015145 to your computer and use it in GitHub Desktop.
Hive TypeInfoDumper
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package org.acz.hive.serde; | |
import org.apache.hadoop.hive.serde2.typeinfo.ListTypeInfo; | |
import org.apache.hadoop.hive.serde2.typeinfo.MapTypeInfo; | |
import org.apache.hadoop.hive.serde2.typeinfo.PrimitiveTypeInfo; | |
import org.apache.hadoop.hive.serde2.typeinfo.StructTypeInfo; | |
import org.apache.hadoop.hive.serde2.typeinfo.TypeInfo; | |
import org.apache.hadoop.hive.serde2.typeinfo.UnionTypeInfo; | |
import java.util.List; | |
import static java.lang.String.format; | |
public class TypeInfoDumper | |
{ | |
public static String dump(TypeInfo type) | |
{ | |
switch (type.getCategory()) { | |
case LIST: | |
return dump((ListTypeInfo) type); | |
case MAP: | |
return dump((MapTypeInfo) type); | |
case PRIMITIVE: | |
return dump((PrimitiveTypeInfo) type); | |
case STRUCT: | |
return dump((StructTypeInfo) type); | |
case UNION: | |
return dump((UnionTypeInfo) type); | |
default: | |
throw new AssertionError("unhandled type category: " + type.getCategory()); | |
} | |
} | |
private static String dump(ListTypeInfo type) | |
{ | |
return format("list<%s>", type.getListElementTypeInfo()); | |
} | |
private static String dump(MapTypeInfo type) | |
{ | |
return format("map<%s,%s>", type.getMapKeyTypeInfo(), type.getMapValueTypeInfo()); | |
} | |
private static String dump(PrimitiveTypeInfo type) | |
{ | |
return format("primitive<%s>", type.getPrimitiveCategory().name().toLowerCase()); | |
} | |
private static String dump(StructTypeInfo type) | |
{ | |
return format("struct<%s>", dump(type.getAllStructFieldTypeInfos())); | |
} | |
private static String dump(UnionTypeInfo type) | |
{ | |
return format("union<%s>", dump(type.getAllUnionObjectTypeInfos())); | |
} | |
private static String dump(List<TypeInfo> types) | |
{ | |
StringBuilder sb = new StringBuilder(); | |
for (TypeInfo type : types) { | |
if (sb.length() > 0) { | |
sb.append(","); | |
} | |
sb.append(dump(type)); | |
} | |
return sb.toString(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment