[FLINK-40486][table] Introduce the UUID logical type - #29041
Conversation
spuru9
left a comment
There was a problem hiding this comment.
LGTM
Need to regenerate rest docs
./mvnw package -Dgenerate-rest-docs -pl flink-docs -am -nsu -DskipTests
then commit the updated docs/static/generated/rest_v1_sql_gateway.yml.
@spuru9 Thanks. Updated the docs |
|
|
|
|
|
|
Casting is intentionally out of this PR. It's a dedicated FLIP-604 sub-task: FLINK-40487 |
Good catch, agreed. isComparable returns true for |
My plan is to add this entry together with FLINK-40490 so the reflective path is functional the moment |
dylanhz
left a comment
There was a problem hiding this comment.
Hi, thanks for the PR!
Just a small question: FLIP-604 also lists byte[] and canonical String as supported conversion classes, while UuidType currently only supports java.util.UUID. Which PR is planned to add support for these two conversion classes?
Up to you. Btw, I don't think you pushed the changes to TypeCheckUtils |
|
|
||
| private static final long serialVersionUID = 1L; | ||
|
|
||
| private static final Set<String> INPUT_OUTPUT_CONVERSION = conversionSet(UUID.class.getName()); |
There was a problem hiding this comment.
One last nit: this reads too complicated for what it actually does
private static final Set<String> INPUT_OUTPUT_CONVERSION = conversionSet(UUID.class.getName());
@Override
public boolean supportsInputConversion(Class<?> clazz) {
return INPUT_OUTPUT_CONVERSION.contains(clazz.getName());
}
Can we simplify it? One of the recent types (DescriptorType) does a similar thing
private static final Class<?> INPUT_OUTPUT_CONVERSION = UUID.class;
@Override
public boolean supportsInputConversion(Class<?> clazz) {
return INPUT_OUTPUT_CONVERSION == clazz;
}
...
Same for supportsOutputConversion
There was a problem hiding this comment.
I can change this now. But on the follow-up PR FLINK-40490 we will add byte[]/String and this will go back to a set
There was a problem hiding this comment.
Makes sense. Sounds fine to leave as-is
There was a problem hiding this comment.
there is a more critical downside of usage of classes: it only works if classloader is same
in case of different classloader == will return false
there is no such issue for classnames
Thanks @dylanhz! They land with FLINK-40490 "Runtime serialization and codegen for UUID", alongside the |
gustavodemorais
left a comment
There was a problem hiding this comment.
LGTM, thanks @raminqaf. Can you make sure CI is green?
| /** | ||
| * Data type of a universally unique identifier (UUID). | ||
| * | ||
| * <p>The type represents a 128-bit value stored as a fixed 16-byte big-endian sequence. |
There was a problem hiding this comment.
RFC describes multiple versions
what version we are talking bout here?
There was a problem hiding this comment.
Good point. The type is version-agnostic. It stores any 128-bit UUID in the canonical 16-byte big-endian layout defined by RFC 9562 (which obsoletes RFC 4122), and it does not inspect or validate the version/variant bits, so v1, v4, v7, and so on all map to the same UUID type. Versions are only relevant to generation, which lands separately as UUID_V4() / UUID_V7() in FLINK-40489. I will reword the javadoc to say this explicitly so it does not read as tied to one version.
Add UUID as a new logical type in the Table/SQL type system as the first sub-task of FLIP-604 (Complete VARIANT Primitive Coverage with UUID and Timestamps). UUID represents a 128-bit value stored as a fixed 16-byte big-endian sequence with a default conversion class of java.util.UUID. It maps to Calcite's native SqlTypeName.UUID, available since Calcite 1.41, so no SQL parser or Calcite version change is required. The type mirrors VARIANT: a parameterless scalar in the EXTENSION family. This change wires UUID through the type system only: the LogicalType and LogicalTypeRoot, the DataTypes.UUID() factory, the LogicalTypeParser keyword, the FlinkTypeFactory and LogicalRelDataTypeConverter mappings in both directions, and the planner and SQL gateway JSON serde. Runtime serialization and codegen (FLINK-40490), casting (FLINK-40487), comparison and ordering (FLINK-40488), functions (FLINK-40489), VARIANT integration (FLINK-40491 to FLINK-40493), and documentation (FLINK-40494) follow in separate sub-tasks.
What is the purpose of the change
This is the first sub-task of FLIP-604 (Complete VARIANT Primitive Coverage with UUID and Timestamps). It introduces
UUIDas a native logical type in the Table/SQL type system.UUIDrepresents a 128-bit value stored as a fixed 16-byte big-endian sequence, withjava.util.UUIDas its default conversion class. It maps to Calcite's nativeSqlTypeName.UUID, which is available in the Calcite 1.41 version Flink already uses, so no SQL parser or Calcite version change is required. The type mirrorsVARIANT: a parameterless scalar in theEXTENSIONfamily.This change is scoped to the type system only. It makes the type exist, be constructible, parseable, and round-trip through the planner and plan serde. It does not make queries over
UUIDexecute. Runtime serialization and codegen (FLINK-40490), casting (FLINK-40487), comparison and ordering (FLINK-40488), functions (FLINK-40489), VARIANT integration (FLINK-40491–40493), and documentation (FLINK-40494) follow in separate sub-tasks.Brief change log
UuidTypeandLogicalTypeRoot.UUID(EXTENSION family); add thedefault visit(UuidType)method toLogicalTypeVisitor.DataTypes.UUID()factory and theUUIDkeyword toLogicalTypeParser.UuidTypeto and fromSqlTypeName.UUIDinFlinkTypeFactoryandLogicalRelDataTypeConverter.UUIDin the planner and SQL gateway logical-type JSON serde.Verifying this change
This change added unit tests and can be verified as follows:
LogicalTypesType,DataTypesTest,LogicalTypeParserTestcover the type, theDataTypes.UUID()factory, and keyword parsing (UUID/UUID NOT NULL).FlinkTypeFactoryTest#testInternalToRelTypecovers theLogicalType↔RelDataTyperound-trip including nullability.LogicalRelDataTypeConverterTest, and the planner and SQL gatewayLogicalTypeJson(Ser)DeTestcover JSON serde round-trips.Does this pull request potentially affect one of the following parts:
@Public(Evolving): yes (new@PublicEvolvingUuidType,LogicalTypeRoot.UUID,DataTypes.UUID())TypeSerializeris added)Documentation
Two things to confirm before you submit:
Was generative AI tooling used to co-author this PR?
Generated-by: Claude Code (Opus 4.8)