Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Fix timestamp precision#1931

Merged
polyzos merged 3 commits intoapache:mainapache/fluss:mainfrom
buvb:fix-timestamp-precision-1843buvb/fluss:fix-timestamp-precision-1843Copy head branch name to clipboard
Nov 5, 2025
Merged

Fix timestamp precision#1931
polyzos merged 3 commits intoapache:mainapache/fluss:mainfrom
buvb:fix-timestamp-precision-1843buvb/fluss:fix-timestamp-precision-1843Copy head branch name to clipboard

Conversation

@buvb
Copy link
Copy Markdown
Contributor

@buvb buvb commented Nov 4, 2025

Purpose

Linked issue: close #1843

This PR fixes a precision handling bug in PojoToRowConverter where timestamp values were not being truncated according to the schema-defined precision when converting POJO objects to internal rows.

fix log

Problem:

  • PojoToRowConverter did not respect the precision parameter defined in TIMESTAMP_WITHOUT_TIME_ZONE and TIMESTAMP_WITH_LOCAL_TIME_ZONE types when converting POJO fields to row values
  • This caused an asymmetry with RowToPojoConverter, which correctly uses precision when reading values
  • As a result, timestamp values could have higher precision than specified in the schema, violating the schema contract

Solution:

  1. Modified createFieldConverter() in PojoToRowConverter to extract precision from DataType for timestamp fields
  2. Updated convertTimestampNtzValue() and convertTimestampLtzValue() methods to accept and use precision parameter
  3. Added three helper methods for precision truncation:
    • truncateToTimestampPrecision(LocalDateTime, int) - truncates LocalDateTime to specified precision
    • truncateToTimestampPrecision(Instant, int) - truncates Instant to specified precision
    • truncateNanos(int, int) - core truncation logic that calculates the divisor based on precision
  4. Added comprehensive test cases to verify precision handling for different precision levels (3, 6, 9) and round-trip conversions

Tests

Unit Tests:

  • PojoToRowConverterTest#testTimestampPrecision3 - Validates precision 3 (milliseconds) truncation
  • PojoToRowConverterTest#testTimestampPrecision6 - Validates precision 6 (microseconds) truncation
  • PojoToRowConverterTest#testTimestampPrecision9 - Validates precision 9 (nanoseconds) preserves full precision
  • PojoToRowConverterTest#testTimestampPrecisionRoundTrip - Validates POJO → Row → POJO round-trip consistency

@polyzos polyzos merged commit a956aa5 into apache:main Nov 5, 2025
5 checks passed
Ugbot pushed a commit to Ugbot/fluss that referenced this pull request Apr 26, 2026
* fix:Enhance the timestamp conversion function, support precision parameters and add truncation methods

* fix:Precision test file

* [client][hotfix] Add Javadoc for TimestampPojo test class
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.

Should converters take into account precision?

2 participants

Morty Proxy This is a proxified and sanitized view of the page, visit original site.