Skip to content

[Enhancement] support DATE and DATETIME types in Java UDF (backport #72337)#72362

Merged
wanpengfei-git merged 1 commit into
branch-4.1from
mergify/bp/branch-4.1/pr-72337
May 10, 2026
Merged

[Enhancement] support DATE and DATETIME types in Java UDF (backport #72337)#72362
wanpengfei-git merged 1 commit into
branch-4.1from
mergify/bp/branch-4.1/pr-72337

Conversation

@mergify

@mergify mergify Bot commented Apr 30, 2026

Copy link
Copy Markdown
Contributor

Why I'm doing:

Map SQL DATE to java.time.LocalDate and DATETIME to java.time.LocalDateTime across the FE analyzer, the udf-extensions JNI runtime, and the BE Java function call path. Wire format mirrors the StarRocks column storage:

  • DATE: int32 Julian day. Java decodes via LocalDate.ofEpochDay(julian - UNIX_EPOCH_JULIAN), encodes the inverse.
  • DATETIME: packed int64 (julian << 40 | microseconds_of_day). Encoding lives in UDFHelper since the layout is StarRocks-specific.

The batch path (input + output) zero-copies the column buffer through DirectByteBuffer; the per-row path (cast_to_jvalue / assign_jvalue / append_jvalue / check_type_matched) routes through new JVMFunctionHelper::newLocalDate{,Time} / valLocalDate{,Time} so const-column inputs and UDAF/UDTF returns also work.

Also wires DATE/DATETIME into the BE-side JNI signature parser (ClassAnalyzer::get_udaf_method_desc) and the GetColumnLogicalTypeVistor so ARRAY/ARRAY elements resolve correctly. The previous silent-skip on unrecognized object classes is hardened to a TYPE_UNKNOWN entry that surfaces a clear "unknown type sign" error from get_method_desc instead of segfaulting at method_desc[0].is_box.

What I'm doing:

Fixes #issue

What type of PR is this:

  • BugFix
  • Feature
  • Enhancement
  • Refactor
  • UT
  • Doc
  • Tool

Does this PR entail a change in behavior?

  • Yes, this PR will result in a change in behavior.
  • No, this PR will not result in a change in behavior.

If yes, please specify the type of change:

  • Interface/UI changes: syntax, type conversion, expression evaluation, display information
  • Parameter changes: default values, similar parameters but with different default values
  • Policy changes: use new policy to replace old one, functionality automatically enabled
  • Feature removed
  • Miscellaneous: upgrade & downgrade compatibility, etc.

Checklist:

  • I have added test cases for my bug fix or my new feature
  • This pr needs user documentation (for new or modified features or behaviors)
    • I have added documentation for my new feature or new function
    • This pr needs auto generate documentation
  • This is a backport pr

Bugfix cherry-pick branch check:

  • I have checked the version labels which the pr will be auto-backported to the target branch
    • 4.1
    • 4.0
    • 3.5
    • 3.4

https://claude.ai/code/session_013eanvS6pP87BHRE865hig8


This is an automatic backport of pull request #72337 done by Mergify.

@mergify mergify Bot added the conflicts label Apr 30, 2026
@mergify

mergify Bot commented Apr 30, 2026

Copy link
Copy Markdown
Contributor Author

Cherry-pick of add5dee has failed:

On branch mergify/bp/branch-4.1/pr-72337
Your branch is up to date with 'origin/branch-4.1'.

You are currently cherry-picking commit add5deeffc.
  (fix conflicts and run "git cherry-pick --continue")
  (use "git cherry-pick --skip" to skip this patch)
  (use "git cherry-pick --abort" to cancel the cherry-pick operation)

Changes to be committed:
	modified:   be/src/udf/java/java_native_method.cpp
	modified:   be/src/udf/java/type_traits.h
	new file:   java-extensions/udf-extensions/src/test/java/com/starrocks/udf/UDFHelperDateTest.java
	new file:   test/sql/test_udf/R/test_jvm_date_udf
	new file:   test/sql/test_udf/T/test_jvm_date_udf

Unmerged paths:
  (use "git add <file>..." to mark resolution)
	both modified:   be/src/udf/java/java_data_converter.cpp
	both modified:   be/src/udf/java/java_udf.cpp
	both modified:   be/src/udf/java/java_udf.h
	both modified:   be/test/udf/java/java_data_converter_test.cpp
	both modified:   be/test/udf/java/java_native_method_test.cpp
	both modified:   be/test/udf/java/java_udf_test.cpp
	both modified:   docs/en/sql-reference/sql-functions/JAVA_UDF.md
	both modified:   docs/ja/sql-reference/sql-functions/JAVA_UDF.md
	both modified:   docs/zh/sql-reference/sql-functions/JAVA_UDF.md
	both modified:   fe/fe-core/src/main/java/com/starrocks/sql/analyzer/CreateFunctionAnalyzer.java
	both modified:   fe/fe-core/src/test/java/com/starrocks/sql/analyzer/CreateFunctionStmtAnalyzerTest.java
	both modified:   java-extensions/udf-extensions/src/main/java/com/starrocks/udf/UDFHelper.java

To fix up this pull request, you can check it out locally. See documentation: https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/reviewing-changes-in-pull-requests/checking-out-pull-requests-locally

@CLAassistant

Copy link
Copy Markdown

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

@github-actions github-actions Bot added documentation Documentation changes automerge labels Apr 30, 2026
@wanpengfei-git wanpengfei-git enabled auto-merge (squash) April 30, 2026 01:59
@mergify mergify Bot closed this Apr 30, 2026
auto-merge was automatically disabled April 30, 2026 01:59

Pull request was closed

@mergify

mergify Bot commented Apr 30, 2026

Copy link
Copy Markdown
Contributor Author

@mergify[bot]: Backport conflict, please reslove the conflict and resubmit the pr

Co-authored-by: Claude <noreply@anthropic.com>

Signed-off-by: Hyper-FF <253014618+Hyper-FF@users.noreply.github.com>

Signed-off-by: stdpain <drfeng08@gmail.com>
@stdpain stdpain reopened this May 10, 2026
@wanpengfei-git wanpengfei-git enabled auto-merge (squash) May 10, 2026 15:51
@stdpain stdpain force-pushed the mergify/bp/branch-4.1/pr-72337 branch from c3da023 to da021cf Compare May 10, 2026 15:51
@github-actions

Copy link
Copy Markdown
Contributor

🌎 Translation Required?

All translation files are up to date.
Great job! No translation actions are required for this PR.

🕒 Last updated: Sun, 10 May 2026 15:58:00 GMT

@wanpengfei-git wanpengfei-git merged commit 68afc3a into branch-4.1 May 10, 2026
32 of 33 checks passed
@wanpengfei-git wanpengfei-git deleted the mergify/bp/branch-4.1/pr-72337 branch May 10, 2026 16:31
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.

4 participants