Skip to content

GH-50437: [Ruby] Add ArrowFormat::*IntervalArray.new(values)#50459

Merged
kou merged 1 commit into
apache:mainfrom
kou:ruby-interval-array-new
Jul 10, 2026
Merged

GH-50437: [Ruby] Add ArrowFormat::*IntervalArray.new(values)#50459
kou merged 1 commit into
apache:mainfrom
kou:ruby-interval-array-new

Conversation

@kou

@kou kou commented Jul 10, 2026

Copy link
Copy Markdown
Member

Rationale for this change

Building a year month/day time/month day nano interval Arrow array from Ruby objects is convenient.

What changes are included in this PR?

  • Accept ArrowFormat::YearMonthIntervalArray.new(values)
  • Accept ArrowFormat::DayTimetntervalArray.new(values)
  • Add ArrowFormat::DayTimeIntervalArray#each
  • Accept ArrowFormat::MonthDayNanoIntervalArray.new(values)
  • Add ArrowFormat::MonthDayNanoIntervalArray#each

Are these changes tested?

Yes.

Are there any user-facing changes?

Yes.

@github-actions

Copy link
Copy Markdown

⚠️ GitHub issue #50437 has been automatically assigned in GitHub to PR creator.

Copilot AI review requested due to automatic review settings July 10, 2026 01:28
@kou
kou force-pushed the ruby-interval-array-new branch from 23de210 to 4983f2d Compare July 10, 2026 01:28

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Adds Ruby ArrowFormat::*IntervalArray.new(values) convenience constructors for Arrow interval arrays, enabling simpler creation of year-month, day-time, and month-day-nano interval arrays from Ruby value collections.

Changes:

  • Added interval type pack_template support and updated interval Type#build_array to construct arrays without passing an explicit type instance.
  • Added .type singleton hooks on interval array classes to support .new(values) construction.
  • Added custom #each (and packing helpers) for day-time and month-day-nano interval arrays, plus new test coverage for interval-array initialization and equality.

Reviewed changes

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

Show a summary per file
File Description
ruby/red-arrow-format/lib/arrow-format/type.rb Adds pack_template for interval types and updates build_array to align with .new(values) constructors.
ruby/red-arrow-format/lib/arrow-format/array.rb Refactors packing to use pack_value and adds interval-specific #each/packing behavior.
ruby/red-arrow-format/test/test-year-month-interval-array.rb Adds tests for year-month interval array initialization and equality.
ruby/red-arrow-format/test/test-day-time-interval-array.rb Adds tests for day-time interval array initialization and equality.
ruby/red-arrow-format/test/test-month-day-nano-interval-array.rb Adds tests for month-day-nano interval array initialization and equality.

Comment on lines +286 to +288
def pack_value(value, template)
[value || 0].pack(template)
end
assert_not_equal(array1, array2.slice(1, 3))
end
end
end
assert_not_equal(array1, array2.slice(1, 3))
end
end
end
@kou
kou force-pushed the ruby-interval-array-new branch from 4983f2d to de8ba54 Compare July 10, 2026 01:50
Copilot AI review requested due to automatic review settings July 10, 2026 01:50

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

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 on lines 498 to +503
class YearMonthIntervalArray < IntervalArray
class << self
def type
YearMonthIntervalType.singleton
end
end
Comment on lines +526 to +531
def each(&block)
return to_enum(__method__) {@size} unless block_given?

each_value = Enumerator.new(@size) do |yielder|
offset = element_size * @offset
@values_buffer.

@Reranko05 Reranko05 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Would it make sense to add dedicated #each tests for DayTimeIntervalArray and MonthDayNanoIntervalArray, or is to_a coverage sufficient?

@Reranko05

Copy link
Copy Markdown
Contributor

Accept ArrowFormat::DayTimetntervalArray.new(values)

Accept ArrowFormat::DayTimeIntervalArray.new(values) is misspelled in the PR description.

@kou

kou commented Jul 10, 2026

Copy link
Copy Markdown
Member Author

Would it make sense to add dedicated #each tests for DayTimeIntervalArray and MonthDayNanoIntervalArray, or is to_a coverage sufficient?

It should be covered by sliced == test.

@kou

kou commented Jul 10, 2026

Copy link
Copy Markdown
Member Author

Accept ArrowFormat::DayTimetntervalArray.new(values)

Accept ArrowFormat::DayTimeIntervalArray.new(values) is misspelled in the PR description.

Good catch! I've fixed it.

@kou

kou commented Jul 10, 2026

Copy link
Copy Markdown
Member Author

I'll merge this.

@kou
kou merged commit eea7369 into apache:main Jul 10, 2026
35 checks passed
@kou kou removed the awaiting committer review Awaiting committer review label Jul 10, 2026
@kou
kou deleted the ruby-interval-array-new branch July 10, 2026 04:35
@conbench-apache-arrow

Copy link
Copy Markdown

After merging your PR, Conbench analyzed the 4 benchmarking runs that have been run so far on merge-commit eea7369.

There were no benchmark performance regressions. 🎉

The full Conbench report has more details. It also includes information about 1 possible false positive for unstable benchmarks that are known to sometimes produce them.

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.

3 participants