Skip to content

Conversation

@suketa
Copy link
Owner

@suketa suketa commented Jul 15, 2025

This is the first step of DuckDB::ScalarFunction class. Currently, this class does nothing.

Summary by CodeRabbit

  • New Features

    • Introduced the DuckDB::ScalarFunction class (currently under construction) to the Ruby extension, laying the groundwork for future scalar function support.
  • Documentation

    • Updated the changelog to include the addition of the DuckDB::ScalarFunction class.

This is the first step of DuckDB::ScalarFunction class.
Currently, this class does nothing.
@coderabbitai
Copy link

coderabbitai bot commented Jul 15, 2025

Walkthrough

A new Ruby C extension class, DuckDB::ScalarFunction, was introduced as part of the DuckDB integration. This includes new source and header files for scalar function support, memory management routines, and initialization hooks. The changelog was updated to reflect the addition, and the initialization sequence was modified to register the new class.

Changes

File(s) Change Summary
CHANGELOG.md Added entry for DuckDB::ScalarFunction class under "Unreleased" section.
ext/duckdb/duckdb.c Added call to initialize scalar function support in the extension initialization function.
ext/duckdb/ruby-duckdb.h Included scalar_function.h and declared cDuckDBScalarFunction global variable.
ext/duckdb/scalar_function.c, ext/duckdb/scalar_function.h Introduced new source and header files for DuckDB::ScalarFunction, including struct, memory management, and initialization routines.

Sequence Diagram(s)

sequenceDiagram
    participant RubyApp as Ruby Application
    participant DuckDBExt as DuckDB Ruby Extension
    participant ScalarFunc as ScalarFunction Class

    RubyApp->>DuckDBExt: require 'duckdb'
    DuckDBExt->>DuckDBExt: Init_duckdb_native()
    DuckDBExt->>DuckDBExt: rbduckdb_init_duckdb_scalar_function()
    DuckDBExt->>ScalarFunc: Define DuckDB::ScalarFunction class
    Note right of ScalarFunc: ScalarFunction ready for use (construction only)
Loading

Poem

A hop, a skip, a scalar leap,
New functions for DuckDB to keep!
Wrapped in Ruby, memory neat,
A class emerges, code complete.
The changelog grows, the features bloom—
More magic for the database room!
🐇✨

✨ Finishing Touches
  • 📝 Generate Docstrings

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
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (1)
ext/duckdb/scalar_function.h (1)

14-14: Remove extra blank line for consistency.

The extra blank line at the end of the file is unnecessary and should be removed for consistency with other header files.

-
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 552d247 and 17803af.

📒 Files selected for processing (5)
  • CHANGELOG.md (1 hunks)
  • ext/duckdb/duckdb.c (1 hunks)
  • ext/duckdb/ruby-duckdb.h (2 hunks)
  • ext/duckdb/scalar_function.c (1 hunks)
  • ext/duckdb/scalar_function.h (1 hunks)
