diff --git hcatalog-pig-adapter/src/main/java/org/apache/hcatalog/pig/PigHCatUtil.java hcatalog-pig-adapter/src/main/java/org/apache/hcatalog/pig/PigHCatUtil.java index 2a5ec2a..817866f 100644 --- hcatalog-pig-adapter/src/main/java/org/apache/hcatalog/pig/PigHCatUtil.java +++ hcatalog-pig-adapter/src/main/java/org/apache/hcatalog/pig/PigHCatUtil.java @@ -363,7 +363,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; @@ -372,7 +372,7 @@ public class PigHCatUtil { return result; } - public static Tuple transformToTuple(List objList, HCatFieldSchema hfs) throws Exception { + private static Tuple transformToTuple(List objList, HCatFieldSchema hfs) throws Exception { try { return transformToTuple(objList, hfs.getStructSubSchema()); } catch (Exception e) { @@ -384,7 +384,7 @@ public class PigHCatUtil { } } - public static Tuple transformToTuple(List objList, HCatSchema hs) throws Exception { + private static Tuple transformToTuple(List objList, HCatSchema hs) throws Exception { if (objList == null) { return null; } @@ -396,20 +396,21 @@ public class PigHCatUtil { return t; } - public static Map transformToPigMap(Map map, HCatFieldSchema hfs) throws Exception { + private 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; } @SuppressWarnings("unchecked") - public static DataBag transformToBag(List list, HCatFieldSchema hfs) throws Exception { + private static DataBag transformToBag(List list, HCatFieldSchema hfs) throws Exception { if (list == null) { return null; } @@ -454,6 +455,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; }