diff --git common/src/java/org/apache/hadoop/hive/conf/HiveConf.java common/src/java/org/apache/hadoop/hive/conf/HiveConf.java index ce5ec43..791628c 100644 --- common/src/java/org/apache/hadoop/hive/conf/HiveConf.java +++ common/src/java/org/apache/hadoop/hive/conf/HiveConf.java @@ -703,6 +703,10 @@ private static void populateLlapDaemonVarsSet(Set llapDaemonVarsSetLocal "Setting it to true will break compatibility with older clients running TBinaryProtocol."), METASTORE_TOKEN_SIGNATURE("hive.metastore.token.signature", "", "The delegation token service name to match when selecting a token from the current user's tokens."), + METASTORE_MAX_TYPENAME_LENGTH("hive.metastore.max.typename.length", 2000, + "Max length allowed in metastore type name, as number of unicode characters. Setting it " + + "to a value higher than the backend DB supports will result either in DB errors or the " + + "values being silently truncated"), METASTORE_CLUSTER_DELEGATION_TOKEN_STORE_CLS("hive.cluster.delegation.token.store.class", "org.apache.hadoop.hive.thrift.MemoryTokenStore", "The delegation token store implementation. Set to org.apache.hadoop.hive.thrift.ZooKeeperTokenStore for load-balanced cluster."), diff --git metastore/src/java/org/apache/hadoop/hive/metastore/HiveAlterHandler.java metastore/src/java/org/apache/hadoop/hive/metastore/HiveAlterHandler.java index b52ab2c..63ae32a 100644 --- metastore/src/java/org/apache/hadoop/hive/metastore/HiveAlterHandler.java +++ metastore/src/java/org/apache/hadoop/hive/metastore/HiveAlterHandler.java @@ -99,7 +99,7 @@ public void alterTable(RawStore msdb, Warehouse wh, String dbname, throw new InvalidOperationException(newt.getTableName() + " is not a valid object name"); } - String validate = MetaStoreUtils.validateTblColumns(newt.getSd().getCols()); + String validate = MetaStoreUtils.validateTblColumns(newt.getSd().getCols(), hiveConf); if (validate != null) { throw new InvalidOperationException("Invalid column " + validate); } diff --git metastore/src/java/org/apache/hadoop/hive/metastore/HiveMetaStore.java metastore/src/java/org/apache/hadoop/hive/metastore/HiveMetaStore.java index e0274d8..bf7b8da 100644 --- metastore/src/java/org/apache/hadoop/hive/metastore/HiveMetaStore.java +++ metastore/src/java/org/apache/hadoop/hive/metastore/HiveMetaStore.java @@ -1359,12 +1359,12 @@ private void create_table_core(final RawStore ms, final Table tbl, throw new InvalidObjectException(tbl.getTableName() + " is not a valid object name"); } - String validate = MetaStoreUtils.validateTblColumns(tbl.getSd().getCols()); + String validate = MetaStoreUtils.validateTblColumns(tbl.getSd().getCols(), hiveConf); if (validate != null) { throw new InvalidObjectException("Invalid column " + validate); } if (tbl.getPartitionKeys() != null) { - validate = MetaStoreUtils.validateTblColumns(tbl.getPartitionKeys()); + validate = MetaStoreUtils.validateTblColumns(tbl.getPartitionKeys(), hiveConf); if (validate != null) { throw new InvalidObjectException("Invalid partition column " + validate); } diff --git metastore/src/java/org/apache/hadoop/hive/metastore/MetaStoreUtils.java metastore/src/java/org/apache/hadoop/hive/metastore/MetaStoreUtils.java index f632542..6c2fc47 100644 --- metastore/src/java/org/apache/hadoop/hive/metastore/MetaStoreUtils.java +++ metastore/src/java/org/apache/hadoop/hive/metastore/MetaStoreUtils.java @@ -584,12 +584,12 @@ public static final boolean validateColumnName(String name) { return true; } - static public String validateTblColumns(List cols) { + static public String validateTblColumns(List cols, Configuration conf) { for (FieldSchema fieldSchema : cols) { if (!validateColumnName(fieldSchema.getName())) { return "name: " + fieldSchema.getName(); } - String typeError = validateColumnType(fieldSchema.getType()); + String typeError = validateColumnType(fieldSchema.getType(), conf); if (typeError != null) { return typeError; } @@ -660,7 +660,6 @@ static private boolean areColTypesCompatible(String oldType, String newType) { TypeInfoUtils.getTypeInfoFromTypeString(newType)); } - public static final int MAX_MS_TYPENAME_LENGTH = 2000; // 4000/2, for an unlikely unicode case public static final String TYPE_FROM_DESERIALIZER = ""; /** @@ -670,10 +669,12 @@ static private boolean areColTypesCompatible(String oldType, String newType) { * @param name * @return */ - static public String validateColumnType(String type) { + static public String validateColumnType(String type, Configuration conf) { if (type.equals(TYPE_FROM_DESERIALIZER)) return null; - if (type.length() > MAX_MS_TYPENAME_LENGTH) { - return "type name is too long: " + type; + int maxLen = HiveConf.getIntVar(conf, HiveConf.ConfVars.METASTORE_MAX_TYPENAME_LENGTH); + if (type.length() > maxLen) { + return "type name length " + type.length() + " exceeds max allowed length " + maxLen + + ", type " + type; } int last = 0; boolean lastAlphaDigit = isValidTypeChar(type.charAt(last));