Skip to content

Add DuckDB::TableFunction::InitInfo#bind_data - #1438

Merged
suketa merged 1 commit into
suketa:mainfrom
otegami:feature/init-info-get-bind-data
Aug 1, 2026
Merged

Add DuckDB::TableFunction::InitInfo#bind_data#1438
suketa merged 1 commit into
suketa:mainfrom
otegami:feature/init-info-get-bind-data

Conversation

@otegami

@otegami otegami commented Aug 1, 2026

Copy link
Copy Markdown
Contributor

GitHub: GH-1123

Wrap duckdb_init_get_bind_data() so the init callback can read the object the bind callback stashed with BindInfo#set_bind_data. Init runs before execute and is where per-scan state (thread count, projected columns) is decided, so it needs the bind-phase data too. #bind_data is the Ruby-style reader and #get_bind_data mirrors the C API name, following #max_threads= / #set_max_threads. ref: https://duckdb.org/docs/stable/clients/c/api.html#duckdb_init_get_bind_data

Summary by CodeRabbit

  • New Features

    • Added access to table-function bind data through TableFunction::InitInfo.
    • Bind data can be retrieved as the original Ruby object, or returns nil when unset.
  • Bug Fixes

    • Preserved bind-data object identity during garbage collection.
  • Documentation

    • Added an unreleased changelog entry describing bind-data access.

GitHub: suketaGH-1123

Wrap duckdb_init_get_bind_data() so the init callback can read the object the
bind callback stashed with BindInfo#set_bind_data. Init runs before execute and
is where per-scan state (thread count, projected columns) is decided, so it
needs the bind-phase data too. #bind_data is the Ruby-style reader and
#get_bind_data mirrors the C API name, following #max_threads= / #set_max_threads.
ref: https://duckdb.org/docs/stable/clients/c/api.html#duckdb_init_get_bind_data
@coderabbitai

coderabbitai Bot commented Aug 1, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

The change adds get_bind_data and bind_data to TableFunction::InitInfo. The accessors return bind data configured through BindInfo#set_bind_data, or nil when no data exists. Integration tests and a changelog entry cover the API.

Changes

Table-function bind-data retrieval

Layer / File(s) Summary
InitInfo bind-data accessors
ext/duckdb/table_function_init_info.c
InitInfo retrieves DuckDB bind data, converts it to a Ruby object, and exposes get_bind_data and bind_data.
Behavior validation and changelog
test/duckdb_test/table_function/init_info_test.rb, CHANGELOG.md
Tests cover configured and unset bind data, object identity after GC.compact, and the new API is documented.‌

Estimated code review effort: 2 (Simple) | ~10 minutes

Possibly related issues

  • suketa/ruby-duckdb issue 1123: Directly tracks adding duckdb_init_get_bind_data.
  • suketa/ruby-duckdb issue 1203: Covers a related bind-data accessor in a different callback context.

Possibly related PRs

Suggested reviewers: suketa

Sequence Diagram(s)

sequenceDiagram
  participant BindInfo
  participant DuckDB
  participant InitInfo
  BindInfo->>DuckDB: Store bind data with set_bind_data
  DuckDB->>InitInfo: Pass bind data during initialization
  InitInfo->>DuckDB: Retrieve bind data
  InitInfo->>InitInfo: Convert function data to a Ruby object
  InitInfo-->>BindInfo: Return the bind-data object or nil
Loading
🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly identifies the primary change: adding DuckDB::TableFunction::InitInfo#bind_data.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🧹 Nitpick comments (3)
test/duckdb_test/table_function/init_info_test.rb (2)

149-152: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Assert identity with the object passed to set_bind_data.

The current assertion compares only the two accessor results. Capture the hash in an outer local and assert that both results are the same object as that local.

This finding is based on the changed test assertions and the stated object-identity behavior.

Proposed assertion change
+      bind_data = { token: 'init-round-trip', n: 7 }
       table_function.bind do |bind_info|
         bind_info.add_result_column('value', DuckDB::LogicalType::BIGINT)
-        bind_info.set_bind_data({ token: 'init-round-trip', n: 7 })
+        bind_info.set_bind_data(bind_data)
       end
...
       assert_equal({ token: 'init-round-trip', n: 7 }, observed_bind_data)
-      assert_same observed_bind_data, observed_via_alias
+      assert_same bind_data, observed_bind_data
+      assert_same bind_data, observed_via_alias

Also applies to: 167-168

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@test/duckdb_test/table_function/init_info_test.rb` around lines 149 - 152,
Update the table_function bind setup around bind_info.set_bind_data to store the
hash in an outer local before passing it in. Change both accessor assertions to
verify object identity against that captured local, not merely equality with
each other.

143-145: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Keep the bind-data round-trip test active on Windows.

Line 144 skips before the bind, init, query, and assertions run. If GC.compact is the only unsafe operation, guard only that call and keep the accessor assertions enabled.

This finding is based on the changed test flow and the stated integration-test objective.

Proposed test change
-      skip 'GC.compact hangs on Windows in parallel test execution' if Gem.win_platform?
-
...
-        GC.compact
+        GC.compact unless Gem.win_platform?

Also applies to: 156-159

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@test/duckdb_test/table_function/init_info_test.rb` around lines 143 - 145,
Remove the Windows skip from test_init_info_bind_data_round_trip and keep the
bind, init, query, and accessor assertions running on all platforms. Guard only
the GC.compact invocation that hangs during parallel Windows execution, while
preserving the existing round-trip verification.
ext/duckdb/table_function_init_info.c (1)

12-12: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Prefix the new C symbol with rbduckdb_.

The declaration, definition, and method registrations use table_function_init_info_get_bind_data. Rename all three references to one rbduckdb_-prefixed name.

As per coding guidelines, all C symbols in ext/duckdb/**/*.c must be prefixed with rbduckdb_.

Proposed rename
-static VALUE table_function_init_info_get_bind_data(VALUE self);
+static VALUE rbduckdb_table_function_init_info_get_bind_data(VALUE self);

-static VALUE table_function_init_info_get_bind_data(VALUE self) {
+static VALUE rbduckdb_table_function_init_info_get_bind_data(VALUE self) {

-    rb_define_method(cDuckDBTableFunctionInitInfo, "get_bind_data", table_function_init_info_get_bind_data, 0);
-    rb_define_method(cDuckDBTableFunctionInitInfo, "bind_data", table_function_init_info_get_bind_data, 0);
+    rb_define_method(cDuckDBTableFunctionInitInfo, "get_bind_data", rbduckdb_table_function_init_info_get_bind_data, 0);
+    rb_define_method(cDuckDBTableFunctionInitInfo, "bind_data", rbduckdb_table_function_init_info_get_bind_data, 0);

Also applies to: 129-135, 149-150

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@ext/duckdb/table_function_init_info.c` at line 12, Rename the
table_function_init_info_get_bind_data declaration, definition, and method
registration references to a consistent rbduckdb_-prefixed symbol, preserving
the existing behavior and signatures.

Source: Coding guidelines

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Nitpick comments:
In `@ext/duckdb/table_function_init_info.c`:
- Line 12: Rename the table_function_init_info_get_bind_data declaration,
definition, and method registration references to a consistent
rbduckdb_-prefixed symbol, preserving the existing behavior and signatures.

In `@test/duckdb_test/table_function/init_info_test.rb`:
- Around line 149-152: Update the table_function bind setup around
bind_info.set_bind_data to store the hash in an outer local before passing it
in. Change both accessor assertions to verify object identity against that
captured local, not merely equality with each other.
- Around line 143-145: Remove the Windows skip from
test_init_info_bind_data_round_trip and keep the bind, init, query, and accessor
assertions running on all platforms. Guard only the GC.compact invocation that
hangs during parallel Windows execution, while preserving the existing
round-trip verification.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 0122cec4-86c1-41ae-bd5c-67fe12e1f00a

📥 Commits

Reviewing files that changed from the base of the PR and between 34970d7 and 25e17b7.

📒 Files selected for processing (3)
  • CHANGELOG.md
  • ext/duckdb/table_function_init_info.c
  • test/duckdb_test/table_function/init_info_test.rb

@suketa
suketa merged commit 6581c24 into suketa:main Aug 1, 2026
35 checks passed
@suketa

suketa commented Aug 1, 2026

Copy link
Copy Markdown
Owner

Thank you I merged it

@otegami
otegami deleted the feature/init-info-get-bind-data branch August 2, 2026 04:08
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.

2 participants