-
Notifications
You must be signed in to change notification settings - Fork 13.8k
[FLINK-11420][core] Fixed duplicate method of TraversableSerializer #7872
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
Conversation
|
Thanks a lot for your contribution to the Apache Flink project. I'm the @flinkbot. I help the community Review Progress
Please see the Pull Request Review Guide for a full explanation of the review process. DetailsThe Bot is tracking the review progress through labels. Labels are applied according to the order of the review items. For consensus, approval by a Flink committer of PMC member is required Bot commandsThe @flinkbot bot supports the following commands:
|
| testSerializedCopyIndividually(); | ||
| testSerializedCopyAsSequence(); | ||
| testSerializabilityAndEquals(); | ||
| try { |
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.
Do you know why these were not called before? Also, why do we need the try-catch around this now?
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.
I guess they were added later to the base class and the person that added those cases was probably not aware of existence of this class.
The try-catch is because a few of the new test cases throw exception, whereas the testAll doesn't. Did not want to change it in every place where the testAll is called. I think though in the long run we should revisit those places and actually get rid of this method at all.
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.
so this isn't even compiling at the moment?
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.
it is compiling
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.
I just realized though there some test failures for different serializers, investigating...
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.
I think it would probably be cleaner to not catch the exception and simply declare that it throws. Which might lead to other places where we need to declare, as you said.
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.
I would suggest maybe replacing this with:
for (Method method : getClass().getMethods()) {
if (method.getAnnotation(Test.class) == null) {
continue;
}
try {
method.invoke(this);
}
catch (IllegalAccessException e) {
throw new RuntimeException("Unable to invoke test " + method.getName(), e);
}
catch (InvocationTargetException e) {
sneakyThrow(e.getCause());
}
}
where sneakyThrow is defined as follows
private static <E extends Throwable> void sneakyThrow(Throwable e) throws E {
throw (E) e;
}
dcfb614 to
8ca7ced
Compare
|
Could you have a look at this PR @igalshilman @aljoscha |
igalshilman
left a comment
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.
Thanks for improving the test coverage!
The changes look good to me, I've left some inline comments for your consideration.
| testSerializedCopyIndividually(); | ||
| testSerializedCopyAsSequence(); | ||
| testSerializabilityAndEquals(); | ||
| try { |
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.
I would suggest maybe replacing this with:
for (Method method : getClass().getMethods()) {
if (method.getAnnotation(Test.class) == null) {
continue;
}
try {
method.invoke(this);
}
catch (IllegalAccessException e) {
throw new RuntimeException("Unable to invoke test " + method.getName(), e);
}
catch (InvocationTargetException e) {
sneakyThrow(e.getCause());
}
}
where sneakyThrow is defined as follows
private static <E extends Throwable> void sneakyThrow(Throwable e) throws E {
throw (E) e;
}
| } catch (Exception ex) { | ||
| throw new RuntimeException(ex); | ||
| } | ||
| public void testAll() throws Exception { |
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.
I don't think this is needed, check my previous comment regarding sneakyThrow
| private static boolean deepEquals0(Object e1, Object e2) { | ||
| assert e1 != null; | ||
| boolean eq; | ||
| if (e1 instanceof Object[] && e2 instanceof Object[]) { |
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.
I think this can be replaced with e1.getClass().isArray()
and the recursively call deepEquals element wise (to catch Tuples of Tuples)
or if this is not needed for the test, then maybe just replace with Arrays.deepEquals
| description.appendValue(wanted); | ||
| } | ||
|
|
||
| private static boolean deepEquals(Object o1, Object o2) { |
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.
I think that this logic can be simplified with something like
private static Stream<Object> flatten(Object o) {
if (o == null) {
return Stream.empty();
}
if (o.getClass().isArray()) {
return Arrays.stream((Object[]) o)
.flatMap(e -> flatten(e));
}
if (o instanceof Tuple) {
Tuple t = (Tuple) o;
return IntStream.range(0, t.getArity())
.mapToObj(t::getField)
.flatMap(e -> flatten(e));
}
return Stream.of(o);
}
and then
private static boolean deepEquals(Object left ,Object right) {
Iterator<Object> l = flatten(left).iterator();
Iterator<Object> r = flatten(right).iterator();
...
}
update: I gave it a bit more thought, and this isn't exactly what you need.
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.
I haven't tested that tho 😅
f771de4 to
5593e8b
Compare
Tuple0Serializer serialized null as just a proper Tuple0 instance, which if later deserialized resulted in a regular value rather than null. This commit changes it so that it is no longer possible to serialize null with Tuple0Serializer.
…yoGenericTypeSerializerTest
…rTestInstance by reflection
The duplicate method of TypeSerializer used an equality check rather than reference check of the element serializer to decide if we need a deep copy. This commit uses proper reference comparison.
…ng Tuples into account This commit introduced a matcher that performs a deepEquals comparison similarly to Objects#deepEquals. The only difference is that it also performs deep equality check for some flink specific classes such as e.g. Tuples, Rows.
|
@flinkbot approve consensus |
What is the purpose of the change
The duplicate method of TypeSerializer used an equality check rather
than reference check of the element serializer to decide if we need a
deep copy. This commit uses proper reference comparison.
Brief change log
TestListCompositeSerializerthat is used only in testsNothingSerializerwhich can be called transitively e.g. fromEitherSerializerSerializerTestBasefrom withinSerializerTestInstancethan reference check of the element serializer to decide if we need a
deep copy. This commit uses proper reference comparison.
Objects#deepEquals. The only difference is that it also performs deep equality check for flink's specific types.Verifying this change
duplicatemethod test inSerializerTestInstanceDoes this pull request potentially affect one of the following parts:
@Public(Evolving): (yes / no)Documentation