From e56726c161df1d588f2f6197dbdd0c0011f14855 Mon Sep 17 00:00:00 2001 From: takuya kodama Date: Mon, 11 Sep 2023 13:04:22 +0800 Subject: [PATCH] GH-37562: [Ruby] Add support for table.each_raw_record.to_a (#37600) ### Rationale for this change This change aligns the behavior of `each_raw_record` with standard Ruby practices by returning an enumerator when no block is provided ### What changes are included in this PR? - Made `Arrow::Table#each_raw_record` and `Arrow::RecordBatch#each_raw_record` return Enumerator when it was called without block. - Added related tests - Resolved warnings related to duplicate test classes which were caused by #37137 ### Are these changes tested? Yes. ### Are there any user-facing changes? No * Closes: #37562 Authored-by: otegami Signed-off-by: Sutou Kouhei --- ruby/red-arrow/ext/arrow/raw-records.cpp | 4 +- .../test/each-raw-record/test-basic-arrays.rb | 180 +++------------ .../each-raw-record/test-dense-union-array.rb | 210 +++-------------- .../each-raw-record/test-dictionary-array.rb | 176 +++----------- .../test/each-raw-record/test-list-array.rb | 213 +++-------------- .../test/each-raw-record/test-map-array.rb | 210 +++-------------- .../each-raw-record/test-multiple-columns.rb | 12 +- .../test-sparse-union-array.rb | 208 +++-------------- .../test/each-raw-record/test-struct-array.rb | 218 ++++-------------- .../test/each-raw-record/test-table.rb | 6 +- 10 files changed, 247 insertions(+), 1190 deletions(-) diff --git a/ruby/red-arrow/ext/arrow/raw-records.cpp b/ruby/red-arrow/ext/arrow/raw-records.cpp index 0043ca3aaf2cc..bbe421971d11a 100644 --- a/ruby/red-arrow/ext/arrow/raw-records.cpp +++ b/ruby/red-arrow/ext/arrow/raw-records.cpp @@ -305,9 +305,10 @@ namespace red_arrow { } VALUE - record_batch_each_raw_record(VALUE rb_record_batch){ + record_batch_each_raw_record(VALUE rb_record_batch) { auto garrow_record_batch = GARROW_RECORD_BATCH(RVAL2GOBJ(rb_record_batch)); auto record_batch = garrow_record_batch_get_raw(garrow_record_batch).get(); + RETURN_SIZED_ENUMERATOR(rb_record_batch, 0, nullptr, record_batch->num_rows()); try { RawRecordsProducer producer; @@ -323,6 +324,7 @@ namespace red_arrow { table_each_raw_record(VALUE rb_table) { auto garrow_table = GARROW_TABLE(RVAL2GOBJ(rb_table)); auto table = garrow_table_get_raw(garrow_table).get(); + RETURN_SIZED_ENUMERATOR(rb_table, 0, nullptr, table->num_rows()); try { RawRecordsProducer producer; diff --git a/ruby/red-arrow/test/each-raw-record/test-basic-arrays.rb b/ruby/red-arrow/test/each-raw-record/test-basic-arrays.rb index dbbbd79ee0acb..d32031dec4ec0 100644 --- a/ruby/red-arrow/test/each-raw-record/test-basic-arrays.rb +++ b/ruby/red-arrow/test/each-raw-record/test-basic-arrays.rb @@ -22,12 +22,8 @@ def test_null [nil], [nil], ] - iterated_records = [] target = build({column: :null}, records) - target.each_raw_record do |record| - iterated_records << record - end - assert_equal(records, iterated_records) + assert_equal(records, target.each_raw_record.to_a) end def test_boolean @@ -36,12 +32,8 @@ def test_boolean [nil], [false], ] - iterated_records = [] target = build({column: :boolean}, records) - target.each_raw_record do |record| - iterated_records << record - end - assert_equal(records, iterated_records) + assert_equal(records, target.each_raw_record.to_a) end def test_int8 @@ -50,12 +42,8 @@ def test_int8 [nil], [(2 ** 7) - 1], ] - iterated_records = [] target = build({column: :int8}, records) - target.each_raw_record do |record| - iterated_records << record - end - assert_equal(records, iterated_records) + assert_equal(records, target.each_raw_record.to_a) end def test_uint8 @@ -64,12 +52,8 @@ def test_uint8 [nil], [(2 ** 8) - 1], ] - iterated_records = [] target = build({column: :uint8}, records) - target.each_raw_record do |record| - iterated_records << record - end - assert_equal(records, iterated_records) + assert_equal(records, target.each_raw_record.to_a) end def test_int16 @@ -78,12 +62,8 @@ def test_int16 [nil], [(2 ** 15) - 1], ] - iterated_records = [] target = build({column: :int16}, records) - target.each_raw_record do |record| - iterated_records << record - end - assert_equal(records, iterated_records) + assert_equal(records, target.each_raw_record.to_a) end def test_uint16 @@ -92,12 +72,8 @@ def test_uint16 [nil], [(2 ** 16) - 1], ] - iterated_records = [] target = build({column: :uint16}, records) - target.each_raw_record do |record| - iterated_records << record - end - assert_equal(records, iterated_records) + assert_equal(records, target.each_raw_record.to_a) end def test_int32 @@ -106,12 +82,8 @@ def test_int32 [nil], [(2 ** 31) - 1], ] - iterated_records = [] target = build({column: :int32}, records) - target.each_raw_record do |record| - iterated_records << record - end - assert_equal(records, iterated_records) + assert_equal(records, target.each_raw_record.to_a) end def test_uint32 @@ -120,12 +92,8 @@ def test_uint32 [nil], [(2 ** 32) - 1], ] - iterated_records = [] target = build({column: :uint32}, records) - target.each_raw_record do |record| - iterated_records << record - end - assert_equal(records, iterated_records) + assert_equal(records, target.each_raw_record.to_a) end def test_int64 @@ -134,12 +102,8 @@ def test_int64 [nil], [(2 ** 63) - 1], ] - iterated_records = [] target = build({column: :int64}, records) - target.each_raw_record do |record| - iterated_records << record - end - assert_equal(records, iterated_records) + assert_equal(records, target.each_raw_record.to_a) end def test_uint64 @@ -148,12 +112,8 @@ def test_uint64 [nil], [(2 ** 64) - 1], ] - iterated_records = [] target = build({column: :uint64}, records) - target.each_raw_record do |record| - iterated_records << record - end - assert_equal(records, iterated_records) + assert_equal(records, target.each_raw_record.to_a) end def test_half_float @@ -162,12 +122,8 @@ def test_half_float [nil], [1.5], ] - iterated_records = [] target = build({column: :half_float}, records) - target.each_raw_record do |record| - iterated_records << record - end - assert_equal(records, iterated_records) + assert_equal(records, target.each_raw_record.to_a) end def test_float @@ -176,12 +132,8 @@ def test_float [nil], [1.0], ] - iterated_records = [] target = build({column: :float}, records) - target.each_raw_record do |record| - iterated_records << record - end - assert_equal(records, iterated_records) + assert_equal(records, target.each_raw_record.to_a) end def test_double @@ -190,12 +142,8 @@ def test_double [nil], [1.0], ] - iterated_records = [] target = build({column: :double}, records) - target.each_raw_record do |record| - iterated_records << record - end - assert_equal(records, iterated_records) + assert_equal(records, target.each_raw_record.to_a) end def test_binary @@ -204,12 +152,8 @@ def test_binary [nil], ["\xff".b], ] - iterated_records = [] target = build({column: :binary}, records) - target.each_raw_record do |record| - iterated_records << record - end - assert_equal(records, iterated_records) + assert_equal(records, target.each_raw_record.to_a) end def test_string @@ -218,12 +162,8 @@ def test_string [nil], ["\u3042"], # U+3042 HIRAGANA LETTER A ] - iterated_records = [] target = build({column: :string}, records) - target.each_raw_record do |record| - iterated_records << record - end - assert_equal(records, iterated_records) + assert_equal(records, target.each_raw_record.to_a) end def test_date32 @@ -232,12 +172,8 @@ def test_date32 [nil], [Date.new(2017, 8, 23)], ] - iterated_records = [] target = build({column: :date32}, records) - target.each_raw_record do |record| - iterated_records << record - end - assert_equal(records, iterated_records) + assert_equal(records, target.each_raw_record.to_a) end def test_date64 @@ -246,12 +182,8 @@ def test_date64 [nil], [DateTime.new(2017, 8, 23, 14, 57, 2)], ] - iterated_records = [] target = build({column: :date64}, records) - target.each_raw_record do |record| - iterated_records << record - end - assert_equal(records, iterated_records) + assert_equal(records, target.each_raw_record.to_a) end def test_timestamp_second @@ -260,7 +192,6 @@ def test_timestamp_second [nil], [Time.parse("2017-08-23T14:57:02Z")], ] - iterated_records = [] target = build({ column: { type: :timestamp, @@ -268,10 +199,7 @@ def test_timestamp_second } }, records) - target.each_raw_record do |record| - iterated_records << record - end - assert_equal(records, iterated_records) + assert_equal(records, target.each_raw_record.to_a) end def test_timestamp_milli @@ -280,7 +208,6 @@ def test_timestamp_milli [nil], [Time.parse("2017-08-23T14:57:02.987Z")], ] - iterated_records = [] target = build({ column: { type: :timestamp, @@ -288,10 +215,7 @@ def test_timestamp_milli } }, records) - target.each_raw_record do |record| - iterated_records << record - end - assert_equal(records, iterated_records) + assert_equal(records, target.each_raw_record.to_a) end def test_timestamp_micro @@ -300,7 +224,6 @@ def test_timestamp_micro [nil], [Time.parse("2017-08-23T14:57:02.987654Z")], ] - iterated_records = [] target = build({ column: { type: :timestamp, @@ -308,10 +231,7 @@ def test_timestamp_micro } }, records) - target.each_raw_record do |record| - iterated_records << record - end - assert_equal(records, iterated_records) + assert_equal(records, target.each_raw_record.to_a) end def test_timestamp_nano @@ -320,7 +240,6 @@ def test_timestamp_nano [nil], [Time.parse("2017-08-23T14:57:02.987654321Z")], ] - iterated_records = [] target = build({ column: { type: :timestamp, @@ -328,10 +247,7 @@ def test_timestamp_nano } }, records) - target.each_raw_record do |record| - iterated_records << record - end - assert_equal(records, iterated_records) + assert_equal(records, target.each_raw_record.to_a) end def test_time32_second @@ -341,7 +257,6 @@ def test_time32_second [nil], [Arrow::Time.new(unit, 60 * 60 * 2 + 9)], # 02:00:09 ] - iterated_records = [] target = build({ column: { type: :time32, @@ -349,10 +264,7 @@ def test_time32_second } }, records) - target.each_raw_record do |record| - iterated_records << record - end - assert_equal(records, iterated_records) + assert_equal(records, target.each_raw_record.to_a) end def test_time32_milli @@ -362,7 +274,6 @@ def test_time32_milli [nil], [Arrow::Time.new(unit, (60 * 60 * 2 + 9) * 1000 + 987)], # 02:00:09.987 ] - iterated_records = [] target = build({ column: { type: :time32, @@ -370,10 +281,7 @@ def test_time32_milli } }, records) - target.each_raw_record do |record| - iterated_records << record - end - assert_equal(records, iterated_records) + assert_equal(records, target.each_raw_record.to_a) end def test_time64_micro @@ -385,7 +293,6 @@ def test_time64_micro # 02:00:09.987654 [Arrow::Time.new(unit, (60 * 60 * 2 + 9) * 1_000_000 + 987_654)], ] - iterated_records = [] target = build({ column: { type: :time64, @@ -393,10 +300,7 @@ def test_time64_micro } }, records) - target.each_raw_record do |record| - iterated_records << record - end - assert_equal(records, iterated_records) + assert_equal(records, target.each_raw_record.to_a) end def test_time64_nano @@ -408,7 +312,6 @@ def test_time64_nano # 02:00:09.987654321 [Arrow::Time.new(unit, (60 * 60 * 2 + 9) * 1_000_000_000 + 987_654_321)], ] - iterated_records = [] target = build({ column: { type: :time64, @@ -416,10 +319,7 @@ def test_time64_nano } }, records) - target.each_raw_record do |record| - iterated_records << record - end - assert_equal(records, iterated_records) + assert_equal(records, target.each_raw_record.to_a) end def test_decimal128 @@ -428,7 +328,6 @@ def test_decimal128 [nil], [BigDecimal("29.29")], ] - iterated_records = [] target = build({ column: { type: :decimal128, @@ -437,10 +336,7 @@ def test_decimal128 } }, records) - target.each_raw_record do |record| - iterated_records << record - end - assert_equal(records, iterated_records) + assert_equal(records, target.each_raw_record.to_a) end def test_decimal256 @@ -449,7 +345,6 @@ def test_decimal256 [nil], [BigDecimal("29.29")], ] - iterated_records = [] target = build({ column: { type: :decimal256, @@ -458,10 +353,7 @@ def test_decimal256 } }, records) - target.each_raw_record do |record| - iterated_records << record - end - assert_equal(records, iterated_records) + assert_equal(records, target.each_raw_record.to_a) end def test_month_interval @@ -470,12 +362,8 @@ def test_month_interval [nil], [12], ] - iterated_records = [] target = build({column: :month_interval}, records) - target.each_raw_record do |record| - iterated_records << record - end - assert_equal(records, iterated_records) + assert_equal(records, target.each_raw_record.to_a) end def test_day_time_interval @@ -484,12 +372,8 @@ def test_day_time_interval [nil], [{day: 2, millisecond: 300}], ] - iterated_records = [] target = build({column: :day_time_interval}, records) - target.each_raw_record do |record| - iterated_records << record - end - assert_equal(records, iterated_records) + assert_equal(records, target.each_raw_record.to_a) end def test_month_day_nano_interval @@ -498,12 +382,8 @@ def test_month_day_nano_interval [nil], [{month: 2, day: 3, nanosecond: 400}], ] - iterated_records = [] target = build({column: :month_day_nano_interval}, records) - target.each_raw_record do |record| - iterated_records << record - end - assert_equal(records, iterated_records) + assert_equal(records, target.each_raw_record.to_a) end end diff --git a/ruby/red-arrow/test/each-raw-record/test-dense-union-array.rb b/ruby/red-arrow/test/each-raw-record/test-dense-union-array.rb index 7c784cccde3a1..b75ce4b4e00d5 100644 --- a/ruby/red-arrow/test/each-raw-record/test-dense-union-array.rb +++ b/ruby/red-arrow/test/each-raw-record/test-dense-union-array.rb @@ -92,13 +92,9 @@ def test_null records = [ [{"0" => nil}], ] - iterated_records = [] target = build(:null, records) - target.each_raw_record do |record| - iterated_records << record - end assert_equal(remove_field_names(records), - iterated_records) + target.each_raw_record.to_a) end def test_boolean @@ -106,13 +102,9 @@ def test_boolean [{"0" => true}], [{"1" => nil}], ] - iterated_records = [] target = build(:boolean, records) - target.each_raw_record do |record| - iterated_records << record - end assert_equal(remove_field_names(records), - iterated_records) + target.each_raw_record.to_a) end def test_int8 @@ -120,13 +112,9 @@ def test_int8 [{"0" => -(2 ** 7)}], [{"1" => nil}], ] - iterated_records = [] target = build(:int8, records) - target.each_raw_record do |record| - iterated_records << record - end assert_equal(remove_field_names(records), - iterated_records) + target.each_raw_record.to_a) end def test_uint8 @@ -134,13 +122,9 @@ def test_uint8 [{"0" => (2 ** 8) - 1}], [{"1" => nil}], ] - iterated_records = [] target = build(:uint8, records) - target.each_raw_record do |record| - iterated_records << record - end assert_equal(remove_field_names(records), - iterated_records) + target.each_raw_record.to_a) end def test_int16 @@ -148,13 +132,9 @@ def test_int16 [{"0" => -(2 ** 15)}], [{"1" => nil}], ] - iterated_records = [] target = build(:int16, records) - target.each_raw_record do |record| - iterated_records << record - end assert_equal(remove_field_names(records), - iterated_records) + target.each_raw_record.to_a) end def test_uint16 @@ -162,13 +142,9 @@ def test_uint16 [{"0" => (2 ** 16) - 1}], [{"1" => nil}], ] - iterated_records = [] target = build(:uint16, records) - target.each_raw_record do |record| - iterated_records << record - end assert_equal(remove_field_names(records), - iterated_records) + target.each_raw_record.to_a) end def test_int32 @@ -176,13 +152,9 @@ def test_int32 [{"0" => -(2 ** 31)}], [{"1" => nil}], ] - iterated_records = [] target = build(:int32, records) - target.each_raw_record do |record| - iterated_records << record - end assert_equal(remove_field_names(records), - iterated_records) + target.each_raw_record.to_a) end def test_uint32 @@ -190,13 +162,9 @@ def test_uint32 [{"0" => (2 ** 32) - 1}], [{"1" => nil}], ] - iterated_records = [] target = build(:uint32, records) - target.each_raw_record do |record| - iterated_records << record - end assert_equal(remove_field_names(records), - iterated_records) + target.each_raw_record.to_a) end def test_int64 @@ -204,13 +172,9 @@ def test_int64 [{"0" => -(2 ** 63)}], [{"1" => nil}], ] - iterated_records = [] target = build(:int64, records) - target.each_raw_record do |record| - iterated_records << record - end assert_equal(remove_field_names(records), - iterated_records) + target.each_raw_record.to_a) end def test_uint64 @@ -218,13 +182,9 @@ def test_uint64 [{"0" => (2 ** 64) - 1}], [{"1" => nil}], ] - iterated_records = [] target = build(:uint64, records) - target.each_raw_record do |record| - iterated_records << record - end assert_equal(remove_field_names(records), - iterated_records) + target.each_raw_record.to_a) end def test_float @@ -232,13 +192,9 @@ def test_float [{"0" => -1.0}], [{"1" => nil}], ] - iterated_records = [] target = build(:float, records) - target.each_raw_record do |record| - iterated_records << record - end assert_equal(remove_field_names(records), - iterated_records) + target.each_raw_record.to_a) end def test_double @@ -246,13 +202,9 @@ def test_double [{"0" => -1.0}], [{"1" => nil}], ] - iterated_records = [] target = build(:double, records) - target.each_raw_record do |record| - iterated_records << record - end assert_equal(remove_field_names(records), - iterated_records) + target.each_raw_record.to_a) end def test_binary @@ -260,13 +212,9 @@ def test_binary [{"0" => "\xff".b}], [{"1" => nil}], ] - iterated_records = [] target = build(:binary, records) - target.each_raw_record do |record| - iterated_records << record - end assert_equal(remove_field_names(records), - iterated_records) + target.each_raw_record.to_a) end def test_string @@ -274,13 +222,9 @@ def test_string [{"0" => "Ruby"}], [{"1" => nil}], ] - iterated_records = [] target = build(:string, records) - target.each_raw_record do |record| - iterated_records << record - end assert_equal(remove_field_names(records), - iterated_records) + target.each_raw_record.to_a) end def test_date32 @@ -288,13 +232,9 @@ def test_date32 [{"0" => Date.new(1960, 1, 1)}], [{"1" => nil}], ] - iterated_records = [] target = build(:date32, records) - target.each_raw_record do |record| - iterated_records << record - end assert_equal(remove_field_names(records), - target.raw_records) + target.each_raw_record.to_a) end def test_date64 @@ -302,13 +242,9 @@ def test_date64 [{"0" => DateTime.new(1960, 1, 1, 2, 9, 30)}], [{"1" => nil}], ] - iterated_records = [] target = build(:date64, records) - target.each_raw_record do |record| - iterated_records << record - end assert_equal(remove_field_names(records), - iterated_records) + target.each_raw_record.to_a) end def test_timestamp_second @@ -316,17 +252,13 @@ def test_timestamp_second [{"0" => Time.parse("1960-01-01T02:09:30Z")}], [{"1" => nil}], ] - iterated_records = [] target = build({ type: :timestamp, unit: :second, }, records) - target.each_raw_record do |record| - iterated_records << record - end assert_equal(remove_field_names(records), - iterated_records) + target.each_raw_record.to_a) end def test_timestamp_milli @@ -334,17 +266,13 @@ def test_timestamp_milli [{"0" => Time.parse("1960-01-01T02:09:30.123Z")}], [{"1" => nil}], ] - iterated_records = [] target = build({ type: :timestamp, unit: :milli, }, records) - target.each_raw_record do |record| - iterated_records << record - end assert_equal(remove_field_names(records), - iterated_records) + target.each_raw_record.to_a) end def test_timestamp_micro @@ -352,17 +280,13 @@ def test_timestamp_micro [{"0" => Time.parse("1960-01-01T02:09:30.123456Z")}], [{"1" => nil}], ] - iterated_records = [] target = build({ type: :timestamp, unit: :micro, }, records) - target.each_raw_record do |record| - iterated_records << record - end assert_equal(remove_field_names(records), - iterated_records) + target.each_raw_record.to_a) end def test_timestamp_nano @@ -370,17 +294,13 @@ def test_timestamp_nano [{"0" => Time.parse("1960-01-01T02:09:30.123456789Z")}], [{"1" => nil}], ] - iterated_records = [] target = build({ type: :timestamp, unit: :nano, }, records) - target.each_raw_record do |record| - iterated_records << record - end assert_equal(remove_field_names(records), - iterated_records) + target.each_raw_record.to_a) end def test_time32_second @@ -390,17 +310,13 @@ def test_time32_second [{"0" => Arrow::Time.new(unit, 60 * 10)}], [{"1" => nil}], ] - iterated_records = [] target = build({ type: :time32, unit: :second, }, records) - target.each_raw_record do |record| - iterated_records << record - end assert_equal(remove_field_names(records), - iterated_records) + target.each_raw_record.to_a) end def test_time32_milli @@ -410,17 +326,13 @@ def test_time32_milli [{"0" => Arrow::Time.new(unit, (60 * 10) * 1000 + 123)}], [{"1" => nil}], ] - iterated_records = [] target = build({ type: :time32, unit: :milli, }, records) - target.each_raw_record do |record| - iterated_records << record - end assert_equal(remove_field_names(records), - iterated_records) + target.each_raw_record.to_a) end def test_time64_micro @@ -430,17 +342,13 @@ def test_time64_micro [{"0" => Arrow::Time.new(unit, (60 * 10) * 1_000_000 + 123_456)}], [{"1" => nil}], ] - iterated_records = [] target = build({ type: :time64, unit: :micro, }, records) - target.each_raw_record do |record| - iterated_records << record - end assert_equal(remove_field_names(records), - iterated_records) + target.each_raw_record.to_a) end def test_time64_nano @@ -450,17 +358,13 @@ def test_time64_nano [{"0" => Arrow::Time.new(unit, (60 * 10) * 1_000_000_000 + 123_456_789)}], [{"1" => nil}], ] - iterated_records = [] target = build({ type: :time64, unit: :nano, }, records) - target.each_raw_record do |record| - iterated_records << record - end assert_equal(remove_field_names(records), - iterated_records) + target.each_raw_record.to_a) end def test_decimal128 @@ -468,18 +372,14 @@ def test_decimal128 [{"0" => BigDecimal("92.92")}], [{"1" => nil}], ] - iterated_records = [] target = build({ type: :decimal128, precision: 8, scale: 2, }, records) - target.each_raw_record do |record| - iterated_records << record - end assert_equal(remove_field_names(records), - iterated_records) + target.each_raw_record.to_a) end def test_decimal256 @@ -487,18 +387,14 @@ def test_decimal256 [{"0" => BigDecimal("92.92")}], [{"1" => nil}], ] - iterated_records = [] target = build({ type: :decimal256, precision: 38, scale: 2, }, records) - target.each_raw_record do |record| - iterated_records << record - end assert_equal(remove_field_names(records), - iterated_records) + target.each_raw_record.to_a) end def test_month_interval @@ -506,13 +402,9 @@ def test_month_interval [{"0" => 1}], [{"1" => nil}], ] - iterated_records = [] target = build(:month_interval, records) - target.each_raw_record do |record| - iterated_records << record - end assert_equal(remove_field_names(records), - iterated_records) + target.each_raw_record.to_a) end def test_day_time_interval @@ -520,13 +412,9 @@ def test_day_time_interval [{"0" => {day: 1, millisecond: 100}}], [{"1" => nil}], ] - iterated_records = [] target = build(:day_time_interval, records) - target.each_raw_record do |record| - iterated_records << record - end assert_equal(remove_field_names(records), - iterated_records) + target.each_raw_record.to_a) end def test_month_day_nano_interval @@ -534,13 +422,9 @@ def test_month_day_nano_interval [{"0" => {month: 1, day: 1, nanosecond: 100}}], [{"1" => nil}], ] - iterated_records = [] target = build(:month_day_nano_interval, records) - target.each_raw_record do |record| - iterated_records << record - end assert_equal(remove_field_names(records), - iterated_records) + target.each_raw_record.to_a) end def test_list @@ -548,7 +432,6 @@ def test_list [{"0" => [true, nil, false]}], [{"1" => nil}], ] - iterated_records = [] target = build({ type: :list, field: { @@ -557,11 +440,8 @@ def test_list }, }, records) - target.each_raw_record do |record| - iterated_records << record - end assert_equal(remove_field_names(records), - iterated_records) + target.each_raw_record.to_a) end def test_struct @@ -570,7 +450,6 @@ def test_struct [{"1" => nil}], [{"0" => {"sub_field" => nil}}], ] - iterated_records = [] target = build({ type: :struct, fields: [ @@ -581,11 +460,8 @@ def test_struct ], }, records) - target.each_raw_record do |record| - iterated_records << record - end assert_equal(remove_field_names(records), - iterated_records) + target.each_raw_record.to_a) end def test_map @@ -593,18 +469,14 @@ def test_map [{"0" => {"key1" => true, "key2" => nil}}], [{"1" => nil}], ] - iterated_records = [] target = build({ type: :map, key: :string, item: :boolean, }, records) - target.each_raw_record do |record| - iterated_records << record - end assert_equal(remove_field_names(records), - iterated_records) + target.each_raw_record.to_a) end def test_sparse_union @@ -614,7 +486,6 @@ def test_sparse_union [{"0" => {"field2" => 29}}], [{"0" => {"field2" => nil}}], ] - iterated_records = [] target = build({ type: :sparse_union, fields: [ @@ -630,11 +501,8 @@ def test_sparse_union type_codes: [0, 1], }, records) - target.each_raw_record do |record| - iterated_records << record - end assert_equal(remove_field_names(remove_field_names(records)), - iterated_records) + target.each_raw_record.to_a) end def test_dense_union @@ -644,7 +512,6 @@ def test_dense_union [{"0" => {"field2" => 29}}], [{"0" => {"field2" => nil}}], ] - iterated_records = [] target = build({ type: :dense_union, fields: [ @@ -660,11 +527,8 @@ def test_dense_union type_codes: [0, 1], }, records) - target.each_raw_record do |record| - iterated_records << record - end assert_equal(remove_field_names(remove_field_names(records)), - iterated_records) + target.each_raw_record.to_a) end def test_dictionary @@ -673,7 +537,6 @@ def test_dictionary [{"1" => nil}], [{"0" => "GLib"}], ] - iterated_records = [] target = build({ type: :dictionary, index_data_type: :int8, @@ -681,11 +544,8 @@ def test_dictionary ordered: false, }, records) - target.each_raw_record do |record| - iterated_records << record - end assert_equal(remove_field_names(records), - iterated_records) + target.each_raw_record.to_a) end end diff --git a/ruby/red-arrow/test/each-raw-record/test-dictionary-array.rb b/ruby/red-arrow/test/each-raw-record/test-dictionary-array.rb index edc6c33cc091d..f85294b30aab8 100644 --- a/ruby/red-arrow/test/each-raw-record/test-dictionary-array.rb +++ b/ruby/red-arrow/test/each-raw-record/test-dictionary-array.rb @@ -29,12 +29,8 @@ def test_null [nil], [nil], ] - iterated_records = [] target = build(Arrow::NullArray.new(records.collect(&:first))) - target.each_raw_record do |record| - iterated_records << record - end - assert_equal(records, iterated_records) + assert_equal(records, target.each_raw_record.to_a) end def test_boolean @@ -43,12 +39,8 @@ def test_boolean [nil], [false], ] - iterated_records = [] target = build(Arrow::BooleanArray.new(records.collect(&:first))) - target.each_raw_record do |record| - iterated_records << record - end - assert_equal(records, iterated_records) + assert_equal(records, target.each_raw_record.to_a) end def test_int8 @@ -57,12 +49,8 @@ def test_int8 [nil], [(2 ** 7) - 1], ] - iterated_records = [] target = build(Arrow::Int8Array.new(records.collect(&:first))) - target.each_raw_record do |record| - iterated_records << record - end - assert_equal(records, iterated_records) + assert_equal(records, target.each_raw_record.to_a) end def test_uint8 @@ -71,12 +59,8 @@ def test_uint8 [nil], [(2 ** 8) - 1], ] - iterated_records = [] target = build(Arrow::UInt8Array.new(records.collect(&:first))) - target.each_raw_record do |record| - iterated_records << record - end - assert_equal(records, iterated_records) + assert_equal(records, target.each_raw_record.to_a) end def test_int16 @@ -85,12 +69,8 @@ def test_int16 [nil], [(2 ** 15) - 1], ] - iterated_records = [] target = build(Arrow::Int16Array.new(records.collect(&:first))) - target.each_raw_record do |record| - iterated_records << record - end - assert_equal(records, iterated_records) + assert_equal(records, target.each_raw_record.to_a) end def test_uint16 @@ -99,12 +79,8 @@ def test_uint16 [nil], [(2 ** 16) - 1], ] - iterated_records = [] target = build(Arrow::UInt16Array.new(records.collect(&:first))) - target.each_raw_record do |record| - iterated_records << record - end - assert_equal(records, iterated_records) + assert_equal(records, target.each_raw_record.to_a) end def test_int32 @@ -113,12 +89,8 @@ def test_int32 [nil], [(2 ** 31) - 1], ] - iterated_records = [] target = build(Arrow::Int32Array.new(records.collect(&:first))) - target.each_raw_record do |record| - iterated_records << record - end - assert_equal(records, iterated_records) + assert_equal(records, target.each_raw_record.to_a) end def test_uint32 @@ -127,12 +99,8 @@ def test_uint32 [nil], [(2 ** 32) - 1], ] - iterated_records = [] target = build(Arrow::UInt32Array.new(records.collect(&:first))) - target.each_raw_record do |record| - iterated_records << record - end - assert_equal(records, iterated_records) + assert_equal(records, target.each_raw_record.to_a) end def test_int64 @@ -141,12 +109,8 @@ def test_int64 [nil], [(2 ** 63) - 1], ] - iterated_records = [] target = build(Arrow::Int64Array.new(records.collect(&:first))) - target.each_raw_record do |record| - iterated_records << record - end - assert_equal(records, iterated_records) + assert_equal(records, target.each_raw_record.to_a) end def test_uint64 @@ -155,12 +119,8 @@ def test_uint64 [nil], [(2 ** 64) - 1], ] - iterated_records = [] target = build(Arrow::UInt64Array.new(records.collect(&:first))) - target.each_raw_record do |record| - iterated_records << record - end - assert_equal(records, iterated_records) + assert_equal(records, target.each_raw_record.to_a) end def test_float @@ -169,12 +129,8 @@ def test_float [nil], [1.0], ] - iterated_records = [] target = build(Arrow::FloatArray.new(records.collect(&:first))) - target.each_raw_record do |record| - iterated_records << record - end - assert_equal(records, iterated_records) + assert_equal(records, target.each_raw_record.to_a) end def test_double @@ -183,12 +139,8 @@ def test_double [nil], [1.0], ] - iterated_records = [] target = build(Arrow::DoubleArray.new(records.collect(&:first))) - target.each_raw_record do |record| - iterated_records << record - end - assert_equal(records, iterated_records) + assert_equal(records, target.each_raw_record.to_a) end def test_binary @@ -197,12 +149,8 @@ def test_binary [nil], ["\xff".b], ] - iterated_records = [] target = build(Arrow::BinaryArray.new(records.collect(&:first))) - target.each_raw_record do |record| - iterated_records << record - end - assert_equal(records, iterated_records) + assert_equal(records, target.each_raw_record.to_a) end def test_string @@ -211,12 +159,8 @@ def test_string [nil], ["\u3042"], # U+3042 HIRAGANA LETTER A ] - iterated_records = [] - target = build(Arrow::StringArray.new(records.collect(&:first))) - target.each_raw_record do |record| - iterated_records << record - end - assert_equal(records, iterated_records) + target = build(Arrow::StringArray.new(records.collect(&:first))) + assert_equal(records, target.each_raw_record.to_a) end def test_date32 @@ -225,12 +169,8 @@ def test_date32 [nil], [Date.new(2017, 8, 23)], ] - iterated_records = [] target = build(Arrow::Date32Array.new(records.collect(&:first))) - target.each_raw_record do |record| - iterated_records << record - end - assert_equal(records, iterated_records) + assert_equal(records, target.each_raw_record.to_a) end def test_date64 @@ -239,12 +179,8 @@ def test_date64 [nil], [DateTime.new(2017, 8, 23, 14, 57, 2)], ] - iterated_records = [] target = build(Arrow::Date64Array.new(records.collect(&:first))) - target.each_raw_record do |record| - iterated_records << record - end - assert_equal(records, iterated_records) + assert_equal(records, target.each_raw_record.to_a) end def test_timestamp_second @@ -253,12 +189,8 @@ def test_timestamp_second [nil], [Time.parse("2017-08-23T14:57:02Z")], ] - iterated_records = [] target = build(Arrow::TimestampArray.new(:second, records.collect(&:first))) - target.each_raw_record do |record| - iterated_records << record - end - assert_equal(records, iterated_records) + assert_equal(records, target.each_raw_record.to_a) end def test_timestamp_milli @@ -267,12 +199,8 @@ def test_timestamp_milli [nil], [Time.parse("2017-08-23T14:57:02.987Z")], ] - iterated_records = [] target = build(Arrow::TimestampArray.new(:milli, records.collect(&:first))) - target.each_raw_record do |record| - iterated_records << record - end - assert_equal(records, iterated_records) + assert_equal(records, target.each_raw_record.to_a) end def test_timestamp_micro @@ -281,12 +209,8 @@ def test_timestamp_micro [nil], [Time.parse("2017-08-23T14:57:02.987654Z")], ] - iterated_records = [] target = build(Arrow::TimestampArray.new(:micro, records.collect(&:first))) - target.each_raw_record do |record| - iterated_records << record - end - assert_equal(records, iterated_records) + assert_equal(records, target.each_raw_record.to_a) end def test_timestamp_nano @@ -295,12 +219,8 @@ def test_timestamp_nano [nil], [Time.parse("2017-08-23T14:57:02.987654321Z")], ] - iterated_records = [] target = build(Arrow::TimestampArray.new(:nano, records.collect(&:first))) - target.each_raw_record do |record| - iterated_records << record - end - assert_equal(records, iterated_records) + assert_equal(records, target.each_raw_record.to_a) end def test_time32_second @@ -310,12 +230,8 @@ def test_time32_second [nil], [Arrow::Time.new(unit, 60 * 60 * 2 + 9)], # 02:00:09 ] - iterated_records = [] target = build(Arrow::Time32Array.new(unit, records.collect(&:first))) - target.each_raw_record do |record| - iterated_records << record - end - assert_equal(records, iterated_records) + assert_equal(records, target.each_raw_record.to_a) end def test_time32_milli @@ -325,12 +241,8 @@ def test_time32_milli [nil], [Arrow::Time.new(unit, (60 * 60 * 2 + 9) * 1000 + 987)], # 02:00:09.987 ] - iterated_records = [] target = build(Arrow::Time32Array.new(unit, records.collect(&:first))) - target.each_raw_record do |record| - iterated_records << record - end - assert_equal(records, iterated_records) + assert_equal(records, target.each_raw_record.to_a) end def test_time64_micro @@ -342,12 +254,8 @@ def test_time64_micro # 02:00:09.987654 [Arrow::Time.new(unit, (60 * 60 * 2 + 9) * 1_000_000 + 987_654)], ] - iterated_records = [] target = build(Arrow::Time64Array.new(unit, records.collect(&:first))) - target.each_raw_record do |record| - iterated_records << record - end - assert_equal(records, iterated_records) + assert_equal(records, target.each_raw_record.to_a) end def test_time64_nano @@ -359,12 +267,8 @@ def test_time64_nano # 02:00:09.987654321 [Arrow::Time.new(unit, (60 * 60 * 2 + 9) * 1_000_000_000 + 987_654_321)], ] - iterated_records = [] target = build(Arrow::Time64Array.new(unit, records.collect(&:first))) - target.each_raw_record do |record| - iterated_records << record - end - assert_equal(records, iterated_records) + assert_equal(records, target.each_raw_record.to_a) end def test_decimal128 @@ -373,13 +277,9 @@ def test_decimal128 [nil], [BigDecimal("29.29")], ] - iterated_records = [] data_type = Arrow::Decimal128DataType.new(8, 2) target = build(Arrow::Decimal128Array.new(data_type, records.collect(&:first))) - target.each_raw_record do |record| - iterated_records << record - end - assert_equal(records, iterated_records) + assert_equal(records, target.each_raw_record.to_a) end def test_decimal256 @@ -388,13 +288,9 @@ def test_decimal256 [nil], [BigDecimal("29.29")], ] - iterated_records = [] data_type = Arrow::Decimal256DataType.new(38, 2) target = build(Arrow::Decimal256Array.new(data_type, records.collect(&:first))) - target.each_raw_record do |record| - iterated_records << record - end - assert_equal(records, target.raw_records) + assert_equal(records, target.each_raw_record.to_a) end def test_month_interval @@ -403,12 +299,8 @@ def test_month_interval [nil], [12], ] - iterated_records = [] target = build(Arrow::MonthIntervalArray.new(records.collect(&:first))) - target.each_raw_record do |record| - iterated_records << record - end - assert_equal(records, iterated_records) + assert_equal(records, target.each_raw_record.to_a) end def test_day_time_interval @@ -417,12 +309,8 @@ def test_day_time_interval [nil], [{day: 2, millisecond: 300}], ] - iterated_records = [] target = build(Arrow::DayTimeIntervalArray.new(records.collect(&:first))) - target.each_raw_record do |record| - iterated_records << record - end - assert_equal(records, iterated_records) + assert_equal(records, target.each_raw_record.to_a) end def test_month_day_nano_interval @@ -431,12 +319,8 @@ def test_month_day_nano_interval [nil], [{month: 2, day: 3, nanosecond: 400}], ] - iterated_records = [] target = build(Arrow::MonthDayNanoIntervalArray.new(records.collect(&:first))) - target.each_raw_record do |record| - iterated_records << record - end - assert_equal(records, iterated_records) + assert_equal(records, target.each_raw_record.to_a) end end diff --git a/ruby/red-arrow/test/each-raw-record/test-list-array.rb b/ruby/red-arrow/test/each-raw-record/test-list-array.rb index 64cc5839bd757..f6f92abf6679e 100644 --- a/ruby/red-arrow/test/each-raw-record/test-list-array.rb +++ b/ruby/red-arrow/test/each-raw-record/test-list-array.rb @@ -38,12 +38,8 @@ def test_null [[nil, nil, nil]], [nil], ] - iterated_records = [] target = build(:null, records) - target.each_raw_record do |record| - iterated_records << record - end - assert_equal(records, iterated_records) + assert_equal(records, target.each_raw_record.to_a) end def test_boolean @@ -51,12 +47,8 @@ def test_boolean [[true, nil, false]], [nil], ] - iterated_records = [] target = build(:boolean, records) - target.each_raw_record do |record| - iterated_records << record - end - assert_equal(records, iterated_records) + assert_equal(records, target.each_raw_record.to_a) end def test_int8 @@ -64,12 +56,8 @@ def test_int8 [[-(2 ** 7), nil, (2 ** 7) - 1]], [nil], ] - iterated_records = [] target = build(:int8, records) - target.each_raw_record do |record| - iterated_records << record - end - assert_equal(records, iterated_records) + assert_equal(records, target.each_raw_record.to_a) end def test_uint8 @@ -77,12 +65,8 @@ def test_uint8 [[0, nil, (2 ** 8) - 1]], [nil], ] - iterated_records = [] target = build(:uint8, records) - target.each_raw_record do |record| - iterated_records << record - end - assert_equal(records, iterated_records) + assert_equal(records, target.each_raw_record.to_a) end def test_int16 @@ -90,12 +74,8 @@ def test_int16 [[-(2 ** 15), nil, (2 ** 15) - 1]], [nil], ] - iterated_records = [] target = build(:int16, records) - target.each_raw_record do |record| - iterated_records << record - end - assert_equal(records, iterated_records) + assert_equal(records, target.each_raw_record.to_a) end def test_uint16 @@ -103,12 +83,8 @@ def test_uint16 [[0, nil, (2 ** 16) - 1]], [nil], ] - iterated_records = [] target = build(:uint16, records) - target.each_raw_record do |record| - iterated_records << record - end - assert_equal(records, iterated_records) + assert_equal(records, target.each_raw_record.to_a) end def test_int32 @@ -116,12 +92,8 @@ def test_int32 [[-(2 ** 31), nil, (2 ** 31) - 1]], [nil], ] - iterated_records = [] target = build(:int32, records) - target.each_raw_record do |record| - iterated_records << record - end - assert_equal(records, iterated_records) + assert_equal(records, target.each_raw_record.to_a) end def test_uint32 @@ -129,12 +101,8 @@ def test_uint32 [[0, nil, (2 ** 32) - 1]], [nil], ] - iterated_records = [] target = build(:uint32, records) - target.each_raw_record do |record| - iterated_records << record - end - assert_equal(records, iterated_records) + assert_equal(records, target.each_raw_record.to_a) end def test_int64 @@ -142,12 +110,8 @@ def test_int64 [[-(2 ** 63), nil, (2 ** 63) - 1]], [nil], ] - iterated_records = [] target = build(:int64, records) - target.each_raw_record do |record| - iterated_records << record - end - assert_equal(records, iterated_records) + assert_equal(records, target.each_raw_record.to_a) end def test_uint64 @@ -155,12 +119,8 @@ def test_uint64 [[0, nil, (2 ** 64) - 1]], [nil], ] - iterated_records = [] target = build(:uint64, records) - target.each_raw_record do |record| - iterated_records << record - end - assert_equal(records, iterated_records) + assert_equal(records, target.each_raw_record.to_a) end def test_float @@ -168,12 +128,8 @@ def test_float [[-1.0, nil, 1.0]], [nil], ] - iterated_records = [] target = build(:float, records) - target.each_raw_record do |record| - iterated_records << record - end - assert_equal(records, iterated_records) + assert_equal(records, target.each_raw_record.to_a) end def test_double @@ -181,12 +137,8 @@ def test_double [[-1.0, nil, 1.0]], [nil], ] - iterated_records = [] target = build(:double, records) - target.each_raw_record do |record| - iterated_records << record - end - assert_equal(records, iterated_records) + assert_equal(records, target.each_raw_record.to_a) end def test_binary @@ -194,12 +146,8 @@ def test_binary [["\x00".b, nil, "\xff".b]], [nil], ] - iterated_records = [] target = build(:binary, records) - target.each_raw_record do |record| - iterated_records << record - end - assert_equal(records, iterated_records) + assert_equal(records, target.each_raw_record.to_a) end def test_string @@ -213,12 +161,8 @@ def test_string ], [nil], ] - iterated_records = [] target = build(:string, records) - target.each_raw_record do |record| - iterated_records << record - end - assert_equal(records, iterated_records) + assert_equal(records, target.each_raw_record.to_a) end def test_date32 @@ -232,12 +176,8 @@ def test_date32 ], [nil], ] - iterated_records = [] target = build(:date32, records) - target.each_raw_record do |record| - iterated_records << record - end - assert_equal(records, iterated_records) + assert_equal(records, target.each_raw_record.to_a) end def test_date64 @@ -251,12 +191,8 @@ def test_date64 ], [nil], ] - iterated_records = [] target = build(:date64, records) - target.each_raw_record do |record| - iterated_records << record - end - assert_equal(records, iterated_records) + assert_equal(records, target.each_raw_record.to_a) end def test_timestamp_second @@ -270,17 +206,12 @@ def test_timestamp_second ], [nil], ] - iterated_records = [] target = build({ type: :timestamp, unit: :second, }, records) - iterated_records = [] - target.each_raw_record do |record| - iterated_records << record - end - assert_equal(records, iterated_records) + assert_equal(records, target.each_raw_record.to_a) end def test_timestamp_milli @@ -294,17 +225,12 @@ def test_timestamp_milli ], [nil], ] - iterated_records = [] target = build({ type: :timestamp, unit: :milli, }, records) - iterated_records = [] - target.each_raw_record do |record| - iterated_records << record - end - assert_equal(records, iterated_records) + assert_equal(records, target.each_raw_record.to_a) end def test_timestamp_micro @@ -318,17 +244,12 @@ def test_timestamp_micro ], [nil], ] - iterated_records = [] target = build({ type: :timestamp, unit: :micro, }, records) - iterated_records = [] - target.each_raw_record do |record| - iterated_records << record - end - assert_equal(records, iterated_records) + assert_equal(records, target.each_raw_record.to_a) end def test_timestamp_nano @@ -342,16 +263,12 @@ def test_timestamp_nano ], [nil], ] - iterated_records = [] target = build({ type: :timestamp, unit: :nano, }, records) - target.each_raw_record do |record| - iterated_records << record - end - assert_equal(records, iterated_records) + assert_equal(records, target.each_raw_record.to_a) end def test_time32_second @@ -368,16 +285,12 @@ def test_time32_second ], [nil], ] - iterated_records = [] target = build({ type: :time32, unit: :second, }, records) - target.each_raw_record do |record| - iterated_records << record - end - assert_equal(records, iterated_records) + assert_equal(records, target.each_raw_record.to_a) end def test_time32_milli @@ -394,16 +307,12 @@ def test_time32_milli ], [nil], ] - iterated_records = [] target = build({ type: :time32, unit: :milli, }, records) - target.each_raw_record do |record| - iterated_records << record - end - assert_equal(records, iterated_records) + assert_equal(records, target.each_raw_record.to_a) end def test_time64_micro @@ -420,16 +329,12 @@ def test_time64_micro ], [nil], ] - iterated_records = [] target = build({ type: :time64, unit: :micro, }, records) - target.each_raw_record do |record| - iterated_records << record - end - assert_equal(records, iterated_records) + assert_equal(records, target.each_raw_record.to_a) end def test_time64_nano @@ -446,16 +351,12 @@ def test_time64_nano ], [nil], ] - iterated_records = [] target = build({ type: :time64, unit: :nano, }, records) - target.each_raw_record do |record| - iterated_records << record - end - assert_equal(records, iterated_records) + assert_equal(records, target.each_raw_record.to_a) end def test_decimal128 @@ -469,17 +370,13 @@ def test_decimal128 ], [nil], ] - iterated_records = [] target = build({ type: :decimal128, precision: 8, scale: 2, }, records) - target.each_raw_record do |record| - iterated_records << record - end - assert_equal(records, iterated_records) + assert_equal(records, target.each_raw_record.to_a) end def test_decimal256 @@ -493,17 +390,13 @@ def test_decimal256 ], [nil], ] - iterated_records = [] target = build({ type: :decimal256, precision: 38, scale: 2, }, records) - target.each_raw_record do |record| - iterated_records << record - end - assert_equal(records, iterated_records) + assert_equal(records, target.each_raw_record.to_a) end def test_month_interval @@ -511,12 +404,8 @@ def test_month_interval [[1, nil, 12]], [nil], ] - iterated_records = [] target = build(:month_interval, records) - target.each_raw_record do |record| - iterated_records << record - end - assert_equal(records, iterated_records) + assert_equal(records, target.each_raw_record.to_a) end def test_day_time_interval @@ -530,12 +419,8 @@ def test_day_time_interval ], [nil], ] - iterated_records = [] target = build(:day_time_interval, records) - target.each_raw_record do |record| - iterated_records << record - end - assert_equal(records, iterated_records) + assert_equal(records, target.each_raw_record.to_a) end def test_month_day_nano_interval @@ -549,12 +434,8 @@ def test_month_day_nano_interval ], [nil], ] - iterated_records = [] target = build(:month_day_nano_interval, records) - target.each_raw_record do |record| - iterated_records << record - end - assert_equal(records, iterated_records) + assert_equal(records, target.each_raw_record.to_a) end def test_list @@ -574,7 +455,6 @@ def test_list ], [nil], ] - iterated_records = [] target = build({ type: :list, field: { @@ -583,10 +463,7 @@ def test_list }, }, records) - target.each_raw_record do |record| - iterated_records << record - end - assert_equal(records, iterated_records) + assert_equal(records, target.each_raw_record.to_a) end def test_struct @@ -600,7 +477,6 @@ def test_struct ], [nil], ] - iterated_records = [] target = build({ type: :struct, fields: [ @@ -611,10 +487,7 @@ def test_struct ], }, records) - target.each_raw_record do |record| - iterated_records << record - end - assert_equal(records, iterated_records) + assert_equal(records, target.each_raw_record.to_a) end def test_map @@ -627,17 +500,13 @@ def test_map ], [nil], ] - iterated_records = [] target = build({ type: :map, key: :string, item: :boolean, }, records) - target.each_raw_record do |record| - iterated_records << record - end - assert_equal(records, iterated_records) + assert_equal(records, target.each_raw_record.to_a) end def remove_union_field_names(records) @@ -670,7 +539,6 @@ def test_sparse_union ], [nil], ] - iterated_records = [] target = build({ type: :sparse_union, fields: [ @@ -686,11 +554,8 @@ def test_sparse_union type_codes: [0, 1], }, records) - target.each_raw_record do |record| - iterated_records << record - end assert_equal(remove_union_field_names(records), - iterated_records) + target.each_raw_record.to_a) end def test_dense_union @@ -705,7 +570,6 @@ def test_dense_union ], [nil], ] - iterated_records = [] target = build({ type: :dense_union, fields: [ @@ -721,11 +585,8 @@ def test_dense_union type_codes: [0, 1], }, records) - target.each_raw_record do |record| - iterated_records << record - end assert_equal(remove_union_field_names(records), - iterated_records) + target.each_raw_record.to_a) end def test_dictionary @@ -739,7 +600,6 @@ def test_dictionary ], [nil], ] - iterated_records = [] target = build({ type: :dictionary, index_data_type: :int8, @@ -747,10 +607,7 @@ def test_dictionary ordered: false, }, records) - target.each_raw_record do |record| - iterated_records << record - end - assert_equal(records, iterated_records) + assert_equal(records, target.each_raw_record.to_a) end end diff --git a/ruby/red-arrow/test/each-raw-record/test-map-array.rb b/ruby/red-arrow/test/each-raw-record/test-map-array.rb index b802275a7f00f..f256543a853e3 100644 --- a/ruby/red-arrow/test/each-raw-record/test-map-array.rb +++ b/ruby/red-arrow/test/each-raw-record/test-map-array.rb @@ -31,12 +31,8 @@ def test_null [{"key1" => nil}], [nil], ] - iterated_records = [] target = build(:null, records) - target.each_raw_record do |record| - iterated_records << record - end - assert_equal(records, iterated_records) + assert_equal(records, target.each_raw_record.to_a) end def test_boolean @@ -44,12 +40,8 @@ def test_boolean [{"key1" => true, "key2" => nil}], [nil], ] - iterated_records = [] target = build(:boolean, records) - target.each_raw_record do |record| - iterated_records << record - end - assert_equal(records, iterated_records) + assert_equal(records, target.each_raw_record.to_a) end def test_int8 @@ -57,12 +49,8 @@ def test_int8 [{"key1" => -(2 ** 7), "key2" => nil}], [nil], ] - iterated_records = [] target = build(:int8, records) - target.each_raw_record do |record| - iterated_records << record - end - assert_equal(records, iterated_records) + assert_equal(records, target.each_raw_record.to_a) end def test_uint8 @@ -70,12 +58,8 @@ def test_uint8 [{"key1" => (2 ** 8) - 1, "key2" => nil}], [nil], ] - iterated_records = [] target = build(:uint8, records) - target.each_raw_record do |record| - iterated_records << record - end - assert_equal(records, iterated_records) + assert_equal(records, target.each_raw_record.to_a) end def test_int16 @@ -83,12 +67,8 @@ def test_int16 [{"key1" => -(2 ** 15), "key2" => nil}], [nil], ] - iterated_records = [] target = build(:int16, records) - target.each_raw_record do |record| - iterated_records << record - end - assert_equal(records, iterated_records) + assert_equal(records, target.each_raw_record.to_a) end def test_uint16 @@ -96,12 +76,8 @@ def test_uint16 [{"key1" => (2 ** 16) - 1, "key2" => nil}], [nil], ] - iterated_records = [] target = build(:uint16, records) - target.each_raw_record do |record| - iterated_records << record - end - assert_equal(records, iterated_records) + assert_equal(records, target.each_raw_record.to_a) end def test_int32 @@ -109,12 +85,8 @@ def test_int32 [{"key1" => -(2 ** 31), "key2" => nil}], [nil], ] - iterated_records = [] target = build(:int32, records) - target.each_raw_record do |record| - iterated_records << record - end - assert_equal(records, iterated_records) + assert_equal(records, target.each_raw_record.to_a) end def test_uint32 @@ -122,12 +94,8 @@ def test_uint32 [{"key1" => (2 ** 32) - 1, "key2" => nil}], [nil], ] - iterated_records = [] target = build(:uint32, records) - target.each_raw_record do |record| - iterated_records << record - end - assert_equal(records, iterated_records) + assert_equal(records, target.each_raw_record.to_a) end def test_int64 @@ -135,12 +103,8 @@ def test_int64 [{"key1" => -(2 ** 63), "key2" => nil}], [nil], ] - iterated_records = [] target = build(:int64, records) - target.each_raw_record do |record| - iterated_records << record - end - assert_equal(records, iterated_records) + assert_equal(records, target.each_raw_record.to_a) end def test_uint64 @@ -148,12 +112,8 @@ def test_uint64 [{"key1" => (2 ** 64) - 1, "key2" => nil}], [nil], ] - iterated_records = [] target = build(:uint64, records) - target.each_raw_record do |record| - iterated_records << record - end - assert_equal(records, iterated_records) + assert_equal(records, target.each_raw_record.to_a) end def test_float @@ -161,12 +121,8 @@ def test_float [{"key1" => -1.0, "key2" => nil}], [nil], ] - iterated_records = [] target = build(:float, records) - target.each_raw_record do |record| - iterated_records << record - end - assert_equal(records, iterated_records) + assert_equal(records, target.each_raw_record.to_a) end def test_double @@ -174,12 +130,8 @@ def test_double [{"key1" => -1.0, "key2" => nil}], [nil], ] - iterated_records = [] target = build(:double, records) - target.each_raw_record do |record| - iterated_records << record - end - assert_equal(records, iterated_records) + assert_equal(records, target.each_raw_record.to_a) end def test_binary @@ -187,12 +139,8 @@ def test_binary [{"key1" => "\xff".b, "key2" => nil}], [nil], ] - iterated_records = [] target = build(:binary, records) - target.each_raw_record do |record| - iterated_records << record - end - assert_equal(records, iterated_records) + assert_equal(records, target.each_raw_record.to_a) end def test_string @@ -200,12 +148,8 @@ def test_string [{"key1" => "Ruby", "key2" => nil}], [nil], ] - iterated_records = [] target = build(:string, records) - target.each_raw_record do |record| - iterated_records << record - end - assert_equal(records, iterated_records) + assert_equal(records, target.each_raw_record.to_a) end def test_date32 @@ -213,12 +157,8 @@ def test_date32 [{"key1" => Date.new(1960, 1, 1), "key2" => nil}], [nil], ] - iterated_records = [] target = build(:date32, records) - target.each_raw_record do |record| - iterated_records << record - end - assert_equal(records, iterated_records) + assert_equal(records, target.each_raw_record.to_a) end def test_date64 @@ -226,12 +166,8 @@ def test_date64 [{"key1" => DateTime.new(1960, 1, 1, 2, 9, 30), "key2" => nil}], [nil], ] - iterated_records = [] target = build(:date64, records) - target.each_raw_record do |record| - iterated_records << record - end - assert_equal(records, iterated_records) + assert_equal(records, target.each_raw_record.to_a) end def test_timestamp_second @@ -239,16 +175,12 @@ def test_timestamp_second [{"key1" => Time.parse("1960-01-01T02:09:30Z"), "key2" => nil}], [nil], ] - iterated_records = [] target = build({ type: :timestamp, unit: :second, }, records) - target.each_raw_record do |record| - iterated_records << record - end - assert_equal(records, iterated_records) + assert_equal(records, target.each_raw_record.to_a) end def test_timestamp_milli @@ -256,16 +188,12 @@ def test_timestamp_milli [{"key1" => Time.parse("1960-01-01T02:09:30.123Z"), "key2" => nil}], [nil], ] - iterated_records = [] target = build({ type: :timestamp, unit: :milli, }, records) - target.each_raw_record do |record| - iterated_records << record - end - assert_equal(records, iterated_records) + assert_equal(records, target.each_raw_record.to_a) end def test_timestamp_micro @@ -273,16 +201,12 @@ def test_timestamp_micro [{"key1" => Time.parse("1960-01-01T02:09:30.123456Z"), "key2" => nil}], [nil], ] - iterated_records = [] target = build({ type: :timestamp, unit: :micro, }, records) - target.each_raw_record do |record| - iterated_records << record - end - assert_equal(records, iterated_records) + assert_equal(records, target.each_raw_record.to_a) end def test_timestamp_nano @@ -290,16 +214,12 @@ def test_timestamp_nano [{"key1" => Time.parse("1960-01-01T02:09:30.123456789Z"), "key2" => nil}], [nil], ] - iterated_records = [] target = build({ type: :timestamp, unit: :nano, }, records) - target.each_raw_record do |record| - iterated_records << record - end - assert_equal(records, iterated_records) + assert_equal(records, target.each_raw_record.to_a) end def test_time32_second @@ -309,16 +229,12 @@ def test_time32_second [{"key1" => Arrow::Time.new(unit, 60 * 10), "key2" => nil}], [nil], ] - iterated_records = [] target = build({ type: :time32, unit: :second, }, records) - target.each_raw_record do |record| - iterated_records << record - end - assert_equal(records, iterated_records) + assert_equal(records, target.each_raw_record.to_a) end def test_time32_milli @@ -328,16 +244,12 @@ def test_time32_milli [{"key1" => Arrow::Time.new(unit, (60 * 10) * 1000 + 123), "key2" => nil}], [nil], ] - iterated_records = [] target = build({ type: :time32, unit: :milli, }, records) - target.each_raw_record do |record| - iterated_records << record - end - assert_equal(records, iterated_records) + assert_equal(records, target.each_raw_record.to_a) end def test_time64_micro @@ -347,16 +259,12 @@ def test_time64_micro [{"key1" => Arrow::Time.new(unit, (60 * 10) * 1_000_000 + 123_456), "key2" => nil}], [nil], ] - iterated_records = [] target = build({ type: :time64, unit: :micro, }, records) - target.each_raw_record do |record| - iterated_records << record - end - assert_equal(records, iterated_records) + assert_equal(records, target.each_raw_record.to_a) end def test_time64_nano @@ -366,16 +274,12 @@ def test_time64_nano [{"key1" => Arrow::Time.new(unit, (60 * 10) * 1_000_000_000 + 123_456_789), "key2" => nil}], [nil], ] - iterated_records = [] target = build({ type: :time64, unit: :nano, }, records) - target.each_raw_record do |record| - iterated_records << record - end - assert_equal(records, iterated_records) + assert_equal(records, target.each_raw_record.to_a) end def test_decimal128 @@ -383,17 +287,13 @@ def test_decimal128 [{"key1" => BigDecimal("92.92"), "key2" => nil}], [nil], ] - iterated_records = [] target = build({ type: :decimal128, precision: 8, scale: 2, }, records) - target.each_raw_record do |record| - iterated_records << record - end - assert_equal(records, iterated_records) + assert_equal(records, target.each_raw_record.to_a) end def test_decimal256 @@ -401,17 +301,13 @@ def test_decimal256 [{"key1" => BigDecimal("92.92"), "key2" => nil}], [nil], ] - iterated_records = [] target = build({ type: :decimal256, precision: 38, scale: 2, }, records) - target.each_raw_record do |record| - iterated_records << record - end - assert_equal(records, iterated_records) + assert_equal(records, target.each_raw_record.to_a) end def test_month_interval @@ -419,12 +315,8 @@ def test_month_interval [{"key1" => 1, "key2" => nil}], [nil], ] - iterated_records = [] target = build(:month_interval, records) - target.each_raw_record do |record| - iterated_records << record - end - assert_equal(records, iterated_records) + assert_equal(records, target.each_raw_record.to_a) end def test_day_time_interval @@ -437,12 +329,8 @@ def test_day_time_interval ], [nil], ] - iterated_records = [] target = build(:day_time_interval, records) - target.each_raw_record do |record| - iterated_records << record - end - assert_equal(records, iterated_records) + assert_equal(records, target.each_raw_record.to_a) end def test_month_day_nano_interval @@ -455,12 +343,8 @@ def test_month_day_nano_interval ], [nil], ] - iterated_records = [] target = build(:month_day_nano_interval, records) - target.each_raw_record do |record| - iterated_records << record - end - assert_equal(records, iterated_records) + assert_equal(records, target.each_raw_record.to_a) end def test_list @@ -468,7 +352,6 @@ def test_list [{"key1" => [true, nil, false], "key2" => nil}], [nil], ] - iterated_records = [] target = build({ type: :list, field: { @@ -477,10 +360,7 @@ def test_list }, }, records) - target.each_raw_record do |record| - iterated_records << record - end - assert_equal(records, iterated_records) + assert_equal(records, target.each_raw_record.to_a) end def test_struct @@ -488,7 +368,6 @@ def test_struct [{"key1" => {"field" => true}, "key2" => nil, "key3" => {"field" => nil}}], [nil], ] - iterated_records = [] target = build({ type: :struct, fields: [ @@ -499,10 +378,7 @@ def test_struct ], }, records) - target.each_raw_record do |record| - iterated_records << record - end - assert_equal(records, iterated_records) + assert_equal(records, target.each_raw_record.to_a) end def test_map @@ -510,17 +386,13 @@ def test_map [{"key1" => {"sub_key1" => true, "sub_key2" => nil}, "key2" => nil}], [nil], ] - iterated_records = [] target = build({ type: :map, key: :string, item: :boolean, }, records) - target.each_raw_record do |record| - iterated_records << record - end - assert_equal(records, iterated_records) + assert_equal(records, target.each_raw_record.to_a) end def remove_union_field_names(records) @@ -552,7 +424,6 @@ def test_sparse_union ], [nil], ] - iterated_records = [] target = build({ type: :sparse_union, fields: [ @@ -568,11 +439,8 @@ def test_sparse_union type_codes: [0, 1], }, records) - target.each_raw_record do |record| - iterated_records << record - end assert_equal(remove_union_field_names(records), - target.raw_records) + target.each_raw_record.to_a) end def test_dense_union @@ -587,7 +455,6 @@ def test_dense_union ], [nil], ] - iterated_records = [] target = build({ type: :dense_union, fields: [ @@ -603,11 +470,8 @@ def test_dense_union type_codes: [0, 1], }, records) - target.each_raw_record do |record| - iterated_records << record - end assert_equal(remove_union_field_names(records), - target.raw_records) + target.each_raw_record.to_a) end def test_dictionary @@ -615,7 +479,6 @@ def test_dictionary [{"key1" => "Ruby", "key2" => nil, "key3" => "GLib"}], [nil], ] - iterated_records = [] target = build({ type: :dictionary, index_data_type: :int8, @@ -623,10 +486,7 @@ def test_dictionary ordered: false, }, records) - target.each_raw_record do |record| - iterated_records << record - end - assert_equal(records, iterated_records) + assert_equal(records, target.each_raw_record.to_a) end end diff --git a/ruby/red-arrow/test/each-raw-record/test-multiple-columns.rb b/ruby/red-arrow/test/each-raw-record/test-multiple-columns.rb index c0547d324d26d..b222ed89afe25 100644 --- a/ruby/red-arrow/test/each-raw-record/test-multiple-columns.rb +++ b/ruby/red-arrow/test/each-raw-record/test-multiple-columns.rb @@ -22,17 +22,13 @@ def test_3_elements [nil, 0, "GLib"], [false, 2 ** 8 - 1, nil], ] - iterated_records = [] target = build([ {name: :column0, type: :boolean}, {name: :column1, type: :uint8}, {name: :column2, type: :string}, ], records) - target.each_raw_record do |record| - iterated_records << record - end - assert_equal(records, iterated_records) + assert_equal(records, target.each_raw_record.to_a) end def test_4_elements @@ -41,7 +37,6 @@ def test_4_elements [nil, 0, "GLib", nil], [false, 2 ** 8 - 1, nil, (2 ** 63) - 1], ] - iterated_records = [] target = build([ {name: :column0, type: :boolean}, {name: :column1, type: :uint8}, @@ -49,10 +44,7 @@ def test_4_elements {name: :column3, type: :int64}, ], records) - target.each_raw_record do |record| - iterated_records << record - end - assert_equal(records, iterated_records) + assert_equal(records, target.each_raw_record.to_a) end end diff --git a/ruby/red-arrow/test/each-raw-record/test-sparse-union-array.rb b/ruby/red-arrow/test/each-raw-record/test-sparse-union-array.rb index 4b1b941fb2079..36b0884bbc91c 100644 --- a/ruby/red-arrow/test/each-raw-record/test-sparse-union-array.rb +++ b/ruby/red-arrow/test/each-raw-record/test-sparse-union-array.rb @@ -82,12 +82,8 @@ def test_null records = [ [{"0" => nil}], ] - iterated_records = [] target = build(:null, records) - target.each_raw_record do |record| - iterated_records << record - end - assert_equal(remove_field_names(records), iterated_records) + assert_equal(remove_field_names(records), target.each_raw_record.to_a) end def test_boolean @@ -95,12 +91,8 @@ def test_boolean [{"0" => true}], [{"1" => nil}], ] - iterated_records = [] target = build(:boolean, records) - target.each_raw_record do |record| - iterated_records << record - end - assert_equal(remove_field_names(records), iterated_records) + assert_equal(remove_field_names(records), target.each_raw_record.to_a) end def test_int8 @@ -108,12 +100,8 @@ def test_int8 [{"0" => -(2 ** 7)}], [{"1" => nil}], ] - iterated_records = [] target = build(:int8, records) - target.each_raw_record do |record| - iterated_records << record - end - assert_equal(remove_field_names(records), iterated_records) + assert_equal(remove_field_names(records), target.each_raw_record.to_a) end def test_uint8 @@ -121,12 +109,8 @@ def test_uint8 [{"0" => (2 ** 8) - 1}], [{"1" => nil}], ] - iterated_records = [] target = build(:uint8, records) - target.each_raw_record do |record| - iterated_records << record - end - assert_equal(remove_field_names(records), iterated_records) + assert_equal(remove_field_names(records), target.each_raw_record.to_a) end def test_int16 @@ -134,12 +118,8 @@ def test_int16 [{"0" => -(2 ** 15)}], [{"1" => nil}], ] - iterated_records = [] target = build(:int16, records) - target.each_raw_record do |record| - iterated_records << record - end - assert_equal(remove_field_names(records), iterated_records) + assert_equal(remove_field_names(records), target.each_raw_record.to_a) end def test_uint16 @@ -147,12 +127,8 @@ def test_uint16 [{"0" => (2 ** 16) - 1}], [{"1" => nil}], ] - iterated_records = [] target = build(:uint16, records) - target.each_raw_record do |record| - iterated_records << record - end - assert_equal(remove_field_names(records), iterated_records) + assert_equal(remove_field_names(records), target.each_raw_record.to_a) end def test_int32 @@ -160,12 +136,8 @@ def test_int32 [{"0" => -(2 ** 31)}], [{"1" => nil}], ] - iterated_records = [] target = build(:int32, records) - target.each_raw_record do |record| - iterated_records << record - end - assert_equal(remove_field_names(records), iterated_records) + assert_equal(remove_field_names(records), target.each_raw_record.to_a) end def test_uint32 @@ -173,12 +145,8 @@ def test_uint32 [{"0" => (2 ** 32) - 1}], [{"1" => nil}], ] - iterated_records = [] target = build(:uint32, records) - target.each_raw_record do |record| - iterated_records << record - end - assert_equal(remove_field_names(records), iterated_records) + assert_equal(remove_field_names(records), target.each_raw_record.to_a) end def test_int64 @@ -186,12 +154,8 @@ def test_int64 [{"0" => -(2 ** 63)}], [{"1" => nil}], ] - iterated_records = [] target = build(:int64, records) - target.each_raw_record do |record| - iterated_records << record - end - assert_equal(remove_field_names(records), iterated_records) + assert_equal(remove_field_names(records), target.each_raw_record.to_a) end def test_uint64 @@ -199,12 +163,8 @@ def test_uint64 [{"0" => (2 ** 64) - 1}], [{"1" => nil}], ] - iterated_records = [] target = build(:uint64, records) - target.each_raw_record do |record| - iterated_records << record - end - assert_equal(remove_field_names(records), iterated_records) + assert_equal(remove_field_names(records), target.each_raw_record.to_a) end def test_float @@ -212,12 +172,8 @@ def test_float [{"0" => -1.0}], [{"1" => nil}], ] - iterated_records = [] target = build(:float, records) - target.each_raw_record do |record| - iterated_records << record - end - assert_equal(remove_field_names(records), iterated_records) + assert_equal(remove_field_names(records), target.each_raw_record.to_a) end def test_double @@ -225,12 +181,8 @@ def test_double [{"0" => -1.0}], [{"1" => nil}], ] - iterated_records = [] target = build(:double, records) - target.each_raw_record do |record| - iterated_records << record - end - assert_equal(remove_field_names(records), iterated_records) + assert_equal(remove_field_names(records), target.each_raw_record.to_a) end def test_binary @@ -238,12 +190,8 @@ def test_binary [{"0" => "\xff".b}], [{"1" => nil}], ] - iterated_records = [] target = build(:binary, records) - target.each_raw_record do |record| - iterated_records << record - end - assert_equal(remove_field_names(records), iterated_records) + assert_equal(remove_field_names(records), target.each_raw_record.to_a) end def test_string @@ -251,12 +199,8 @@ def test_string [{"0" => "Ruby"}], [{"1" => nil}], ] - iterated_records = [] target = build(:string, records) - target.each_raw_record do |record| - iterated_records << record - end - assert_equal(remove_field_names(records), iterated_records) + assert_equal(remove_field_names(records), target.each_raw_record.to_a) end def test_date32 @@ -264,12 +208,8 @@ def test_date32 [{"0" => Date.new(1960, 1, 1)}], [{"1" => nil}], ] - iterated_records = [] target = build(:date32, records) - target.each_raw_record do |record| - iterated_records << record - end - assert_equal(remove_field_names(records), iterated_records) + assert_equal(remove_field_names(records), target.each_raw_record.to_a) end def test_date64 @@ -277,12 +217,8 @@ def test_date64 [{"0" => DateTime.new(1960, 1, 1, 2, 9, 30)}], [{"1" => nil}], ] - iterated_records = [] target = build(:date64, records) - target.each_raw_record do |record| - iterated_records << record - end - assert_equal(remove_field_names(records), iterated_records) + assert_equal(remove_field_names(records), target.each_raw_record.to_a) end def test_timestamp_second @@ -290,16 +226,12 @@ def test_timestamp_second [{"0" => Time.parse("1960-01-01T02:09:30Z")}], [{"1" => nil}], ] - iterated_records = [] target = build({ type: :timestamp, unit: :second, }, records) - target.each_raw_record do |record| - iterated_records << record - end - assert_equal(remove_field_names(records), iterated_records) + assert_equal(remove_field_names(records), target.each_raw_record.to_a) end def test_timestamp_milli @@ -307,16 +239,12 @@ def test_timestamp_milli [{"0" => Time.parse("1960-01-01T02:09:30.123Z")}], [{"1" => nil}], ] - iterated_records = [] target = build({ type: :timestamp, unit: :milli, }, records) - target.each_raw_record do |record| - iterated_records << record - end - assert_equal(remove_field_names(records), iterated_records) + assert_equal(remove_field_names(records), target.each_raw_record.to_a) end @@ -325,16 +253,12 @@ def test_timestamp_micro [{"0" => Time.parse("1960-01-01T02:09:30.123456Z")}], [{"1" => nil}], ] - iterated_records = [] target = build({ type: :timestamp, unit: :micro, }, records) - target.each_raw_record do |record| - iterated_records << record - end - assert_equal(remove_field_names(records), iterated_records) + assert_equal(remove_field_names(records), target.each_raw_record.to_a) end def test_timestamp_nano @@ -342,16 +266,12 @@ def test_timestamp_nano [{"0" => Time.parse("1960-01-01T02:09:30.123456789Z")}], [{"1" => nil}], ] - iterated_records = [] target = build({ type: :timestamp, unit: :nano, }, records) - target.each_raw_record do |record| - iterated_records << record - end - assert_equal(remove_field_names(records), iterated_records) + assert_equal(remove_field_names(records), target.each_raw_record.to_a) end def test_time32_second @@ -361,16 +281,12 @@ def test_time32_second [{"0" => Arrow::Time.new(unit, 60 * 10)}], [{"1" => nil}], ] - iterated_records = [] target = build({ type: :time32, unit: :second, }, records) - target.each_raw_record do |record| - iterated_records << record - end - assert_equal(remove_field_names(records), iterated_records) + assert_equal(remove_field_names(records), target.each_raw_record.to_a) end def test_time32_milli @@ -380,16 +296,12 @@ def test_time32_milli [{"0" => Arrow::Time.new(unit, (60 * 10) * 1000 + 123)}], [{"1" => nil}], ] - iterated_records = [] target = build({ type: :time32, unit: :milli, }, records) - target.each_raw_record do |record| - iterated_records << record - end - assert_equal(remove_field_names(records), iterated_records) + assert_equal(remove_field_names(records), target.each_raw_record.to_a) end def test_time64_micro @@ -399,16 +311,12 @@ def test_time64_micro [{"0" => Arrow::Time.new(unit, (60 * 10) * 1_000_000 + 123_456)}], [{"1" => nil}], ] - iterated_records = [] target = build({ type: :time64, unit: :micro, }, records) - target.each_raw_record do |record| - iterated_records << record - end - assert_equal(remove_field_names(records), iterated_records) + assert_equal(remove_field_names(records), target.each_raw_record.to_a) end def test_time64_nano @@ -418,16 +326,12 @@ def test_time64_nano [{"0" => Arrow::Time.new(unit, (60 * 10) * 1_000_000_000 + 123_456_789)}], [{"1" => nil}], ] - iterated_records = [] target = build({ type: :time64, unit: :nano, }, records) - target.each_raw_record do |record| - iterated_records << record - end - assert_equal(remove_field_names(records), iterated_records) + assert_equal(remove_field_names(records), target.each_raw_record.to_a) end def test_decimal128 @@ -435,17 +339,13 @@ def test_decimal128 [{"0" => BigDecimal("92.92")}], [{"1" => nil}], ] - iterated_records = [] target = build({ type: :decimal128, precision: 8, scale: 2, }, records) - target.each_raw_record do |record| - iterated_records << record - end - assert_equal(remove_field_names(records), iterated_records) + assert_equal(remove_field_names(records), target.each_raw_record.to_a) end def test_decimal256 @@ -453,17 +353,13 @@ def test_decimal256 [{"0" => BigDecimal("92.92")}], [{"1" => nil}], ] - iterated_records = [] target = build({ type: :decimal256, precision: 38, scale: 2, }, - records) - target.each_raw_record do |record| - iterated_records << record - end - assert_equal(remove_field_names(records), iterated_records) + records) + assert_equal(remove_field_names(records), target.each_raw_record.to_a) end def test_month_interval @@ -471,12 +367,8 @@ def test_month_interval [{"0" => 1}], [{"1" => nil}], ] - iterated_records = [] target = build(:month_interval, records) - target.each_raw_record do |record| - iterated_records << record - end - assert_equal(remove_field_names(records), iterated_records) + assert_equal(remove_field_names(records), target.each_raw_record.to_a) end def test_day_time_interval @@ -484,12 +376,8 @@ def test_day_time_interval [{"0" => {day: 1, millisecond: 100}}], [{"1" => nil}], ] - iterated_records = [] target = build(:day_time_interval, records) - target.each_raw_record do |record| - iterated_records << record - end - assert_equal(remove_field_names(records), iterated_records) + assert_equal(remove_field_names(records), target.each_raw_record.to_a) end def test_month_day_nano_interval @@ -497,12 +385,8 @@ def test_month_day_nano_interval [{"0" => {month: 1, day: 1, nanosecond: 100}}], [{"1" => nil}], ] - iterated_records = [] target = build(:month_day_nano_interval, records) - target.each_raw_record do |record| - iterated_records << record - end - assert_equal(remove_field_names(records), iterated_records) + assert_equal(remove_field_names(records), target.each_raw_record.to_a) end def test_list @@ -510,7 +394,6 @@ def test_list [{"0" => [true, nil, false]}], [{"1" => nil}], ] - iterated_records = [] target = build({ type: :list, field: { @@ -519,10 +402,7 @@ def test_list }, }, records) - target.each_raw_record do |record| - iterated_records << record - end - assert_equal(remove_field_names(records), iterated_records) + assert_equal(remove_field_names(records), target.each_raw_record.to_a) end def test_struct @@ -531,7 +411,6 @@ def test_struct [{"1" => nil}], [{"0" => {"sub_field" => nil}}], ] - iterated_records = [] target = build({ type: :struct, fields: [ @@ -542,10 +421,7 @@ def test_struct ], }, records) - target.each_raw_record do |record| - iterated_records << record - end - assert_equal(remove_field_names(records), iterated_records) + assert_equal(remove_field_names(records), target.each_raw_record.to_a) end def test_map @@ -553,17 +429,13 @@ def test_map [{"0" => {"key1" => true, "key2" => nil}}], [{"1" => nil}], ] - iterated_records = [] target = build({ type: :map, key: :string, item: :boolean, }, records) - target.each_raw_record do |record| - iterated_records << record - end - assert_equal(remove_field_names(records), iterated_records) + assert_equal(remove_field_names(records), target.each_raw_record.to_a) end def test_sparse_union @@ -573,7 +445,6 @@ def test_sparse_union [{"0" => {"field2" => 29}}], [{"0" => {"field2" => nil}}], ] - iterated_records = [] target = build({ type: :sparse_union, fields: [ @@ -589,10 +460,8 @@ def test_sparse_union type_codes: [0, 1], }, records) - target.each_raw_record do |record| - iterated_records << record - end - assert_equal(remove_field_names(remove_field_names(records)), iterated_records) + assert_equal(remove_field_names(remove_field_names(records)), + target.each_raw_record.to_a) end def test_dense_union @@ -602,7 +471,6 @@ def test_dense_union [{"0" => {"field2" => 29}}], [{"0" => {"field2" => nil}}], ] - iterated_records = [] target = build({ type: :dense_union, fields: [ @@ -618,10 +486,8 @@ def test_dense_union type_codes: [0, 1], }, records) - target.each_raw_record do |record| - iterated_records << record - end - assert_equal(remove_field_names(remove_field_names(records)), iterated_records) + assert_equal(remove_field_names(remove_field_names(records)), + target.each_raw_record.to_a) end def test_dictionary diff --git a/ruby/red-arrow/test/each-raw-record/test-struct-array.rb b/ruby/red-arrow/test/each-raw-record/test-struct-array.rb index de6e78aaeef4c..91a3d09af4e84 100644 --- a/ruby/red-arrow/test/each-raw-record/test-struct-array.rb +++ b/ruby/red-arrow/test/each-raw-record/test-struct-array.rb @@ -40,12 +40,8 @@ def test_null [{"field" => nil}], [nil], ] - iterated_records = [] target = build(:null, records) - target.each_raw_record do |record| - iterated_records << record - end - assert_equal(records, iterated_records) + assert_equal(records, target.each_raw_record.to_a) end def test_boolean @@ -54,12 +50,8 @@ def test_boolean [nil], [{"field" => nil}], ] - iterated_records = [] target = build(:boolean, records) - target.each_raw_record do |record| - iterated_records << record - end - assert_equal(records, iterated_records) + assert_equal(records, target.each_raw_record.to_a) end def test_int8 @@ -68,12 +60,8 @@ def test_int8 [nil], [{"field" => nil}], ] - iterated_records = [] target = build(:int8, records) - target.each_raw_record do |record| - iterated_records << record - end - assert_equal(records, iterated_records) + assert_equal(records, target.each_raw_record.to_a) end def test_uint8 @@ -82,12 +70,8 @@ def test_uint8 [nil], [{"field" => nil}], ] - iterated_records = [] target = build(:uint8, records) - target.each_raw_record do |record| - iterated_records << record - end - assert_equal(records, iterated_records) + assert_equal(records, target.each_raw_record.to_a) end def test_int16 @@ -96,12 +80,8 @@ def test_int16 [nil], [{"field" => nil}], ] - iterated_records = [] target = build(:int16, records) - target.each_raw_record do |record| - iterated_records << record - end - assert_equal(records, iterated_records) + assert_equal(records, target.each_raw_record.to_a) end def test_uint16 @@ -110,12 +90,8 @@ def test_uint16 [nil], [{"field" => nil}], ] - iterated_records = [] target = build(:uint16, records) - target.each_raw_record do |record| - iterated_records << record - end - assert_equal(records, iterated_records) + assert_equal(records, target.each_raw_record.to_a) end def test_int32 @@ -124,12 +100,8 @@ def test_int32 [nil], [{"field" => nil}], ] - iterated_records = [] target = build(:int32, records) - target.each_raw_record do |record| - iterated_records << record - end - assert_equal(records, iterated_records) + assert_equal(records, target.each_raw_record.to_a) end def test_uint32 @@ -138,12 +110,8 @@ def test_uint32 [nil], [{"field" => nil}], ] - iterated_records = [] target = build(:uint32, records) - target.each_raw_record do |record| - iterated_records << record - end - assert_equal(records, iterated_records) + assert_equal(records, target.each_raw_record.to_a) end def test_int64 @@ -152,12 +120,8 @@ def test_int64 [nil], [{"field" => nil}], ] - iterated_records = [] target = build(:int64, records) - target.each_raw_record do |record| - iterated_records << record - end - assert_equal(records, iterated_records) + assert_equal(records, target.each_raw_record.to_a) end def test_uint64 @@ -166,12 +130,8 @@ def test_uint64 [nil], [{"field" => nil}], ] - iterated_records = [] target = build(:uint64, records) - target.each_raw_record do |record| - iterated_records << record - end - assert_equal(records, iterated_records) + assert_equal(records, target.each_raw_record.to_a) end def test_float @@ -180,12 +140,8 @@ def test_float [nil], [{"field" => nil}], ] - iterated_records = [] target = build(:float, records) - target.each_raw_record do |record| - iterated_records << record - end - assert_equal(records, iterated_records) + assert_equal(records, target.each_raw_record.to_a) end def test_double @@ -194,12 +150,8 @@ def test_double [nil], [{"field" => nil}], ] - iterated_records = [] target = build(:double, records) - target.each_raw_record do |record| - iterated_records << record - end - assert_equal(records, iterated_records) + assert_equal(records, target.each_raw_record.to_a) end def test_binary @@ -208,12 +160,8 @@ def test_binary [nil], [{"field" => nil}], ] - iterated_records = [] target = build(:binary, records) - target.each_raw_record do |record| - iterated_records << record - end - assert_equal(records, iterated_records) + assert_equal(records, target.each_raw_record.to_a) end def test_string @@ -222,12 +170,8 @@ def test_string [nil], [{"field" => nil}], ] - iterated_records = [] - target = build(:string, records) - target.each_raw_record do |record| - iterated_records << record - end - assert_equal(records, iterated_records) + target = build(:string, records) + assert_equal(records, target.each_raw_record.to_a) end def test_date32 @@ -236,12 +180,8 @@ def test_date32 [nil], [{"field" => nil}], ] - iterated_records = [] target = build(:date32, records) - target.each_raw_record do |record| - iterated_records << record - end - assert_equal(records, iterated_records) + assert_equal(records, target.each_raw_record.to_a) end def test_date64 @@ -250,12 +190,8 @@ def test_date64 [nil], [{"field" => nil}], ] - iterated_records = [] target = build(:date64, records) - target.each_raw_record do |record| - iterated_records << record - end - assert_equal(records, iterated_records) + assert_equal(records, target.each_raw_record.to_a) end def test_timestamp_second @@ -264,16 +200,12 @@ def test_timestamp_second [nil], [{"field" => nil}], ] - iterated_records = [] target = build({ type: :timestamp, unit: :second, }, - records) - target.each_raw_record do |record| - iterated_records << record - end - assert_equal(records, iterated_records) + records) + assert_equal(records, target.each_raw_record.to_a) end def test_timestamp_milli @@ -282,16 +214,12 @@ def test_timestamp_milli [nil], [{"field" => nil}], ] - iterated_records = [] target = build({ type: :timestamp, unit: :milli, }, records) - target.each_raw_record do |record| - iterated_records << record - end - assert_equal(records, iterated_records) + assert_equal(records, target.each_raw_record.to_a) end def test_timestamp_micro @@ -300,16 +228,12 @@ def test_timestamp_micro [nil], [{"field" => nil}], ] - iterated_records = [] target = build({ type: :timestamp, unit: :micro, }, records) - target.each_raw_record do |record| - iterated_records << record - end - assert_equal(records, iterated_records) + assert_equal(records, target.each_raw_record.to_a) end def test_timestamp_nano @@ -318,16 +242,12 @@ def test_timestamp_nano [nil], [{"field" => nil}], ] - iterated_records = [] target = build({ type: :timestamp, unit: :nano, }, records) - target.each_raw_record do |record| - iterated_records << record - end - assert_equal(records, iterated_records) + assert_equal(records, target.each_raw_record.to_a) end def test_time32_second @@ -338,16 +258,12 @@ def test_time32_second [nil], [{"field" => nil}], ] - iterated_records = [] target = build({ type: :time32, unit: :second, }, records) - target.each_raw_record do |record| - iterated_records << record - end - assert_equal(records, iterated_records) + assert_equal(records, target.each_raw_record.to_a) end def test_time32_milli @@ -358,16 +274,12 @@ def test_time32_milli [nil], [{"field" => nil}], ] - iterated_records = [] target = build({ type: :time32, unit: :milli, }, records) - target.each_raw_record do |record| - iterated_records << record - end - assert_equal(records, iterated_records) + assert_equal(records, target.each_raw_record.to_a) end def test_time64_micro @@ -378,16 +290,12 @@ def test_time64_micro [nil], [{"field" => nil}], ] - iterated_records = [] target = build({ type: :time64, unit: :micro, }, records) - target.each_raw_record do |record| - iterated_records << record - end - assert_equal(records, iterated_records) + assert_equal(records, target.each_raw_record.to_a) end def test_time64_nano @@ -398,16 +306,12 @@ def test_time64_nano [nil], [{"field" => nil}], ] - iterated_records = [] target = build({ type: :time64, unit: :nano, }, records) - target.each_raw_record do |record| - iterated_records << record - end - assert_equal(records, iterated_records) + assert_equal(records, target.each_raw_record.to_a) end def test_decimal128 @@ -416,17 +320,13 @@ def test_decimal128 [nil], [{"field" => nil}], ] - iterated_records = [] target = build({ type: :decimal128, precision: 8, scale: 2, }, records) - target.each_raw_record do |record| - iterated_records << record - end - assert_equal(records, iterated_records) + assert_equal(records, target.each_raw_record.to_a) end def test_decimal256 @@ -435,17 +335,13 @@ def test_decimal256 [nil], [{"field" => nil}], ] - iterated_records = [] target = build({ type: :decimal256, precision: 38, scale: 2, }, records) - target.each_raw_record do |record| - iterated_records << record - end - assert_equal(records, iterated_records) + assert_equal(records, target.each_raw_record.to_a) end def test_month_interval @@ -454,12 +350,8 @@ def test_month_interval [nil], [{"field" => nil}], ] - iterated_records = [] target = build(:month_interval, records) - target.each_raw_record do |record| - iterated_records << record - end - assert_equal(records, iterated_records) + assert_equal(records, target.each_raw_record.to_a) end def test_day_time_interval @@ -468,12 +360,8 @@ def test_day_time_interval [nil], [{"field" => nil}], ] - iterated_records = [] target = build(:day_time_interval, records) - target.each_raw_record do |record| - iterated_records << record - end - assert_equal(records, iterated_records) + assert_equal(records, target.each_raw_record.to_a) end def test_month_day_nano_interval @@ -482,12 +370,8 @@ def test_month_day_nano_interval [nil], [{"field" => nil}], ] - iterated_records = [] target = build(:month_day_nano_interval, records) - target.each_raw_record do |record| - iterated_records << record - end - assert_equal(records, iterated_records) + assert_equal(records, target.each_raw_record.to_a) end def test_list @@ -496,7 +380,6 @@ def test_list [nil], [{"field" => nil}], ] - iterated_records = [] target = build({ type: :list, field: { @@ -505,10 +388,7 @@ def test_list }, }, records) - target.each_raw_record do |record| - iterated_records << record - end - assert_equal(records, iterated_records) + assert_equal(records, target.each_raw_record.to_a) end def test_struct @@ -518,7 +398,6 @@ def test_struct [{"field" => nil}], [{"field" => {"sub_field" => nil}}], ] - iterated_records = [] target = build({ type: :struct, fields: [ @@ -529,10 +408,7 @@ def test_struct ], }, records) - target.each_raw_record do |record| - iterated_records << record - end - assert_equal(records, iterated_records) + assert_equal(records, target.each_raw_record.to_a) end def test_map @@ -541,17 +417,13 @@ def test_map [nil], [{"field" => nil}], ] - iterated_records = [] target = build({ type: :map, key: :string, item: :boolean, }, records) - target.each_raw_record do |record| - iterated_records << record - end - assert_equal(records, iterated_records) + assert_equal(records, target.each_raw_record.to_a) end def remove_union_field_names(records) @@ -576,7 +448,6 @@ def test_sparse_union [{"field" => {"field2" => 29}}], [{"field" => {"field2" => nil}}], ] - iterated_records = [] target = build({ type: :sparse_union, fields: [ @@ -592,11 +463,8 @@ def test_sparse_union type_codes: [0, 1], }, records) - target.each_raw_record do |record| - iterated_records << record - end assert_equal(remove_union_field_names(records), - iterated_records) + target.each_raw_record.to_a) end def test_dense_union @@ -607,7 +475,6 @@ def test_dense_union [{"field" => {"field2" => 29}}], [{"field" => {"field2" => nil}}], ] - iterated_records = [] target = build({ type: :dense_union, fields: [ @@ -623,11 +490,8 @@ def test_dense_union type_codes: [0, 1], }, records) - target.each_raw_record do |record| - iterated_records << record - end assert_equal(remove_union_field_names(records), - iterated_records) + target.each_raw_record.to_a) end def test_dictionary @@ -637,7 +501,6 @@ def test_dictionary [{"field" => nil}], [{"field" => "GLib"}], ] - iterated_records = [] target = build({ type: :dictionary, index_data_type: :int8, @@ -645,14 +508,11 @@ def test_dictionary ordered: false, }, records) - target.each_raw_record do |record| - iterated_records << record - end - assert_equal(records, iterated_records) + assert_equal(records, target.each_raw_record.to_a) end end -class RawRecordsRecordBatchStructArrayTest < Test::Unit::TestCase +class EachRawRecordRecordBatchStructArrayTest < Test::Unit::TestCase include EachRawRecordStructArrayTests def build(type, records) @@ -660,7 +520,7 @@ def build(type, records) end end -class RawRecordsTableStructArrayTest < Test::Unit::TestCase +class EachRawRecordTableStructArrayTest < Test::Unit::TestCase include EachRawRecordStructArrayTests def build(type, records) diff --git a/ruby/red-arrow/test/each-raw-record/test-table.rb b/ruby/red-arrow/test/each-raw-record/test-table.rb index b5bd80127c8b0..96dbe576382b2 100644 --- a/ruby/red-arrow/test/each-raw-record/test-table.rb +++ b/ruby/red-arrow/test/each-raw-record/test-table.rb @@ -41,11 +41,7 @@ class EachRawRecordTableTest < Test::Unit::TestCase record_batches = raw_record_batches.collect do |record_batch| Arrow::RecordBatch.new(schema, record_batch) end - iterated_records = [] table = Arrow::Table.new(schema, record_batches) - table.each_raw_record do |record| - iterated_records << record - end - assert_equal(raw_records, iterated_records) + assert_equal(raw_records, table.each_raw_record.to_a) end end