Skip to content

[FLINK-39492][starrocks] Fix microsecond precision loss for TIMESTAMP types in StarRocks sink#4404

Open
ThorneANN wants to merge 1 commit into
apache:masterfrom
ThorneANN:fix/starrocks-timestamp-precision
Open

[FLINK-39492][starrocks] Fix microsecond precision loss for TIMESTAMP types in StarRocks sink#4404
ThorneANN wants to merge 1 commit into
apache:masterfrom
ThorneANN:fix/starrocks-timestamp-precision

Conversation

@ThorneANN
Copy link
Copy Markdown
Contributor

TIMESTAMP_WITHOUT_TIME_ZONE and TIMESTAMP_WITH_LOCAL_TIME_ZONE fields were
serialized using a hardcoded "yyyy-MM-dd HH:mm:ss" formatter, silently
dropping sub-second precision regardless of the declared column precision.

Add datetimeFormatter(int precision), mirroring the existing timeFormatter,
which appends fractional seconds only when precision > 0. The formatter
instances are cached per precision to avoid repeated allocation.

For StarRocks < 3.1, the fractional part is truncated by the server on
ingestion — no behavioral regression. For StarRocks >= 3.1 (which supports
microsecond DATETIME storage), full precision is now preserved end-to-end.

@ThorneANN ThorneANN changed the title FLINK-39492[starrocks] Fix microsecond precision loss for TIMESTAMP types in StarRocks sink [FLINK-39492][starrocks] Fix microsecond precision loss for TIMESTAMP types in StarRocks sink May 20, 2026
Copy link
Copy Markdown
Member

@yuxiqian yuxiqian left a comment

Choose a reason for hiding this comment

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

Adding integrated tests / E2e cases would be nice.

if (precision <= 0) {
return DATETIME_FORMATTER;
}
if (precision < DATETIME_FORMATTERS.length) {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

The maximal precision for temporal types is 9. We may add a precondition guard here, and remove the non-caching branch.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants