Index: hcatalog/core/src/main/java/org/apache/hive/hcatalog/data/HCatRecordSerDe.java =================================================================== --- hcatalog/core/src/main/java/org/apache/hive/hcatalog/data/HCatRecordSerDe.java (revision 1632447) +++ hcatalog/core/src/main/java/org/apache/hive/hcatalog/data/HCatRecordSerDe.java (working copy) @@ -23,7 +23,7 @@ import java.util.List; import java.util.Map; import java.util.Properties; -import java.util.TreeMap; +import java.util.HashMap; import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.hive.serde.serdeConstants; @@ -212,7 +212,7 @@ private static Map serializeMap(Object f, MapObjectInspector moi) throws SerDeException { ObjectInspector koi = moi.getMapKeyObjectInspector(); ObjectInspector voi = moi.getMapValueObjectInspector(); - Map m = new TreeMap(); + Map m = new HashMap(); Map readMap = moi.getMap(f); if (readMap == null) { Index: hcatalog/hcatalog-pig-adapter/src/main/java/org/apache/hive/hcatalog/pig/PigHCatUtil.java =================================================================== --- hcatalog/hcatalog-pig-adapter/src/main/java/org/apache/hive/hcatalog/pig/PigHCatUtil.java (revision 1632447) +++ hcatalog/hcatalog-pig-adapter/src/main/java/org/apache/hive/hcatalog/pig/PigHCatUtil.java (working copy) @@ -480,7 +480,9 @@ Map result = new HashMap(); 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))); + if (entry.getKey()!=null) { + result.put(entry.getKey().toString(), extractPigObject(entry.getValue(), hfs.getMapValueSchema().get(0))); + } } return result; } Index: hcatalog/hcatalog-pig-adapter/src/test/java/org/apache/hive/hcatalog/pig/TestHCatLoaderComplexSchema.java =================================================================== --- hcatalog/hcatalog-pig-adapter/src/test/java/org/apache/hive/hcatalog/pig/TestHCatLoaderComplexSchema.java (revision 1632447) +++ hcatalog/hcatalog-pig-adapter/src/test/java/org/apache/hive/hcatalog/pig/TestHCatLoaderComplexSchema.java (working copy) @@ -18,8 +18,6 @@ */ package org.apache.hive.hcatalog.pig; -import com.google.common.collect.ImmutableSet; - import java.io.IOException; import java.util.ArrayList; import java.util.Arrays; @@ -52,7 +50,6 @@ import org.apache.pig.impl.logicalLayer.schema.Schema; import org.apache.pig.impl.logicalLayer.schema.Schema.FieldSchema; -import org.junit.Before; import org.junit.BeforeClass; import org.junit.Test; import org.junit.runner.RunWith; @@ -79,11 +76,13 @@ add("testSyntheticComplexSchema"); add("testTupleInBagInTupleInBag"); add("testMapWithComplexData"); + add("testMapNullKey"); }}); put(IOConstants.PARQUETFILE, new HashSet() {{ add("testSyntheticComplexSchema"); add("testTupleInBagInTupleInBag"); add("testMapWithComplexData"); + add("testMapNullKey"); }}); }}; @@ -223,6 +222,10 @@ private void verifyWriteRead(String tablename, String pigSchema, String tableSchema, List data, boolean provideSchemaToStorer) throws IOException, CommandNeedRetryException, ExecException, FrontendException { + verifyWriteRead(tablename, pigSchema, tableSchema, data, data, provideSchemaToStorer); + } + private void verifyWriteRead(String tablename, String pigSchema, String tableSchema, List data, List result, boolean provideSchemaToStorer) + throws IOException, CommandNeedRetryException, ExecException, FrontendException { MockLoader.setData(tablename + "Input", data); try { createTable(tablename, tableSchema); @@ -244,7 +247,7 @@ Iterator it = server.openIterator("X"); int i = 0; while (it.hasNext()) { - Tuple input = data.get(i++); + Tuple input = result.get(i++); Tuple output = it.next(); compareTuples(input, output); LOG.info("tuple : {} ", output); @@ -354,4 +357,40 @@ verifyWriteRead("testMapWithComplexData", pigSchema, tableSchema, data, true); verifyWriteRead("testMapWithComplexData2", pigSchema, tableSchema, data, false); } + + /** + * artificially complex nested schema to test nested schema conversion + * @throws Exception + */ + @Test + public void testMapNullKey() throws Exception { + assumeTrue(!TestUtil.shouldSkip(storageFormat, DISABLED_STORAGE_FORMATS)); + String pigSchema = "m:map[]"; + + String tableSchema = "m map"; + + List data = new ArrayList(); + Tuple t = t( + new HashMap() { + { + put("ac test1", "test 1"); + put("ac test2", "test 2"); + put(null, "test 3"); + }; + }); + data.add(t); + + List result = new ArrayList(); + t = t( + new HashMap() { + { + put("ac test1", "test 1"); + put("ac test2", "test 2"); + }; + }); + result.add(t); + + verifyWriteRead("testSyntheticComplexSchema", pigSchema, tableSchema, data, result, true); + verifyWriteRead("testSyntheticComplexSchema", pigSchema, tableSchema, data, result, false); + } }