New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[BEAM-5646] Fix quality and hashcode for bytes in Row. #6765
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -26,6 +26,7 @@ | |
import com.google.common.collect.ImmutableMap; | ||
import com.google.common.collect.Lists; | ||
import java.math.BigDecimal; | ||
import java.nio.ByteBuffer; | ||
import java.util.Arrays; | ||
import java.util.List; | ||
import java.util.Map; | ||
|
@@ -34,6 +35,7 @@ | |
import org.apache.beam.sdk.schemas.Schema.FieldType; | ||
import org.joda.time.DateTime; | ||
import org.joda.time.DateTimeZone; | ||
import org.junit.Assert; | ||
import org.junit.Rule; | ||
import org.junit.Test; | ||
import org.junit.rules.ExpectedException; | ||
|
@@ -297,4 +299,30 @@ public void testThrowsForIncorrectNumberOfFields() { | |
thrown.expect(IllegalArgumentException.class); | ||
Row.withSchema(type).addValues(1, "2").build(); | ||
} | ||
|
||
@Test | ||
public void testByteArrayEquality() { | ||
byte[] a0 = new byte[] {1, 2, 3, 4}; | ||
byte[] b0 = new byte[] {1, 2, 3, 4}; | ||
|
||
Schema schema = Schema.of(Schema.Field.of("bytes", Schema.FieldType.BYTES)); | ||
|
||
Row a = Row.withSchema(schema).addValue(a0).build(); | ||
Row b = Row.withSchema(schema).addValue(b0).build(); | ||
|
||
Assert.assertEquals(a, b); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. will this fail without the change in There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nope. Seems like |
||
} | ||
|
||
@Test | ||
public void testByteBufferEquality() { | ||
byte[] a0 = new byte[] {1, 2, 3, 4}; | ||
byte[] b0 = new byte[] {1, 2, 3, 4}; | ||
|
||
Schema schema = Schema.of(Schema.Field.of("bytes", Schema.FieldType.BYTES)); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Need a test of many deeper structures. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
|
||
Row a = Row.withSchema(schema).addValue(ByteBuffer.wrap(a0)).build(); | ||
Row b = Row.withSchema(schema).addValue(ByteBuffer.wrap(b0)).build(); | ||
|
||
Assert.assertEquals(a, b); | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is actually not enough. If you have a schema with
f: LIST<BYTES>
it will not have correct equality. We need our own schema-driven deep equality.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes. This is a valid concern. If there is no other option, we need our deep equality check for our schema.
https://issues.apache.org/jira/browse/BEAM-5868
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The problem comes from
Objects.deepEquals
only have a deep equal implementation for primitive types and array. So Map and List will at least fail to check the correct equality.