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-4673] [core] TypeInfoFactory for Either type #2545

Closed

Conversation

greghogan
Copy link
Contributor

Removes from TypeExtractor the explicit parsing for Either and adds an EitherTypeInfoFactory.

A test was removed that was expected to fail but now looks to succeed.

Removes from TypeExtractor the explicit parsing for Either and adds an
EitherTypeInfoFactory.
@twalthr
Copy link
Contributor

twalthr commented Sep 26, 2016

I will review this PR soon.

Copy link
Contributor

@twalthr twalthr left a comment

Choose a reason for hiding this comment

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

Thanks for the PR @greghogan. There are some things that need to be fixed so that we have the same behavior again.


@Override
public TypeInformation<Either<L, R>> createTypeInfo(Type t, Map<String, TypeInformation<?>> genericParameters) {
return new EitherTypeInfo(genericParameters.get("L"), genericParameters.get("R"));
Copy link
Contributor

Choose a reason for hiding this comment

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

Can check here if the key is not null? Btw. we should add a null check to the constructor of EitherTypeInfo.

// type needs to be treated a pojo due to additional fields
if (subTypesInfo == null) {
if (t instanceof ParameterizedType) {
return (TypeInformation<OUT>) analyzePojo(typeToClass(t), new ArrayList<Type>(typeHierarchy), (ParameterizedType) t, in1Type, in2Type);
Copy link
Contributor

Choose a reason for hiding this comment

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

What happens if Either class is extended? The whole checking is missing when using a factory. It need to go into the createTypeInfo method. What I just recognized, actually the EitherTypeInfo needs a second constructor that takes the subclass similar to TupleTypeInfo. The t parameter of createTypeInfo can than passed to this constructor.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Either is overridden in TypeExtractorTest without any test errors. Could you give an example that would break the current PR? @twalthr

Copy link
Contributor

Choose a reason for hiding this comment

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

Sorry, for the delay. I will have a look at it again.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hi @twalthr just a gentle reminder for when you have some time to look at this.

Copy link
Contributor

Choose a reason for hiding this comment

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

Sorry for not writing back earlier. You are right, all tests still work. The factories work better than I expected. We lose the input validation in this PR but I think this is ok. I will merge this.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@twalthr thanks for checking this! Glad to hear that your factories implementation has exceeded expectations :)

@Test(expected=InvalidTypesException.class)
public void testEitherFromObjectException() {
Either<String, Tuple1<Integer>> either = Either.Left("test");
TypeExtractor.getForObject(either);
Copy link
Contributor

Choose a reason for hiding this comment

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

This test is necessary. The exception is not thrown anymore but the type information that is currently generated is invalid (the right type information is null, which should never happen).

@greghogan greghogan force-pushed the 4673_typeinfofactory_for_either_type branch from 869245d to 80e807d Compare September 26, 2016 13:36
@asfgit asfgit closed this in d4d7cc3 Jan 10, 2017
liuyuzhong7 pushed a commit to liuyuzhong7/flink that referenced this pull request Jan 17, 2017
Removes from TypeExtractor the explicit parsing for Either and adds an
EitherTypeInfoFactory.

This closes apache#2545.
joseprupi pushed a commit to joseprupi/flink that referenced this pull request Feb 12, 2017
Removes from TypeExtractor the explicit parsing for Either and adds an
EitherTypeInfoFactory.

This closes apache#2545.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
3 participants