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

[Fix] Fix get bytes from LinkHashMap #5622

Merged
merged 2 commits into from
Oct 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,7 @@ private int getBytesForValue(Object v) {
case "Double[]":
return ((Double[]) v).length * 8;
case "HashMap":
case "LinkedHashMap":
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will other types of map be used?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the data circulated within SeaTunnelRow. We should standardize the type used when creating map type data in SeaTunnelRow to prevent burden on downstream parsing. For now, Hashmap and LinkHashMap are enough.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok

int size = 0;
for (Map.Entry<?, ?> entry : ((Map<?, ?>) v).entrySet()) {
size += getBytesForValue(entry.getKey()) + getBytesForValue(entry.getValue());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@

import java.math.BigDecimal;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.Map;

public class SeaTunnelRowTest {
Expand Down Expand Up @@ -87,4 +88,12 @@ void testForRowSize() {
});
Assertions.assertEquals(181, row2.getBytesSize());
}

@Test
void testWithLinkHashMap() {
Map<String, String> map = new LinkedHashMap<>();
map.put("key", "value");
SeaTunnelRow row = new SeaTunnelRow(new Object[] {map});
Assertions.assertEquals(8, row.getBytesSize());
}
}