in emr-dynamodb-hive/src/main/java/org/apache/hadoop/hive/dynamodb/DynamoDBStorageHandler.java [312:365]
void checkTableSchemaType(TableDescription tableDescription, Table table) throws
MetaException {
List<FieldSchema> tableSchema = table.getSd().getCols();
String mapping = table.getParameters().get(DynamoDBConstants.DYNAMODB_TYPE_MAPPING);
Map<String, String> typeMapping = HiveDynamoDBUtil.getHiveToDynamoDBMapping(mapping);
boolean hasItemMapType = false;
for (FieldSchema fieldSchema : tableSchema) {
String fieldName = fieldSchema.getName();
String fieldType = fieldSchema.getType();
HiveDynamoDBType ddType;
if (typeMapping.containsKey(fieldName)) {
try {
ddType = HiveDynamoDBTypeFactory.getTypeObjectFromDynamoDBType(
typeMapping.get(fieldName));
} catch (IllegalArgumentException e) {
throw new MetaException("The DynamoDB type " + typeMapping.get(fieldName)
+ " is not supported");
}
if (!ddType.supportsHiveType(TypeInfoUtils.getTypeInfoFromTypeString(fieldType))) {
throw new MetaException("The DynamoDB type " + typeMapping.get(fieldName)
+ " does not support Hive type " + fieldType);
}
} else {
try {
ddType = HiveDynamoDBTypeFactory.getTypeObjectFromHiveType(fieldType);
} catch (IllegalArgumentException e) {
throw new MetaException("The hive type " + fieldSchema.getType() + " is not supported in "
+ "DynamoDB");
}
}
// make sure only one column has item map type
if (HiveDynamoDBTypeFactory.isHiveDynamoDBItemMapType(ddType)) {
if (hasItemMapType) {
throw new MetaException("Only one column can be mapped to item map type " + fieldType);
}
hasItemMapType = true;
}
// validate key schema
for (AttributeDefinition definition : tableDescription.getAttributeDefinitions()) {
String attributeName = definition.getAttributeName();
if (fieldName.equalsIgnoreCase(attributeName)) {
String attributeType = definition.getAttributeType();
if (HiveDynamoDBTypeFactory.isHiveDynamoDBItemMapType(ddType)
|| (!ddType.getDynamoDBType().equals(attributeType))) {
throw new MetaException("The key element " + fieldName + " does not match type. "
+ "DynamoDB Type: " + attributeType + " Hive type: " + fieldType);
}
}
}
}
}