🧰 Additional context used
🧠 Learnings (6)
📓 Common learnings
Learnt from: suketa
PR: suketa/ruby-duckdb#0
File: :0-0
Timestamp: 2025-01-24T22:37:32.786Z
Learning: In Ruby-DuckDB C extensions, when initializing resources like prepared statements, store them directly in the context structure instead of using temporary variables to prevent memory leaks, especially when exceptions might be thrown.
Learnt from: suketa
PR: suketa/ruby-duckdb#0
File: :0-0
Timestamp: 2025-01-24T22:18:24.630Z
Learning: When using ruby-asan (AddressSanitizer), avoid letting DuckDB throw C++ exceptions by checking conditions (like table existence) beforehand and raising Ruby exceptions directly to prevent ASAN from intercepting the C++ exceptions.
Learnt from: suketa
PR: suketa/ruby-duckdb#0
File: :0-0
Timestamp: 2025-01-25T05:20:48.677Z
Learning: In Ruby C extensions, prefer using Ruby's string functions (like rb_str_new2) over C string functions (like strdup) to avoid manual memory management and potential memory leaks.
Learnt from: suketa
PR: suketa/ruby-duckdb#871
File: ext/duckdb/appender.c:170-178
Timestamp: 2025-01-26T00:37:44.001Z
Learning: In ruby-duckdb's DuckDB::Appender#append_uint8, values larger than uint8 max (255) are silently truncated to maintain backward compatibility, following C's implicit truncation behavior. Range checking is intentionally omitted to avoid breaking changes.
CHANGELOG.md (2)
Learnt from: suketa
PR: suketa/ruby-duckdb#871
File: ext/duckdb/appender.c:170-178
Timestamp: 2025-01-26T00:37:44.001Z
Learning: In ruby-duckdb's DuckDB::Appender#append_uint8, values larger than uint8 max (255) are silently truncated to maintain backward compatibility, following C's implicit truncation behavior. Range checking is intentionally omitted to avoid breaking changes.
Learnt from: suketa
PR: suketa/ruby-duckdb#0
File: :0-0
Timestamp: 2025-01-24T22:18:24.630Z
Learning: When using ruby-asan (AddressSanitizer), avoid letting DuckDB throw C++ exceptions by checking conditions (like table existence) beforehand and raising Ruby exceptions directly to prevent ASAN from intercepting the C++ exceptions.
ext/duckdb/ruby-duckdb.h (3)
Learnt from: suketa
PR: suketa/ruby-duckdb#0
File: :0-0
Timestamp: 2025-01-24T22:37:32.786Z
Learning: In Ruby-DuckDB C extensions, when initializing resources like prepared statements, store them directly in the context structure instead of using temporary variables to prevent memory leaks, especially when exceptions might be thrown.
Learnt from: suketa
PR: suketa/ruby-duckdb#0
File: :0-0
Timestamp: 2025-01-24T22:18:24.630Z
Learning: When using ruby-asan (AddressSanitizer), avoid letting DuckDB throw C++ exceptions by checking conditions (like table existence) beforehand and raising Ruby exceptions directly to prevent ASAN from intercepting the C++ exceptions.
Learnt from: suketa
PR: suketa/ruby-duckdb#871
File: ext/duckdb/appender.c:170-178
Timestamp: 2025-01-26T00:37:44.001Z
Learning: In ruby-duckdb's DuckDB::Appender#append_uint8, values larger than uint8 max (255) are silently truncated to maintain backward compatibility, following C's implicit truncation behavior. Range checking is intentionally omitted to avoid breaking changes.
ext/duckdb/duckdb.c (2)
Learnt from: suketa
PR: suketa/ruby-duckdb#0
File: :0-0
Timestamp: 2025-01-24T22:37:32.786Z
Learning: In Ruby-DuckDB C extensions, when initializing resources like prepared statements, store them directly in the context structure instead of using temporary variables to prevent memory leaks, especially when exceptions might be thrown.
Learnt from: suketa
PR: suketa/ruby-duckdb#0
File: :0-0
Timestamp: 2025-01-24T22:18:24.630Z
Learning: When using ruby-asan (AddressSanitizer), avoid letting DuckDB throw C++ exceptions by checking conditions (like table existence) beforehand and raising Ruby exceptions directly to prevent ASAN from intercepting the C++ exceptions.
ext/duckdb/scalar_function.c (3)
Learnt from: suketa
PR: suketa/ruby-duckdb#0
File: :0-0
Timestamp: 2025-01-24T22:37:32.786Z
Learning: In Ruby-DuckDB C extensions, when initializing resources like prepared statements, store them directly in the context structure instead of using temporary variables to prevent memory leaks, especially when exceptions might be thrown.
Learnt from: suketa
PR: suketa/ruby-duckdb#0
File: :0-0
Timestamp: 2025-01-25T05:20:48.677Z
Learning: In Ruby C extensions, prefer using Ruby's string functions (like rb_str_new2) over C string functions (like strdup) to avoid manual memory management and potential memory leaks.
Learnt from: suketa
PR: suketa/ruby-duckdb#0
File: :0-0
Timestamp: 2025-01-24T22:18:24.630Z
Learning: When using ruby-asan (AddressSanitizer), avoid letting DuckDB throw C++ exceptions by checking conditions (like table existence) beforehand and raising Ruby exceptions directly to prevent ASAN from intercepting the C++ exceptions.
ext/duckdb/scalar_function.h (2)
Learnt from: suketa
PR: suketa/ruby-duckdb#0
File: :0-0
Timestamp: 2025-01-24T22:37:32.786Z
Learning: In Ruby-DuckDB C extensions, when initializing resources like prepared statements, store them directly in the context structure instead of using temporary variables to prevent memory leaks, especially when exceptions might be thrown.
Learnt from: suketa
PR: suketa/ruby-duckdb#0
File: :0-0
Timestamp: 2025-01-24T22:18:24.630Z
Learning: When using ruby-asan (AddressSanitizer), avoid letting DuckDB throw C++ exceptions by checking conditions (like table existence) beforehand and raising Ruby exceptions directly to prevent ASAN from intercepting the C++ exceptions.
🧬 Code Graph Analysis (2)
ext/duckdb/duckdb.c (2)
ext/duckdb/scalar_function.h (1)
  • rbduckdb_init_duckdb_scalar_function (10-10)
ext/duckdb/scalar_function.c (1)
  • rbduckdb_init_duckdb_scalar_function (30-36)
ext/duckdb/scalar_function.c (1)
ext/duckdb/scalar_function.h (1)
  • rbduckdb_init_duckdb_scalar_function (10-10)
🔇 Additional comments (9)
ext/duckdb/ruby-duckdb.h (2)

32-32: LGTM! Proper header inclusion.

The inclusion of the scalar function header follows the established pattern in the codebase.


46-46: LGTM! Consistent external variable declaration.

The external variable declaration follows the same pattern as other Ruby class variables in the codebase.

CHANGELOG.md (1)

9-9: LGTM! Appropriate changelog documentation.

The changelog entry properly documents the new class addition and correctly notes it's under construction, following the established pattern.

ext/duckdb/duckdb.c (1)

44-44: LGTM! Proper initialization integration.

The initialization call follows the established pattern and is correctly placed in the initialization sequence.

ext/duckdb/scalar_function.h (1)

1-12: LGTM! Well-structured header file.

The header file follows proper C conventions with include guards, appropriate struct definition, and clear function declaration.

ext/duckdb/scalar_function.c (4)

9-13: LGTM! Proper Ruby data type descriptor.

The data type descriptor correctly defines the deallocate and memsize functions for Ruby's garbage collection system, following established patterns in the codebase.


15-19: LGTM! Proper resource cleanup.

The deallocate function correctly calls duckdb_destroy_scalar_function to clean up the DuckDB resource before freeing the memory, following the established pattern for resource management.


21-24: LGTM! Proper memory allocation.

The allocate function uses xcalloc to initialize a zeroed instance and properly wraps it as a Ruby object, consistent with other classes in the codebase.


30-36: LGTM! Proper Ruby class initialization.

The initialization function correctly defines the ScalarFunction class under the existing DuckDB module and associates the custom allocator, following the established pattern.

@suketa suketa merged commit 0314efb into main Jul 15, 2025
38 checks passed
@suketa suketa deleted the feature/scalar_functions branch July 15, 2025 13:00
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