-
Notifications
You must be signed in to change notification settings - Fork 2.4k
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
Flink: Fix range distribution npe when value is null #11662
Merged
Merged
Changes from 2 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
cbcf744
Flink: Fix range distribution npe when value is null
a49b87b
Flink: SortKeySerializer and CompletedStatisticsSerializer support ve…
Guosmilesmile 1e27dcb
Flink: SortKeySerializer and CompletedStatisticsSerializer support ve…
Guosmilesmile 5ebc768
Flink: SortKeySerializer and CompletedStatisticsSerializer support ve…
Guosmilesmile ae1dfe0
Flink: SortKeySerializer and CompletedStatisticsSerializer support ve…
Guosmilesmile a2d4e04
Flink: SortKeySerializer and CompletedStatisticsSerializer support ve…
Guosmilesmile fb226bb
Flink: SortKeySerializer and CompletedStatisticsSerializer support ve…
Guosmilesmile d5fb96b
Flink: SortKeySerializer and CompletedStatisticsSerializer support ve…
Guosmilesmile 13ddf61
Flink: SortKeySerializer and CompletedStatisticsSerializer support ve…
Guosmilesmile File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -52,8 +52,32 @@ class SortKeySerializer extends TypeSerializer<SortKey> { | |
private final int size; | ||
private final Types.NestedField[] transformedFields; | ||
|
||
private int version = SortKeySerializerSnapshot.CURRENT_VERSION; | ||
|
||
private transient SortKey sortKey; | ||
|
||
SortKeySerializer(Schema schema, SortOrder sortOrder, int version) { | ||
this.version = version; | ||
this.schema = schema; | ||
this.sortOrder = sortOrder; | ||
this.size = sortOrder.fields().size(); | ||
|
||
this.transformedFields = new Types.NestedField[size]; | ||
for (int i = 0; i < size; ++i) { | ||
SortField sortField = sortOrder.fields().get(i); | ||
Types.NestedField sourceField = schema.findField(sortField.sourceId()); | ||
Type resultType = sortField.transform().getResultType(sourceField.type()); | ||
Types.NestedField transformedField = | ||
Types.NestedField.of( | ||
sourceField.fieldId(), | ||
sourceField.isOptional(), | ||
sourceField.name(), | ||
resultType, | ||
sourceField.doc()); | ||
transformedFields[i] = transformedField; | ||
} | ||
Guosmilesmile marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
|
||
SortKeySerializer(Schema schema, SortOrder sortOrder) { | ||
this.schema = schema; | ||
this.sortOrder = sortOrder; | ||
|
@@ -83,6 +107,18 @@ private SortKey lazySortKey() { | |
return sortKey; | ||
} | ||
|
||
public int getLatestVersion() { | ||
return snapshotConfiguration().getCurrentVersion(); | ||
} | ||
|
||
public void restoreToLatestVersion() { | ||
this.version = snapshotConfiguration().getCurrentVersion(); | ||
} | ||
|
||
public void setVersion(int version) { | ||
this.version = version; | ||
} | ||
|
||
@Override | ||
public boolean isImmutableType() { | ||
return false; | ||
|
@@ -124,6 +160,16 @@ public void serialize(SortKey record, DataOutputView target) throws IOException | |
for (int i = 0; i < size; ++i) { | ||
int fieldId = transformedFields[i].fieldId(); | ||
Type.TypeID typeId = transformedFields[i].type().typeId(); | ||
if (version > 1) { | ||
Object value = record.get(i, Object.class); | ||
if (value == null) { | ||
target.writeBoolean(true); | ||
continue; | ||
} else { | ||
target.writeBoolean(false); | ||
} | ||
} | ||
pvary marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
switch (typeId) { | ||
case BOOLEAN: | ||
target.writeBoolean(record.get(i, Boolean.class)); | ||
|
@@ -192,6 +238,14 @@ public SortKey deserialize(SortKey reuse, DataInputView source) throws IOExcepti | |
reuse.size(), | ||
size); | ||
for (int i = 0; i < size; ++i) { | ||
if (version > 1) { | ||
boolean isNull = source.readBoolean(); | ||
if (isNull) { | ||
reuse.set(i, null); | ||
continue; | ||
} | ||
} | ||
pvary marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
int fieldId = transformedFields[i].fieldId(); | ||
Type.TypeID typeId = transformedFields[i].type().typeId(); | ||
switch (typeId) { | ||
|
@@ -276,11 +330,13 @@ public TypeSerializerSnapshot<SortKey> snapshotConfiguration() { | |
} | ||
|
||
public static class SortKeySerializerSnapshot implements TypeSerializerSnapshot<SortKey> { | ||
private static final int CURRENT_VERSION = 1; | ||
private static final int CURRENT_VERSION = 2; | ||
|
||
private Schema schema; | ||
private SortOrder sortOrder; | ||
|
||
private int version = CURRENT_VERSION; | ||
|
||
/** Constructor for read instantiation. */ | ||
@SuppressWarnings({"unused", "checkstyle:RedundantModifier"}) | ||
public SortKeySerializerSnapshot() { | ||
|
@@ -310,10 +366,16 @@ public void writeSnapshot(DataOutputView out) throws IOException { | |
@Override | ||
public void readSnapshot(int readVersion, DataInputView in, ClassLoader userCodeClassLoader) | ||
throws IOException { | ||
if (readVersion == 1) { | ||
readV1(in); | ||
} else { | ||
throw new IllegalArgumentException("Unknown read version: " + readVersion); | ||
switch (readVersion) { | ||
case 1: | ||
readV1(in); | ||
this.version = 1; | ||
break; | ||
case 2: | ||
readV1(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. Can we remove the version suffix in the method name? It handles both versions. |
||
break; | ||
default: | ||
throw new IllegalArgumentException("Unknown read version: " + readVersion); | ||
} | ||
} | ||
|
||
|
@@ -324,6 +386,10 @@ public TypeSerializerSchemaCompatibility<SortKey> resolveSchemaCompatibility( | |
return TypeSerializerSchemaCompatibility.incompatible(); | ||
} | ||
|
||
if (oldSerializerSnapshot.getCurrentVersion() == 1 && this.getCurrentVersion() == 2) { | ||
return TypeSerializerSchemaCompatibility.compatibleAfterMigration(); | ||
} | ||
|
||
// Sort order should be identical | ||
SortKeySerializerSnapshot oldSnapshot = (SortKeySerializerSnapshot) oldSerializerSnapshot; | ||
if (!sortOrder.sameOrder(oldSnapshot.sortOrder)) { | ||
|
@@ -349,7 +415,7 @@ public TypeSerializerSchemaCompatibility<SortKey> resolveSchemaCompatibility( | |
public TypeSerializer<SortKey> restoreSerializer() { | ||
Preconditions.checkState(schema != null, "Invalid schema: null"); | ||
Preconditions.checkState(sortOrder != null, "Invalid sort order: null"); | ||
return new SortKeySerializer(schema, sortOrder); | ||
return new SortKeySerializer(schema, sortOrder, version); | ||
} | ||
|
||
private void readV1(DataInputView in) throws IOException { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -73,12 +73,17 @@ static byte[] serializeCompletedStatistics( | |
} | ||
|
||
static CompletedStatistics deserializeCompletedStatistics( | ||
byte[] bytes, TypeSerializer<CompletedStatistics> statisticsSerializer) { | ||
byte[] bytes, CompletedStatisticsSerializer statisticsSerializer) { | ||
try { | ||
DataInputDeserializer input = new DataInputDeserializer(bytes); | ||
return statisticsSerializer.deserialize(input); | ||
} catch (IOException e) { | ||
throw new UncheckedIOException("Fail to deserialize aggregated statistics", e); | ||
} catch (Exception e) { | ||
try { | ||
DataInputDeserializer input = new DataInputDeserializer(bytes); | ||
return statisticsSerializer.deserializeV1(input); | ||
} catch (IOException ioException) { | ||
throw new UncheckedIOException("Fail to deserialize aggregated statistics", ioException); | ||
} | ||
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. I see, we're retrying here in case the restore fails. |
||
} | ||
} | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
AFAIK We were not writing the serializer version before this change. So not sure this works when restoring the serializer to read old data.