XComp commented on code in PR #23490:
URL: https://github.com/apache/flink/pull/23490#discussion_r1388282048
##########
flink-core/src/main/java/org/apache/flink/api/java/typeutils/runtime/PojoSerializer.java:
##########
@@ -473,25 +521,40 @@ public T deserialize(T reuse, DataInputView source)
throws IOException {
}
}
- if ((flags & NO_SUBCLASS) != 0) {
+ if (isRecord()) {
try {
+ JavaRecordBuilderFactory<T>.JavaRecordBuilder builder =
recordHelper.newBuilder();
for (int i = 0; i < numFields; i++) {
boolean isNull = source.readBoolean();
if (fields[i] != null) {
if (isNull) {
- fields[i].set(reuse, null);
+ builder.setField(i, null);
} else {
- Object field;
+ builder.setField(i, deserializeField(null, i,
source));
Review Comment:
> If you pass a non-null reuse it's not null, but otherwise createInstance
returns null for records
true, I overlooked that `createInstance` actually returns `null` in certain
situations.
##########
flink-core/src/main/java/org/apache/flink/api/java/typeutils/runtime/PojoSerializer.java:
##########
@@ -400,21 +444,23 @@ public T deserialize(DataInputView source) throws
IOException {
target = createInstance();
}
- if ((flags & NO_SUBCLASS) != 0) {
+ if (isRecord) {
+ JavaRecordBuilderFactory<T>.JavaRecordBuilder builder =
recordHelper.newBuilder();
Review Comment:
This is not resolved in the code. I still struggle to understand why this is
not necessary to be added here :thinking:
##########
flink-core/src/main/java/org/apache/flink/api/java/typeutils/runtime/PojoSerializer.java:
##########
@@ -473,25 +521,41 @@ public T deserialize(T reuse, DataInputView source)
throws IOException {
}
}
- if ((flags & NO_SUBCLASS) != 0) {
+ if (isRecord()) {
try {
+ JavaRecordBuilderFactory<T>.JavaRecordBuilder builder =
recordFactory.newBuilder();
for (int i = 0; i < numFields; i++) {
boolean isNull = source.readBoolean();
if (fields[i] != null) {
if (isNull) {
- fields[i].set(reuse, null);
+ builder.setField(i, null);
} else {
- Object field;
+ Object reuseField = reuse == null ? null :
fields[i].get(reuse);
+ builder.setField(i, deserializeField(reuseField,
i, source));
+ }
+ } else if (!isNull) {
+ // read and dump a pre-existing field value
+ fieldSerializers[i].deserialize(source);
+ }
+ }
- Object reuseField = fields[i].get(reuse);
- if (reuseField != null) {
- field =
fieldSerializers[i].deserialize(reuseField, source);
- } else {
- field =
fieldSerializers[i].deserialize(source);
- }
+ reuse = builder.build();
+ } catch (IllegalAccessException e) {
+ throw new RuntimeException(
+ "Error during POJO copy, this should not happen since
we check the fields before.",
+ e);
+ }
+ } else if ((flags & NO_SUBCLASS) != 0) {
Review Comment:
test
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]