-
Notifications
You must be signed in to change notification settings - Fork 4.5k
[BEAM-10529] nullable xlang coder #16923
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
Changes from all commits
b4b0025
798fd53
8743549
1ce6605
04868d6
a6a38d0
e3e0223
30f06d6
24dd876
e642e7c
f55074c
4dd1c54
43c84e6
3e93b56
48b6f34
a078029
258d7a9
af2930f
d19c47c
269b414
4656b31
59d3d73
b54da74
f60e4ea
1805a49
40556b7
488e1d1
cc243f1
a343a57
c9761f5
c5ae489
d0a5979
962ec4b
dbe1bb3
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 |
|---|---|---|
|
|
@@ -69,6 +69,7 @@ | |
| import org.apache.beam.sdk.coders.IterableCoder; | ||
| import org.apache.beam.sdk.coders.IterableLikeCoder; | ||
| import org.apache.beam.sdk.coders.KvCoder; | ||
| import org.apache.beam.sdk.coders.NullableCoder; | ||
| import org.apache.beam.sdk.coders.RowCoder; | ||
| import org.apache.beam.sdk.coders.StringUtf8Coder; | ||
| import org.apache.beam.sdk.coders.TimestampPrefixingWindowCoder; | ||
|
|
@@ -134,6 +135,7 @@ public class CommonCoderTest { | |
| .put(getUrn(StandardCoders.Enum.SHARDED_KEY), ShardedKey.Coder.class) | ||
| .put(getUrn(StandardCoders.Enum.CUSTOM_WINDOW), TimestampPrefixingWindowCoder.class) | ||
| .put(getUrn(StandardCoders.Enum.STATE_BACKED_ITERABLE), StateBackedIterable.Coder.class) | ||
| .put(getUrn(StandardCoders.Enum.NULLABLE), NullableCoder.class) | ||
| .build(); | ||
|
|
||
| @AutoValue | ||
|
|
@@ -201,7 +203,7 @@ abstract static class OneCoderTestSpec { | |
| @SuppressWarnings("mutable") | ||
| abstract byte[] getSerialized(); | ||
|
|
||
| abstract Object getValue(); | ||
| abstract @Nullable Object getValue(); | ||
|
|
||
| static OneCoderTestSpec create( | ||
| CommonCoder coder, boolean nested, byte[] serialized, Object value) { | ||
|
|
@@ -382,6 +384,17 @@ private static Object convertValue(Object value, CommonCoder coderSpec, Coder co | |
| Map<String, Object> kvMap = (Map<String, Object>) value; | ||
| Coder windowCoder = ((TimestampPrefixingWindowCoder) coder).getWindowCoder(); | ||
| return convertValue(kvMap.get("window"), coderSpec.getComponents().get(0), windowCoder); | ||
| } else if (s.equals(getUrn(StandardCoders.Enum.NULLABLE))) { | ||
|
Contributor
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. Are we generating individual tests for coders here or are we lumping everything into a single test ? If it's latter probably we should consider adding tests specifically for the new case.
Contributor
Author
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. It is a single test in the java sense, but there are 3 test cases in the yaml file for nullable coders. |
||
| if (coderSpec.getComponents().size() == 1 | ||
| && coderSpec.getComponents().get(0).getUrn().equals(getUrn(StandardCoders.Enum.BYTES))) { | ||
| if (value == null) { | ||
| return null; | ||
| } else { | ||
| return ((String) value).getBytes(StandardCharsets.ISO_8859_1); | ||
| } | ||
| } else { | ||
| throw new IllegalStateException("Unknown or missing nested coder for nullable coder"); | ||
| } | ||
| } else { | ||
| throw new IllegalStateException("Unknown coder URN: " + coderSpec.getUrn()); | ||
| } | ||
|
|
@@ -575,6 +588,8 @@ private void verifyDecodedValue(CommonCoder coder, Object expectedValue, Object | |
| assertEquals(expectedValue, actualValue); | ||
| } else if (s.equals(getUrn(StandardCoders.Enum.CUSTOM_WINDOW))) { | ||
| assertEquals(expectedValue, actualValue); | ||
| } else if (s.equals(getUrn(StandardCoders.Enum.NULLABLE))) { | ||
| assertThat(expectedValue, equalTo(actualValue)); | ||
| } else { | ||
| throw new IllegalStateException("Unknown coder URN: " + coder.getUrn()); | ||
| } | ||
|
|
||
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.
To clarify, only the last byte here will be in the an encoded element that has value null ?
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.
yep. 0000 means null, 0001 means "the rest of this is non-null"