Skip to content

fix(udf/win): udf c and python plugins for windows#35313

Open
stephenkgu wants to merge 16 commits into
3.0from
fix/6876989393
Open

fix(udf/win): udf c and python plugins for windows#35313
stephenkgu wants to merge 16 commits into
3.0from
fix/6876989393

Conversation

@stephenkgu
Copy link
Copy Markdown
Contributor

Description

Issue(s)

Checklist

Please check the items in the checklist if applicable.

  • Is the user manual updated?
  • Are the test cases passed and automated?
  • Is there no significant decrease in test coverage?

Copilot AI review requested due to automatic review settings May 11, 2026 08:32
Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request enhances Windows compatibility for User Defined Functions (UDFs) by replacing POSIX-specific environment handling with libuv's portable alternatives and adjusting pipe initialization for Windows IOCP requirements. Feedback identifies a missing path separator in the Windows UDF directory creation logic, inconsistent naming conventions for binary plugins on Windows, and a leftover commented-out line that should be removed.

Comment thread source/libs/function/src/udfd.c Outdated
Comment thread source/libs/function/src/udfd.c Outdated
Comment thread source/libs/function/src/udfd.c Outdated
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR adds/extends Windows support for UDF execution by enabling udfd on Windows, adjusting libuv process/pipe spawning to work with Windows overlapped pipes, and removing Windows platform blocks around UDF creation.

Changes:

  • Add Windows-compatible spawning of udfd (libuv pipes/env inheritance, PATH vs LD_LIBRARY_PATH).
  • Enable Python UDF plugin loading on Windows and adjust UDF body path handling.
  • Remove Windows-only rejection of CREATE FUNCTION and fix a Windows-incompatible __typeof__ usage in executor code.

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
source/libs/function/src/udfd.c Windows support for python plugin lib naming, UDF file path formatting, control pipe init, and UDF directory creation.
source/libs/function/src/tudf.c Windows-safe udfd spawn: pipe flags, PATH/LD_LIBRARY_PATH handling, and portable environment inheritance via libuv.
source/libs/executor/src/projectoperator.c Replace __typeof__ with sclIsTaskKilled for Windows compiler compatibility.
source/dnode/mnode/impl/src/mndFunc.c Allow CREATE FUNCTION on Windows by removing a platform block.
source/common/src/tglobal.c Enable tsStartUdfd by default (including Windows).
Comments suppressed due to low confidence (1)

