Skip to content

[Java] Mark the casters of TSDataType transient so that Flink accepts a TSDataType - #1065

Merged
ColinLeeo merged 1 commit into
apache:developfrom
PDGGK:fix-tsdatatype-transient-casters
Nov 5, 2026
Merged

ColinLeeo merged 1 commit into
apache:developfrom
PDGGK:fix-tsdatatype-transient-casters

Conversation

@PDGGK

@PDGGK PDGGK commented Nov 3, 2026

Copy link
Copy Markdown
Contributor

Description

Since #872, every TSDataType constant holds a SingleValueCaster and an ArrayCaster, set to lambdas that are not serializable (TSDataType.java:129-:130 on develop). Java serializes an enum constant only by its name, so Java serialization is not affected. Flink's ClosureCleaner, however, serializes every non-static, non-transient field of the objects that a function holds, including the fields of enum constants, and rejects the function when one of them fails.

I ran into this while raising iotdb-extras to TsFile 2.5.0. RowTsFileInputFormatIntegrationTest.testStreamExecution of its Flink TsFile connector (Flink 1.17.1) passes with TsFile 2.4.0 and fails with 2.5.0:

org.apache.flink.api.common.InvalidProgramException: org.apache.tsfile.enums.TSDataType$$Lambda$96/0x000000d80109d000@3ccb12d is not serializable. The object probably contains or references non serializable fields.
	at org.apache.flink.api.java.ClosureCleaner.clean(ClosureCleaner.java:164)
	...
	at org.apache.flink.streaming.api.environment.StreamExecutionEnvironment.createInput(StreamExecutionEnvironment.java:1784)

The input format reaches a TSDataType through TsFileInputFormat.config → TSFileConfig.timeSeriesDataType, and ClosureCleaner recurses into every field that is neither static nor transient (needsRecursion in Flink 1.17). Until a release has this change, a job on 2.5.0 can avoid it with env.getConfig().setClosureCleanerLevel(ExecutionConfig.ClosureCleanerLevel.TOP_LEVEL).

Change

Both fields are now transient. Nothing reads them after deserialization, because deserializing an enum constant returns the existing constant.

Verification

  • New TSDataTypeSerializationTest in java/common:
    • every non-static, non-transient field of every constant can be serialized. This fails before the change with NotSerializableException: org.apache.tsfile.enums.TSDataType$$Lambda...;
    • Java serialization still returns the same constant.
  • All 7 tests in java/common pass, and so do TypeCastTest and TsPrimitiveTypeTest in java/tsfile. spotless:check passes.
  • I applied the change to v2.5.0 and installed it locally as 2.5.0-tsfix. With it, all 8 tests of the iotdb-extras flink-tsfile-connector pass, including testStreamExecution.

Since apache#872, every TSDataType constant holds a SingleValueCaster and an
ArrayCaster, initialised with lambdas that are not serializable. Java
serializes an enum constant only by its name, but Flink's ClosureCleaner
checks every non-static, non-transient field of the objects reachable
from a function, including the fields of enum constants. A Flink job
whose function or input format reaches a TSDataType through its fields
is therefore rejected with "TSDataType$$Lambda... is not serializable".

Mark both fields transient. Nothing reads them after serialization,
since deserializing an enum constant returns the existing constant.
@ColinLeeo

Copy link
Copy Markdown
Contributor

LGTM

@ColinLeeo
ColinLeeo merged commit eed50a3 into apache:develop Nov 5, 2026
19 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants