diff --git a/hcatalog-pig-adapter/src/main/java/org/apache/hcatalog/pig/PigHCatUtil.java b/hcatalog-pig-adapter/src/main/java/org/apache/hcatalog/pig/PigHCatUtil.java index 2407de5..b2cccc7 100644 --- a/hcatalog-pig-adapter/src/main/java/org/apache/hcatalog/pig/PigHCatUtil.java +++ b/hcatalog-pig-adapter/src/main/java/org/apache/hcatalog/pig/PigHCatUtil.java @@ -53,9 +53,13 @@ import org.apache.pig.data.DefaultDataBag; import org.apache.pig.data.Tuple; import org.apache.pig.data.TupleFactory; import org.apache.pig.impl.util.UDFContext; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; public class PigHCatUtil { + private static final Logger LOG = LoggerFactory.getLogger(PigHCatUtil.class); + static final int PIG_EXCEPTION_CODE = 1115; // http://wiki.apache.org/pig/PigErrorHandlingFunctionalSpecification#Error_codes private static final String DEFAULT_DB = MetaStoreUtils.DEFAULT_DATABASE_NAME; @@ -328,7 +332,7 @@ public class PigHCatUtil { result = transformToBag((List) o, hfs); break; case MAP: - result = transformToPigMap((Map) o, hfs); + result = transformToPigMap((Map) o, hfs); break; default: result = o; @@ -361,14 +365,15 @@ public class PigHCatUtil { return t; } - public static Map transformToPigMap(Map map, HCatFieldSchema hfs) throws Exception { + public static Map transformToPigMap(Map map, HCatFieldSchema hfs) throws Exception { if (map == null) { return null; } Map result = new HashMap(); - for (Entry entry : map.entrySet()) { - result.put(entry.getKey(), extractPigObject(entry.getValue(), hfs.getMapValueSchema().get(0))); + for (Entry entry : map.entrySet()) { + // since map key for Pig has to be Strings + result.put(entry.getKey().toString(), extractPigObject(entry.getValue(), hfs.getMapValueSchema().get(0))); } return result; } @@ -415,6 +420,10 @@ public class PigHCatUtil { break; case MAP: // key is only string + if (hcatField.getMapKeyType() != Type.STRING) { + LOG.info("Converting non-String key of map " + hcatField.getName() + " from " + + hcatField.getMapKeyType() + " to String."); + } validateHCatSchemaFollowsPigRules(hcatField.getMapValueSchema()); break; }