source/libs/function/src/udfd.c:1776

  • The fallback path after taosMkDir failure is hard-coded to "%s/.udf" even on Windows. This is inconsistent with the Windows primary path ("%s.udf") and will flip directory naming depending on whether the first mkdir succeeds. Use the same Windows naming scheme in the fallback branch as well.
  if (code != TSDB_CODE_SUCCESS) {
    snprintf(global.udfDataDir, PATH_MAX, "%s/.udf", tsTempDir);
    code = taosMkDir(global.udfDataDir);

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread source/libs/function/src/tudf.c Outdated
Comment thread source/libs/function/src/udfd.c Outdated
Copilot AI review requested due to automatic review settings May 12, 2026 06:22
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 5 out of 5 changed files in this pull request and generated 1 comment.

Comment thread source/libs/function/src/tudf.c Outdated
Copilot AI review requested due to automatic review settings May 12, 2026 06:43
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 5 out of 5 changed files in this pull request and generated 4 comments.

Comment thread source/libs/function/src/tudf.c Outdated
Comment thread source/libs/function/src/tudf.c
Comment thread source/libs/function/src/tudf.c Outdated
Comment thread source/libs/function/src/tudf.c
@stephenkgu
Copy link
Copy Markdown
Contributor Author

/gemini review

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request focuses on improving Windows compatibility for User Defined Functions (UDF). Key changes include replacing POSIX-specific environment handling with libuv's portable uv_os_environ, updating pipe initialization to support Windows IOCP requirements, and enabling UDF functionality on Windows by removing previous platform restrictions. The review feedback identifies several opportunities to improve type safety in tudf.c by using size_t for string lengths and buffer size calculations, which ensures consistency with strlen and prevents potential signedness or overflow issues.

Comment thread source/libs/function/src/tudf.c Outdated
Comment thread source/libs/function/src/tudf.c Outdated
Comment thread source/libs/function/src/tudf.c Outdated
Copilot AI review requested due to automatic review settings May 12, 2026 07:33
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 5 out of 5 changed files in this pull request and generated 1 comment.

Comment thread source/common/src/tglobal.c
@stephenkgu
Copy link
Copy Markdown
Contributor Author

/gemini review

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request enhances Windows support for User Defined Functions (UDF) by replacing POSIX-specific environment variable handling with libuv's portable uv_os_environ and adjusting pipe initialization for Windows compatibility. It also refines path construction and library naming across platforms. Feedback was provided regarding the use of the POSIX-specific strncasecmp function within a Windows-specific code block, suggesting the use of _strnicmp for better compatibility with MSVC.

Comment thread source/libs/function/src/tudf.c
Copilot AI review requested due to automatic review settings May 12, 2026 07:59
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 5 out of 5 changed files in this pull request and generated 4 comments.

Comment thread source/libs/function/src/udfd.c
Comment thread source/libs/function/src/udfd.c Outdated
Comment thread source/libs/function/src/udfd.c
Comment thread source/libs/function/src/tudf.c
@stephenkgu
Copy link
Copy Markdown
Contributor Author

/gemini review

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request enhances Windows compatibility and portability for the UDF daemon. Significant changes include replacing POSIX-specific environ usage with libuv's uv_os_environ, adjusting pipe initialization for Windows requirements, and implementing platform-aware library naming and path construction. Review feedback suggests improving the portability of string comparison functions and refining the memory allocation logic for environment variable arrays to ensure long-term robustness.

Comment thread source/libs/function/src/tudf.c Outdated
Comment thread source/libs/function/src/tudf.c
Copilot AI review requested due to automatic review settings May 12, 2026 08:40
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 5 out of 5 changed files in this pull request and generated 2 comments.

Comment thread source/libs/function/src/tudf.c Outdated
Comment thread source/common/src/tglobal.c
@stephenkgu stephenkgu requested a review from zitsen as a code owner May 12, 2026 08:54
@stephenkgu
Copy link
Copy Markdown
Contributor Author

/gemini review

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request enables and improves User Defined Function (UDF) support on Windows. Key changes include replacing POSIX-specific environment handling with libuv's portable uv_os_environ, configuring pipes with UV_OVERLAPPED_PIPE and ipc=0 for Windows compatibility, and using platform-native directory separators and library extensions. It also removes previous Windows-specific restrictions on UDF creation. I have no feedback to provide.

@JinqingKuang
Copy link
Copy Markdown
Contributor

Code Review

发现 2 个需要处理的问题:

  1. source/libs/function/src/tudf.cudfSpawnUdfd()uv_pipe_init() 成功后新增了多条 goto _OVER 错误路径,但 _OVER 只释放内存,没有关闭 pData->ctrlPipe。启动失败时会留下活动 libuv handle,随后 uv_loop_close() 可能失败,清理状态不干净。
  2. UV_OVERLAPPED_PIPE 被无条件加到 child stdio flags。libuv 1.49.2 中它是 UV_NONBLOCK_PIPE 的兼容别名,不是 POSIX no-op;这会改变 Linux/macOS 上 taosudf 的 stdin 行为。

已分别发 inline comment 到对应代码行。

Comment thread source/libs/function/src/tudf.c
Comment thread source/libs/function/src/tudf.c
Copilot AI review requested due to automatic review settings May 14, 2026 06:02
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 7 out of 7 changed files in this pull request and generated 2 comments.

Comment on lines +336 to +340
int32_t pipeInitErr = uv_pipe_init(&pData->loop, &pData->ctrlPipe, 0);
if (pipeInitErr != 0) {
fnError("uv_pipe_init failed: %s", uv_strerror(pipeInitErr));
err = TSDB_CODE_UDF_UV_EXEC_FAILURE;
goto _OVER;
Comment on lines +404 to +405
#ifdef WINDOWS
snprintf(plugin->libPath, PATH_MAX, "%s", "taospyudf.dll");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants