Skip to content

feat: add DuckDB::LogicalType.create_map to create a map logical type#1194

Merged
suketa merged 1 commit intosuketa:mainfrom
otegami:feature/create-map-type
Mar 28, 2026
Merged

feat: add DuckDB::LogicalType.create_map to create a map logical type#1194
suketa merged 1 commit intosuketa:mainfrom
otegami:feature/create-map-type

Conversation

@otegami
Copy link
Copy Markdown
Contributor

@otegami otegami commented Mar 27, 2026

refs: GH-940

In this PR, we add DuckDB::LogicalType.create_map to create a map logical type by wrapping the following C API:

The method accepts either symbols (e.g., :integer, :varchar) or DuckDB::LogicalType instances for both key and value types.

This is one of the steps for supporting the duckdb_create_xxxx_type C APIs.

Summary by CodeRabbit

  • New Features

    • Added a public API to create map logical types with customizable key and value types.
  • Tests

    • Added unit tests covering successful map type creation (via type objects and symbols) and error handling when invalid key/value types are provided.

@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Mar 27, 2026

📝 Walkthrough

Walkthrough

Adds a public Ruby factory DuckDB::LogicalType.create_map, a private C extension singleton _create_map_type that calls duckdb_create_map_type, unit tests for success and failure cases, and a changelog entry documenting the new API. (39 words)

Changes

Cohort / File(s) Summary
Changelog
CHANGELOG.md
Added entry documenting the new public API DuckDB::LogicalType.create_map.
C Extension Binding
ext/duckdb/logical_type.c
Added private singleton _create_map_type(key_type, value_type) that unwraps Ruby LogicalTypes, calls duckdb_create_map_type, raises eDuckDBError on NULL, returns a wrapped LogicalType, and registered it at init.
Ruby Wrapper
lib/duckdb/logical_type.rb
Added public factory DuckDB::LogicalType.create_map(key_type, value_type) which resolves inputs via LogicalType.resolve and delegates to _create_map_type.
Unit Tests
test/duckdb_test/logical_type_test.rb
Added tests for successful map creation (using constants and symbols) and negative tests asserting DuckDB::Error for invalid key/value type symbols.

Sequence Diagram(s)

sequenceDiagram
  participant Ruby as Ruby (caller)
  participant Ext as C extension (ext/duckdb/logical_type.c)
  participant DuckDB as DuckDB C API

  Ruby->>Ext: LogicalType.create_map(key_type, value_type)
  Ext-->>Ruby: call LogicalType.resolve (for each arg)
  Ruby->>Ext: resolved key_type, value_type
  Ext->>DuckDB: duckdb_create_map_type(key, value)
  DuckDB-->>Ext: duckdb_logical_type* (or NULL)
  alt success
    Ext-->>Ruby: wrapped DuckDB::LogicalType(:map)
  else failure
    Ext-->>Ruby: raise eDuckDBError("Failed to create map type")
  end
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related issues

Possibly related PRs

Suggested reviewers

  • suketa

Poem

🐇
I hopped from C into Ruby land,
With key and value paw in hand.
A map now springs from binding art,
Wrapped and ready—fluttering heart!

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 30.77% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately and concisely describes the main change: adding a public factory method DuckDB::LogicalType.create_map for creating map logical types, which is the primary feature across all modified files.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ 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 and usage tips.

@otegami otegami force-pushed the feature/create-map-type branch from 96ba26d to ff7c0b1 Compare March 27, 2026 04:47
Copy link
Copy Markdown

@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.

🧹 Nitpick comments (1)
ext/duckdb/logical_type.c (1)

28-28: Prefix the new C symbol with rbduckdb_ for convention compliance.

The newly added symbol duckdb_logical_type_s_create_map_type should follow the project’s C symbol prefix convention.

