You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@arrow.apache.org by "kou (via GitHub)" <gi...@apache.org> on 2023/06/10 19:55:45 UTC

[GitHub] [arrow] kou commented on a diff in pull request #36022: GH-36008: [Ruby] [Parquet] Add Parquet::ArrowFileReader#each_row_group

kou commented on code in PR #36022:
URL: https://github.com/apache/arrow/pull/36022#discussion_r1225548093


##########
ruby/red-parquet/test/test-arrow-file-reader.rb:
##########
@@ -0,0 +1,56 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+class TestArrowFileReader < Test::Unit::TestCase
+  def setup
+    visible_field = Arrow::Field.new("visible", :boolean)
+    @schema = Arrow::Schema.new([visible_field])
+    visible_arrays = [Arrow::BooleanArray.new([true, false])]
+    visible_array = Arrow::ChunkedArray.new(visible_arrays)
+    table = Arrow::Table.new(@schema, [visible_array])
+    @file = Tempfile.open(["red-parquet", ".parquet"])
+    chunk_size = 1
+    writer = Parquet::ArrowFileWriter.new(table.schema, @file.path)
+    writer.write_table(table, chunk_size)
+    writer.close

Review Comment:
   Could you use `Tempfile.create {...}` and `yield` in `setup` to remove a temporary file as soon as possible?
   
    ```suggestion
       Tempfile.create(["red-parquet", ".parquet"]) do |file|
         @file = file
         chunk_size = 1
         writer = Parquet::ArrowFileWriter.new(table.schema, @file.path)
         writer.write_table(table, chunk_size)
         writer.close
         yield
       end
   ```



##########
ruby/red-parquet/test/test-arrow-file-reader.rb:
##########
@@ -0,0 +1,56 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+class TestArrowFileReader < Test::Unit::TestCase
+  def setup
+    visible_field = Arrow::Field.new("visible", :boolean)
+    @schema = Arrow::Schema.new([visible_field])
+    visible_arrays = [Arrow::BooleanArray.new([true, false])]
+    visible_array = Arrow::ChunkedArray.new(visible_arrays)
+    table = Arrow::Table.new(@schema, [visible_array])
+    @file = Tempfile.open(["red-parquet", ".parquet"])
+    chunk_size = 1
+    writer = Parquet::ArrowFileWriter.new(table.schema, @file.path)
+    writer.write_table(table, chunk_size)
+    writer.close
+  end
+
+  sub_test_case("#each_row_group") do
+    test("without block") do
+      first_visible_arrays = [Arrow::BooleanArray.new([true])]
+      first_visible_array = Arrow::ChunkedArray.new(first_visible_arrays)
+      second_visible_arrays = [Arrow::BooleanArray.new([false])]
+      second_visible_array = Arrow::ChunkedArray.new(second_visible_arrays)
+
+      Arrow::FileInputStream.open(@file.path) do |input|
+        reader = Parquet::ArrowFileReader.new(input)
+        each_row_group = reader.each_row_group
+        assert_equal({
+                       size: 2,
+                       to_a: [
+                         Arrow::Table.new(@schema, [first_visible_array]),
+                         Arrow::Table.new(@schema, [second_visible_array])

Review Comment:
   We can simplify this:
   
   ```suggestion
         Arrow::FileInputStream.open(@file.path) do |input|
           reader = Parquet::ArrowFileReader.new(input)
           each_row_group = reader.each_row_group
           assert_equal({
                          size: 2,
                          to_a: [
                            Arrow::Table.new(@schema, [[true]]),
                            Arrow::Table.new(@schema, [[false]])
   ```



##########
ruby/red-parquet/test/test-arrow-file-reader.rb:
##########
@@ -0,0 +1,56 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+class TestArrowFileReader < Test::Unit::TestCase
+  def setup
+    visible_field = Arrow::Field.new("visible", :boolean)
+    @schema = Arrow::Schema.new([visible_field])

Review Comment:
   We can simplify this:
   
   ```suggestion
       @schema = Arrow::Schema.new(visible: :boolean)
   ```



##########
ruby/red-parquet/test/test-arrow-file-reader.rb:
##########
@@ -0,0 +1,56 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+class TestArrowFileReader < Test::Unit::TestCase
+  def setup
+    visible_field = Arrow::Field.new("visible", :boolean)
+    @schema = Arrow::Schema.new([visible_field])
+    visible_arrays = [Arrow::BooleanArray.new([true, false])]
+    visible_array = Arrow::ChunkedArray.new(visible_arrays)
+    table = Arrow::Table.new(@schema, [visible_array])

Review Comment:
   we can simplify this:
   
   ```suggestion
       table = Arrow::Table.new(@schema, [[true], [false]])
   ```



##########
ruby/red-parquet/test/test-arrow-file-reader.rb:
##########
@@ -0,0 +1,56 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+class TestArrowFileReader < Test::Unit::TestCase
+  def setup
+    visible_field = Arrow::Field.new("visible", :boolean)
+    @schema = Arrow::Schema.new([visible_field])
+    visible_arrays = [Arrow::BooleanArray.new([true, false])]
+    visible_array = Arrow::ChunkedArray.new(visible_arrays)
+    table = Arrow::Table.new(@schema, [visible_array])
+    @file = Tempfile.open(["red-parquet", ".parquet"])
+    chunk_size = 1
+    writer = Parquet::ArrowFileWriter.new(table.schema, @file.path)
+    writer.write_table(table, chunk_size)
+    writer.close

Review Comment:
   Could you use more Ruby-ish `ArrowFileWriter.open {...}` API?
   
   ```suggestion
       Parquet::ArrowFileWriter.open(table.schema, @file.path) do |writer|
         chunk_size = 1
         writer.write_table(table, chunk_size)
       end
   ```



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org