Skip to content
Open
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?

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 @@ -90,6 +90,7 @@
import java.lang.reflect.Method;
import java.time.Duration;
import java.util.List;
import java.util.UUID;

import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
Expand Down Expand Up @@ -836,6 +837,31 @@ public Long reduce(Long value1, Long value2) throws Exception {
.isEqualTo(preferredResource7);
}

@Test
void testMapWithExplicitUuidType() {
final StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment();
// 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();
}
};
Comment on lines +844 to +850

@raminqaf raminqaf Sep 11, 2026

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.

Can the MapFunction return the UUID type as byte[] or Byte? Let's add a test like this

    @Test
    void testMapToBytesWithExplicitUuidType() {
        final StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment();
        // A lambda would bypass the input validation exercised by this test.
        final MapFunction<UUID, byte[]> byteMapper = value -> {
            ByteBuffer buffer = ByteBuffer.wrap(new byte[16]);
            buffer.putLong(value.getMostSignificantBits());
            buffer.putLong(value.getLeastSignificantBits());
            return buffer.array();
        };

        final DataStream<byte[]> stream = env.fromData(Types.UUID, new UUID(0L, 0L)).map(byteMapper);

        assertThat(stream.getType()).isEqualTo(PrimitiveArrayTypeInfo.BYTE_PRIMITIVE_ARRAY_TYPE_INFO);
    }

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.

Or even having a test for Mapping String -> UUID


final DataStream<String> stream = env.fromData(Types.UUID, new UUID(0L, 0L)).map(mapper);

assertThat(stream.getType()).isEqualTo(Types.STRING);
}

@Test
void testUuidIsNotAutomaticallyExtracted() {
final StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment();

assertThat(env.fromData(new UUID(0L, 0L)).getType())
.isEqualTo(new GenericTypeInfo<>(UUID.class));
}

@Test
void testTypeInfo() {
StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment();
Expand Down