♻️ Suggested rename
-static VALUE duckdb_logical_type_s_create_map_type(VALUE klass, VALUE key, VALUE value);
+static VALUE rbduckdb_logical_type_s_create_map_type(VALUE klass, VALUE key, VALUE value);
...
-static VALUE duckdb_logical_type_s_create_map_type(VALUE klass, VALUE key, VALUE value) {
+static VALUE rbduckdb_logical_type_s_create_map_type(VALUE klass, VALUE key, VALUE value) {
...
-    rb_define_private_method(rb_singleton_class(cDuckDBLogicalType), "_create_map_type",
-                             duckdb_logical_type_s_create_map_type, 2);
+    rb_define_private_method(rb_singleton_class(cDuckDBLogicalType), "_create_map_type",
+                             rbduckdb_logical_type_s_create_map_type, 2);

As per coding guidelines, C symbols must be prefixed with rbduckdb_ to avoid namespace conflicts.

Also applies to: 475-491, 535-536

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@ext/duckdb/logical_type.c` at line 28, Rename the C symbol
duckdb_logical_type_s_create_map_type to follow project convention by prefixing
it with rbduckdb_ (e.g., rbduckdb_logical_type_s_create_map_type), and update
all declarations, definitions, and call sites to use the new name; also apply
the same rbduckdb_ prefix to the other newly added/related symbols called out in
the review so all C symbols in this file consistently follow the rbduckdb_
naming convention.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@ext/duckdb/logical_type.c`:
- Line 28: Rename the C symbol duckdb_logical_type_s_create_map_type to follow
project convention by prefixing it with rbduckdb_ (e.g.,
rbduckdb_logical_type_s_create_map_type), and update all declarations,
definitions, and call sites to use the new name; also apply the same rbduckdb_
prefix to the other newly added/related symbols called out in the review so all
C symbols in this file consistently follow the rbduckdb_ naming convention.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 6bd164be-142d-4c4f-8ed6-853696a29afa

📥 Commits

Reviewing files that changed from the base of the PR and between 7e86731 and 96ba26d.

📒 Files selected for processing (4)
  • CHANGELOG.md
  • ext/duckdb/logical_type.c
  • lib/duckdb/logical_type.rb
  • test/duckdb_test/logical_type_test.rb

Copy link
Copy Markdown
Owner

@suketa suketa left a comment

Choose a reason for hiding this comment

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

Thank you. Pls resolve conflicts. code and test are LGTM.

refs: suketaGH-940

In this PR, we add `DuckDB::LogicalType.create_map` to create
a map logical type by wrapping the following C API:

- [duckdb_logical_type duckdb_create_map_type(duckdb_logical_type key_type, duckdb_logical_type value_type);](https://duckdb.org/docs/stable/clients/c/api#duckdb_create_map_type)

The method accepts either symbols (e.g., `:integer`, `:varchar`) or
`DuckDB::LogicalType` instances for both key and value types.

This is one of the steps for supporting the duckdb_create_xxxx_type C APIs.
@otegami otegami force-pushed the feature/create-map-type branch from ff7c0b1 to 601f0a1 Compare March 28, 2026 02:29
@otegami
Copy link
Copy Markdown
Contributor Author

otegami commented Mar 28, 2026

@suketa Thank you so much for reviewing it. I've just resolved it.

Copy link
Copy Markdown

@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: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@ext/duckdb/logical_type.c`:
- Line 28: Rename the public symbol to follow the extension convention (prefix
with rbduckdb_)—e.g., change duckdb_logical_type_s_create_map_type to
rbduckdb_logical_type_s_create_map_type—and replace direct rb_raise calls in
this entrypoint with the error helper exported from error.c (use that helper to
raise/format errors consistently). Also audit the other
non-prefixed/error-raising entrypoints referenced in the review (the other
logical-type factory functions near the same changes) and apply the same rename
+ error-helper replacement so all logical_type factories use rbduckdb_ prefixes
and the centralized error helper.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 64d103e5-b188-4a4e-bc4c-f87e8367354e

📥 Commits

Reviewing files that changed from the base of the PR and between ff7c0b1 and 601f0a1.

📒 Files selected for processing (4)
  • CHANGELOG.md
  • ext/duckdb/logical_type.c
  • lib/duckdb/logical_type.rb
  • test/duckdb_test/logical_type_test.rb
✅ Files skipped from review due to trivial changes (1)
  • CHANGELOG.md
🚧 Files skipped from review as they are similar to previous changes (1)
  • lib/duckdb/logical_type.rb

static VALUE duckdb_logical_type__set_alias(VALUE self, VALUE aname);
static VALUE duckdb_logical_type_s_create_array_type(VALUE klass, VALUE child, VALUE array_size);
static VALUE duckdb_logical_type_s_create_list_type(VALUE klass, VALUE child);
static VALUE duckdb_logical_type_s_create_map_type(VALUE klass, VALUE key, VALUE value);
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟡 Minor

Align the new map factory with C-extension conventions.

The new entrypoint uses a non-rbduckdb_ symbol name and raises directly via rb_raise. Please align with the extension conventions (prefixed symbol + error helper from error.c).

Suggested rename diff (symbol prefix consistency)
-static VALUE duckdb_logical_type_s_create_map_type(VALUE klass, VALUE key, VALUE value);
+static VALUE rbduckdb_logical_type_s_create_map_type(VALUE klass, VALUE key, VALUE value);
...
-static VALUE duckdb_logical_type_s_create_map_type(VALUE klass, VALUE key, VALUE value) {
+static VALUE rbduckdb_logical_type_s_create_map_type(VALUE klass, VALUE key, VALUE value) {
...
-    rb_define_private_method(rb_singleton_class(cDuckDBLogicalType), "_create_map_type",
-                             duckdb_logical_type_s_create_map_type, 2);
+    rb_define_private_method(rb_singleton_class(cDuckDBLogicalType), "_create_map_type",
+                             rbduckdb_logical_type_s_create_map_type, 2);

As per coding guidelines ext/duckdb/**/*.c: “C symbols must be prefixed with rbduckdb_ to avoid namespace conflicts” and “Use rb_raise for errors in C extension, wrapped in error.c helpers”.

Also applies to: 481-488, 535-536

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@ext/duckdb/logical_type.c` at line 28, Rename the public symbol to follow the
extension convention (prefix with rbduckdb_)—e.g., change
duckdb_logical_type_s_create_map_type to
rbduckdb_logical_type_s_create_map_type—and replace direct rb_raise calls in
this entrypoint with the error helper exported from error.c (use that helper to
raise/format errors consistently). Also audit the other
non-prefixed/error-raising entrypoints referenced in the review (the other
logical-type factory functions near the same changes) and apply the same rename
+ error-helper replacement so all logical_type factories use rbduckdb_ prefixes
and the centralized error helper.

Copy link
Copy Markdown
Owner

@suketa suketa left a comment

Choose a reason for hiding this comment

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

Thank you. LGTM

@suketa suketa merged commit 32dc5ce into suketa:main Mar 28, 2026
57 of 58 checks passed
@otegami otegami deleted the feature/create-map-type branch March 28, 2026 05:12
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