Skip to content

Commit

Permalink
[HUDI-5233] Fix bug when InternalSchemaUtils.collectTypeChangedCols r…
Browse files Browse the repository at this point in the history
…eturns all columns (#7228)
  • Loading branch information
trushev authored Nov 18, 2022
1 parent c5590cd commit e4e2883
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import java.io.Serializable;
import java.util.List;
import java.util.Locale;
import java.util.Objects;

/**
* The type of a schema, reference avro schema.
Expand Down Expand Up @@ -60,6 +61,27 @@ abstract class PrimitiveType implements Type {
public boolean isNestedType() {
return false;
}

/**
* We need to override equals because the check {@code intType1 == intType2} can return {@code false}.
* Despite the fact that most subclasses look like singleton with static field {@code INSTANCE},
* they can still be created by deserializer.
*/
@Override
public boolean equals(Object o) {
if (this == o) {
return true;
} else if (!(o instanceof PrimitiveType)) {
return false;
}
PrimitiveType that = (PrimitiveType) o;
return typeId().equals(that.typeId());
}

@Override
public int hashCode() {
return Objects.hashCode(typeId());
}
}

abstract class NestedType implements Type {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.Assertions;

import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
Expand Down Expand Up @@ -76,6 +80,16 @@ public void testInternalSchemaVisitor() {
Assertions.assertEquals(result1.get("double"), 4);
}

@Test
public void testIntTypeEqualsAfterDeserialization() throws Exception {
Types.IntType intType = Types.IntType.get();
ByteArrayOutputStream baos = new ByteArrayOutputStream();
new ObjectOutputStream(baos).writeObject(intType);
Types.IntType deserializedIntType = (Types.IntType)
new ObjectInputStream(new ByteArrayInputStream(baos.toByteArray())).readObject();
Assertions.assertEquals(intType, deserializedIntType);
}

public Types.RecordType getNestRecordType() {
return Types.RecordType.get(Types.Field.get(0, false, "id", Types.IntType.get()),
Types.Field.get(1, true, "data", Types.StringType.get()),
Expand Down

0 comments on commit e4e2883

Please sign in to comment.