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

[FLINK-4609] Remove redundant check for null in CrossOperator #2490

Closed
wants to merge 1 commit into from

Conversation

apivovarov
Copy link
Contributor

if (input1 == null || input2 == null) {
throw new NullPointerException();
}

Copy link
Contributor

Choose a reason for hiding this comment

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

we could instead move the null check into the super() call using Preconditions.checkNotNull()

Copy link
Contributor Author

Choose a reason for hiding this comment

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

if input1 or/and input2 are null DefaultCross will throw NPE on line 133

I also added null check to TwoInputOperator (grand grand parent of DefaultCross)

Copy link
Contributor

Choose a reason for hiding this comment

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

yes, but if you used the preconditions check you could supply a useful error message, for example stating which input was actually null.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ok, I added null check for input1 and input2 with a message inline with calling super in DefaultCross

@apivovarov apivovarov force-pushed the FLINK-4609 branch 3 times, most recently from 85b227a to e61ee24 Compare September 10, 2016 22:59
@@ -129,14 +129,11 @@ private String getDefaultName() {

public DefaultCross(DataSet<I1> input1, DataSet<I2> input2, CrossHint hint, String defaultName) {

super(input1, input2, new DefaultCrossFunction<I1, I2>(),
super(Preconditions.checkNotNull(input1, "input1 is null"),
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we do the preconditions check in TwoInputOperator rather than the subclasses?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

DefaultCross calls input1.getType() and input2.getType() before calling super() on line 134. So, if we add null check to super class (e.g. TwoInputOperator) it will not work for DefaultCross

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I also added null check to TwoInputOperator
And removed input1 and input2 fields from DefaultCross because TwoInputOperator already has them

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@apivovarov apivovarov force-pushed the FLINK-4609 branch 2 times, most recently from 47ad988 to e8e4f72 Compare September 11, 2016 05:37
@@ -971,10 +971,7 @@ public void testForwardWithAtLeastOneIterationAssumptionForJavac() {
public void reduce(Iterable<Tuple2<Long, Long>> values, Collector<Long> out) throws Exception {
Long id = 0L;
for (Tuple2<Long, Long> value : values) {
id = value.f0;
Copy link
Contributor

Choose a reason for hiding this comment

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

This change causes a test to fail and should be reverted.
The UdfAnalyzer is a component that inspects the bytecode of user-defined functions to infer how they access input values. By removing the if condition (which is not evaluated by the analyzer), the analyzer can better infer the behavior of the function produces a different output.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Just reverted this change. Thank you!

@fhueske
Copy link
Contributor

fhueske commented Sep 19, 2016

Thanks for the contribution @apivovarov. The PR looks good except for the modified test which fails.

@fhueske
Copy link
Contributor

fhueske commented Sep 19, 2016

Thanks for the fast update @apivovarov.
PR is good to merge

@StephanEwen
Copy link
Contributor

Playing Devil's advocate here:

Does this really improve anything meaningful? This is an API-level operator, not anything runtime related, so the additional null check is not really important. The code is not getting simpler in my opinion as well. It worked well before, and every change may introduce another bug.

Why not focus energies on improvements where the system really gains?

@greghogan
Copy link
Contributor

This isn't improving performance but moving the null checks before first access and removing the duplicate DataSet references.

@fhueske
Copy link
Contributor

fhueske commented Sep 20, 2016

+1 to what Greg said. It also gets rid of a compiler warning.

@StephanEwen
Copy link
Contributor

All right, +1 then

@greghogan
Copy link
Contributor

Merging ...

@asfgit asfgit closed this in 470b752 Sep 20, 2016
liuyuzhong pushed a commit to liuyuzhong/flink that referenced this pull request Dec 5, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
6 participants