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