Skip to content
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

[Bug]: [Java] Row equality not working as expected when ByteBuffer used as Map key #26695

Closed
1 of 15 tasks
ahmedabu98 opened this issue May 15, 2023 · 1 comment · Fixed by #31600
Closed
1 of 15 tasks
Assignees

Comments

@ahmedabu98
Copy link
Contributor

ahmedabu98 commented May 15, 2023

What happened?

I was writing a test that checked for the equality of Beam Rows with Maps that have ByteBuffer keys. Row's .equals() method doesn't account for this case.

To reproduce:

Schema schema = Schema.of(Schema.Field.of("bytesMap", Schema.FieldType.map(Schema.FieldType.BYTES, Schema.FieldType.STRING)));

ByteBuffer bytes1 = ByteBuffer.wrap("a".getBytes(StandardCharsets.UTF_8));
Map<ByteBuffer, String> map1 = new HashMap<>();
map1.put(bytes1, "abc");
Row row1 = Row.withSchema(schema).withFieldValue("bytesMap", map1).build();

ByteBuffer bytes2 = ByteBuffer.wrap("a".getBytes(StandardCharsets.UTF_8));
Map<ByteBuffer, String> map2 = new HashMap<>();
map2.put(bytes2, "abc");
Row row2 = Row.withSchema(schema).withFieldValue("bytesMap", map2).build();

System.out.println("map equals: " + map1.equals(map2)); // true
System.out.println(row1.equals(row2)); // false

Although ByteBuffer is used as the map key, Row stores the byte array value instead. There are known issues when using byte[] type as Map key (equality is determined by array identity, so only the exact same byte[] key can be used to retrieve a value. ie, a new identical byte[] will not retrieve any values. Read here for more details).

Issue Priority

Priority: 3 (minor)

Issue Components

  • Component: Python SDK
  • Component: Java SDK
  • Component: Go SDK
  • Component: Typescript SDK
  • Component: IO connector
  • Component: Beam examples
  • Component: Beam playground
  • Component: Beam katas
  • Component: Website
  • Component: Spark Runner
  • Component: Flink Runner
  • Component: Samza Runner
  • Component: Twister2 Runner
  • Component: Hazelcast Jet Runner
  • Component: Google Cloud Dataflow Runner
@ahmedabu98 ahmedabu98 changed the title [Bug]: [Java] Hamcrest containsInAnyOrder doesn't recognize Row equality with BYTES [Bug]: [Java] Row equality not working as expected when ByteBuffer used as Map key May 15, 2023
@Amar3tto
Copy link
Contributor

.take-issue

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants