GH-50436: [Ruby] Add ArrowFormat::TimestampArray.new(unit, values)#50445
Conversation
|
|
There was a problem hiding this comment.
Pull request overview
This PR improves the Ruby red-arrow-format API to make it easier to build Arrow timestamp arrays directly from Ruby values by allowing ArrowFormat::TimestampArray.new(unit, values) (via TimestampType.try_convert support), and adds a dedicated unit test for the new initialization behavior.
Changes:
- Add
TimestampType.try_convertsoTimestampArray.newcan accept a unit (and optionally[unit, time_zone]) and build the appropriateTimestampType. - Add
TimestampType#pack_templateso timestamp values can be packed into buffers like other primitive/temporal arrays. - Add a new
TestTimestampArraytest file covering initialization and equality behaviors.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
| ruby/red-arrow-format/lib/arrow-format/type.rb | Adds conversion and packing support for TimestampType needed for TimestampArray.new(unit, values) to work. |
| ruby/red-arrow-format/test/test-timestamp-array.rb | Introduces unit tests for ArrowFormat::TimestampArray initialization and equality semantics. |
| unit = value | ||
| TimestampType.new(unit, nil) | ||
| when Array | ||
| unit, time_zone = value | ||
| TimestampType.new(unit, time_zone) |
| sub_test_case("#initialize") do | ||
| def test_no_null | ||
| values = [ | ||
| @timestamp_2019_11_17_15_09_11, | ||
| @timestamp_2025_12_16_05_33_58, | ||
| ] | ||
| assert_equal(values, | ||
| ArrowFormat::TimestampArray.new(:second, values).to_a) | ||
| end | ||
|
|
||
| def test_mixed | ||
| values = [ | ||
| @timestamp_2019_11_17_15_09_11, | ||
| nil, | ||
| @timestamp_2025_12_16_05_33_58, | ||
| ] | ||
| assert_equal(values, | ||
| ArrowFormat::TimestampArray.new(:second, values).to_a) | ||
| end | ||
| end |
| assert_equal(values, | ||
| ArrowFormat::TimestampArray.new(:second, values).to_a) | ||
| end |
ArrowFormat::Timestamp.new(unit, values)ArrowFormat::TimestampArray.new(unit, values)
9bb1581 to
4ebb2bf
Compare
| assert_equal(values, | ||
| ArrowFormat::TimestampArray.new(:second, values).to_a) | ||
| end |
| def try_convert(value) | ||
| case value | ||
| when Symbol | ||
| unit = value | ||
| new(unit, nil) | ||
| when Array | ||
| unit, time_zone = value | ||
| new(unit, time_zone) | ||
| when self |
4ebb2bf to
07128f7
Compare
| when ::Array | ||
| unit, time_zone = value | ||
| new(unit, time_zone) | ||
| when self |
|
+1 |
|
After merging your PR, Conbench analyzed the 4 benchmarking runs that have been run so far on merge-commit 58a6ea2. There were no benchmark performance regressions. 🎉 The full Conbench report has more details. It also includes information about 3 possible false positives for unstable benchmarks that are known to sometimes produce them. |
Rationale for this change
Building a timestamp Arrow array from Ruby objects is convenient.
What changes are included in this PR?
Accept
ArrowFormat::TimestampArray.new(unit, values).Are these changes tested?
Yes.
Are there any user-facing changes?
Yes.
ArrowFormat::TimestampArray.new(unit, values)#50436