seatunnel icon indicating copy to clipboard operation
seatunnel copied to clipboard

[Fix][Transform-V2] Fix datetime/numeric/string function edge cases and update tests

Open yzeng1618 opened this issue 3 weeks ago • 0 comments

https://github.com/apache/seatunnel/issues/10137

Purpose of this pull request

Fix several edge cases of SQL transform built‑in functions (DATEDIFF with MONTH, WEEK, SIGN, ASCII/LEFT/RIGHT, and CAST), and update corresponding unit tests and E2E expectations.

Does this PR introduce any user-facing change?

Yes.

  • DATEDIFF(..., 'MONTH') now returns the total month difference across years (e.g. from 2023-01-01 to 2024-03-01 returns 14 instead of 15).

  • WEEK() uses the ISO week number without the previous extra +1.

  • SIGN(null) now returns NULL instead of 0.

  • ASCII(NULL) / ASCII('') now return NULL instead of throwing, and LEFT / RIGHT with negative length return an empty string.

  • CAST no longer returns NULL when the value text equals the type name (e.g. CAST('VARCHAR' AS VARCHAR) now returns "VARCHAR").

These behavior changes only affect the dev branch and fix previously incorrect or inconsistent results.

How was this patch tested?

Updated and added unit tests in seatunnel-transforms-v2:

  • DateTimeFunctionTest for DATEDIFF month across years.

  • NumericFunctionTest for round on SHORT and SIGN(NULL).

  • StringFunctionTest for ASCII(NULL/'') and LEFT/RIGHT with negative length.

  • SystemFunctionTest for CAST and COALESCE with target type.

  • Updated the datetime E2E config in seatunnel-e2e to align with the corrected DATEDIFF behavior.

Check list

  • [ ] If any new Jar binary package adding in your PR, please add License Notice according New License Guide
  • [ ] If necessary, please update the documentation to describe the new feature. https://github.com/apache/seatunnel/tree/dev/docs
  • [ ] If necessary, please update incompatible-changes.md to describe the incompatibility caused by this PR.
  • [ ] If you are contributing the connector code, please check that the following files are updated:
    1. Update plugin-mapping.properties and add new connector information in it
    2. Update the pom file of seatunnel-dist
    3. Add ci label in label-scope-conf
    4. Add e2e testcase in seatunnel-e2e
    5. Update connector plugin_config

yzeng1618 avatar Dec 09 '25 07:12 yzeng1618