Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.UUID;

import static org.apache.flink.api.java.typeutils.TypeExtractionUtils.checkAndExtractLambda;
import static org.apache.flink.api.java.typeutils.TypeExtractionUtils.getAllDeclaredMethods;
Expand Down Expand Up @@ -1498,10 +1499,16 @@ private static void validateInfo(
// check for Java Basic Types
if (typeInfo instanceof BasicTypeInfo) {

TypeInformation<?> actual;
// check if basic type at all
if (!(type instanceof Class<?>)
|| (actual = BasicTypeInfo.getInfoFor((Class<?>) type)) == null) {
if (!(type instanceof Class<?>)) {
throw new InvalidTypesException("Basic type expected.");
}
// UUID is not registered for automatic extraction to preserve existing serializers.
final TypeInformation<?> actual =
type == UUID.class
? BasicTypeInfo.UUID_TYPE_INFO
: BasicTypeInfo.getInfoFor((Class<?>) type);
Comment on lines +1507 to +1510

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Should we add a test in TypeExtractorTest?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Agreed. Moved both tests to TypeExtractorTest.

if (actual == null) {
throw new InvalidTypesException("Basic type expected.");
}
// check if correct basic type
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.UUID;

import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
Expand Down Expand Up @@ -115,6 +116,26 @@ public void reduce(Iterable<Boolean> values, Collector<Boolean> out)
assertThat(TypeExtractor.getForObject(true)).isEqualTo(BasicTypeInfo.BOOLEAN_TYPE_INFO);
}

@Test
void testMapWithExplicitUuidType() {
// A lambda would bypass the input validation exercised by this test.
final MapFunction<UUID, String> mapper =
new MapFunction<UUID, String>() {
@Override
public String map(UUID value) {
return value.toString();
}
};

assertThat(TypeExtractor.getMapReturnTypes(mapper, Types.UUID)).isEqualTo(Types.STRING);
}

@Test
void testUuidIsNotAutomaticallyExtracted() {
assertThat(TypeExtractor.getForObject(new UUID(0L, 0L)))
.isEqualTo(new GenericTypeInfo<>(UUID.class));
}

@SuppressWarnings({"unchecked", "rawtypes"})
@Test
void testTupleWithBasicTypes() throws Exception {
Expand Down