diff --git hcatalog/core/src/main/java/org/apache/hive/hcatalog/data/schema/HCatSchema.java hcatalog/core/src/main/java/org/apache/hive/hcatalog/data/schema/HCatSchema.java index 59e18b4..c6dcd9a 100644 --- hcatalog/core/src/main/java/org/apache/hive/hcatalog/data/schema/HCatSchema.java +++ hcatalog/core/src/main/java/org/apache/hive/hcatalog/data/schema/HCatSchema.java @@ -58,7 +58,7 @@ public HCatSchema(final List fieldSchemas) { if (field == null) throw new IllegalArgumentException("Field cannot be null"); - String fieldName = field.getName(); + String fieldName = normalizeName(field.getName()); if (fieldPositionMap.containsKey(fieldName)) throw new IllegalArgumentException("Field named " + fieldName + " already exists"); @@ -72,7 +72,7 @@ public void append(final HCatFieldSchema hfs) throws HCatException { if (hfs == null) throw new HCatException("Attempt to append null HCatFieldSchema in HCatSchema."); - String fieldName = hfs.getName(); + String fieldName = normalizeName(hfs.getName()); if (fieldPositionMap.containsKey(fieldName)) throw new HCatException("Attempt to append HCatFieldSchema with already " + "existing name: " + fieldName + "."); @@ -98,7 +98,7 @@ public void append(final HCatFieldSchema hfs) throws HCatException { * present, returns null. */ public Integer getPosition(String fieldName) { - return fieldPositionMap.get(fieldName); + return fieldPositionMap.get(normalizeName(fieldName)); } public HCatFieldSchema get(String fieldName) throws HCatException { @@ -134,9 +134,14 @@ public void remove(final HCatFieldSchema hcatFieldSchema) throws HCatException { } fieldSchemas.remove(hcatFieldSchema); // Re-align the positionMap by -1 for the columns appearing after hcatFieldSchema. - reAlignPositionMap(fieldPositionMap.get(hcatFieldSchema.getName())+1, -1); - fieldPositionMap.remove(hcatFieldSchema.getName()); - fieldNames.remove(hcatFieldSchema.getName()); + String fieldName = normalizeName(hcatFieldSchema.getName()); + reAlignPositionMap(fieldPositionMap.get(fieldName)+1, -1); + fieldPositionMap.remove(fieldName); + fieldNames.remove(fieldName); + } + + private String normalizeName(String name) { + return name == null ? null : name.toLowerCase(); } @Override diff --git hcatalog/core/src/test/java/org/apache/hive/hcatalog/data/TestJsonSerDe.java hcatalog/core/src/test/java/org/apache/hive/hcatalog/data/TestJsonSerDe.java index da5ae97..b4a810a 100644 --- hcatalog/core/src/test/java/org/apache/hive/hcatalog/data/TestJsonSerDe.java +++ hcatalog/core/src/test/java/org/apache/hive/hcatalog/data/TestJsonSerDe.java @@ -22,6 +22,7 @@ import java.sql.Date; import java.sql.Timestamp; import java.util.ArrayList; +import java.util.Arrays; import java.util.HashMap; import java.util.List; import java.util.Map; @@ -287,4 +288,23 @@ public void testLooseJsonReadability() throws Exception { } + public void testUpperCaseKey() throws Exception { + Configuration conf = new Configuration(); + Properties props = new Properties(); + + props.put(serdeConstants.LIST_COLUMNS, "empid,name"); + props.put(serdeConstants.LIST_COLUMN_TYPES, "int,string"); + JsonSerDe rjsd = new JsonSerDe(); + SerDeUtils.initializeSerDe(rjsd, conf, props, null); + + Text text1 = new Text("{ \"empId\" : 123, \"name\" : \"John\" } "); + Text text2 = new Text("{ \"empId\" : 456, \"name\" : \"Jane\" } "); + + HCatRecord expected1 = new DefaultHCatRecord(Arrays.asList(123, "John")); + HCatRecord expected2 = new DefaultHCatRecord(Arrays.asList(456, "Jane")); + + assertTrue(HCatDataCheckUtil.recordsEqual((HCatRecord)rjsd.deserialize(text1), expected1)); + assertTrue(HCatDataCheckUtil.recordsEqual((HCatRecord)rjsd.deserialize(text2), expected2)); + + } }