Skip to content

Commit

Permalink
Update UnionByNameVisitor helper method name with more detailed comments
Browse files Browse the repository at this point in the history
  • Loading branch information
rocco408 committed Nov 14, 2024
1 parent 679df6c commit 223e0e5
Showing 1 changed file with 9 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ private void updateColumn(Types.NestedField field, Types.NestedField existingFie
String fullName = partnerSchema.findColumnName(existingField.fieldId());

boolean needsOptionalUpdate = field.isOptional() && existingField.isRequired();
boolean needsTypeUpdate = !isCompatibleType(existingField.type(), field.type());
boolean needsTypeUpdate = !isIgnorableTypeUpdate(existingField.type(), field.type());
boolean needsDocUpdate = field.doc() != null && !field.doc().equals(existingField.doc());

if (needsOptionalUpdate) {
Expand All @@ -180,9 +180,15 @@ private void updateColumn(Types.NestedField field, Types.NestedField existingFie
}
}

private boolean isCompatibleType(Type existingType, Type newType) {
private boolean isIgnorableTypeUpdate(Type existingType, Type newType) {
if (existingType.isPrimitiveType()) {
// Primitive -> Wider Primitive
/* TypeUtil.isPromotionAllowed is used to check whether type promotion is allowed in the reverse order,
* newType to existingType. A true result implies that the newType is more narrow than the existingType,
* which translates in this context as an ignorable type update. A false result implies the opposite.
* Examples:
* existingType:long -> newType:int returns true, meaning it is ignorable
* existingType:int -> newType:long returns false, meaning it is not ignorable
*/
return newType.isPrimitiveType()
&& TypeUtil.isPromotionAllowed(newType, existingType.asPrimitiveType());
} else {
Expand Down

0 comments on commit 223e0e5

Please sign in to comment.