@Override public List<String> primitive(Type.PrimitiveType readPrimitive) { if (currentType.equals(readPrimitive)) { return NO_ERRORS; } if (!currentType.isPrimitiveType()) { return ImmutableList.of(String.format(": %s cannot be read as a %s", currentType.typeId().toString().toLowerCase(Locale.ENGLISH), readPrimitive)); } if (!isPromotionAllowed(currentType.asPrimitiveType(), readPrimitive)) { return ImmutableList.of(String.format(": %s cannot be promoted to %s", currentType, readPrimitive)); } // both are primitives and promotion is allowed to the read type return NO_ERRORS; } }
@Override public UpdateSchema updateColumn(String name, Type.PrimitiveType newType) { Types.NestedField field = schema.findField(name); Preconditions.checkArgument(field != null, "Cannot update missing column: %s", name); Preconditions.checkArgument(!deletes.contains(field.fieldId()), "Cannot update a column that will be deleted: %s", field.name()); Preconditions.checkArgument(TypeUtil.isPromotionAllowed(field.type(), newType), "Cannot change column type: %s: %s -> %s", name, field.type(), newType); // merge with a rename, if present int fieldId = field.fieldId(); Types.NestedField rename = updates.get(fieldId); if (rename != null) { updates.put(fieldId, Types.NestedField.required(fieldId, rename.name(), newType)); } else { updates.put(fieldId, Types.NestedField.required(fieldId, field.name(), newType)); } return this; }
new Schema(required(1, "to_field", to)), fromSchema); if (TypeUtil.isPromotionAllowed(from, to)) { Assert.assertEquals("Should produce 0 error messages", 0, errors.size()); } else {