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


##########
c_glib/parquet-glib/arrow-file-reader.hpp:
##########
@@ -25,5 +25,12 @@
 
 GParquetArrowFileReader *
 gparquet_arrow_file_reader_new_raw(parquet::arrow::FileReader 
*parquet_arrow_file_reader);
+GParquetArrowFileReader *
+gparquet_arrow_file_reader_new_raw(parquet::arrow::FileReader 
*parquet_arrow_file_reader,
+                                   GArrowSeekableInputStream *source);

Review Comment:
   Can we simplify them by the default argument?
   
   ```suggestion
   GParquetArrowFileReader *
   gparquet_arrow_file_reader_new_raw(parquet::arrow::FileReader 
*parquet_arrow_file_reader,
                                      GArrowSeekableInputStream 
*source=nullptr);
   ```



##########
c_glib/parquet-glib/arrow-file-reader.cpp:
##########
@@ -25,25 +25,222 @@
 
 #include <parquet/file_reader.h>
 
+namespace {
+  GParquetArrowFileReader *
+  open_reader(std::shared_ptr<arrow::io::RandomAccessFile> source,

Review Comment:
   Can we use this in `gparquet_arrow_file_reader_new_path()` too to remove 
duplicated code?



##########
c_glib/test/parquet/test-arrow-file-reader.rb:
##########
@@ -39,6 +39,109 @@ def setup
     end
   end
 
+  sub_test_case(".new with properties") do
+    data("path" => :path, "stream" => :stream)
+    test("read") do |source_type|
+      properties = Parquet::ReaderProperties.new
+      properties.enable_buffered_stream
+      properties.pre_buffer = false
+      properties.buffer_size = 4096
+      source = if source_type == :path
+                 @file.path
+               else
+                 Arrow::FileInputStream.new(@file.path)
+               end
+      reader = Parquet::ArrowFileReader.new(source, properties)
+      begin
+        assert_equal(@table, reader.read_table)
+        assert_equal(build_table("a" => @a_array.slice(1, 1),
+                                 "b" => @b_array.slice(1, 1)),
+                     reader.read_row_group(1))
+      ensure
+        reader.close
+        reader.unref
+        source.unref if source_type == :stream
+      end
+    end
+
+    test("copies properties") do
+      properties = Parquet::ReaderProperties.new
+      properties.enable_buffered_stream
+      properties.pre_buffer = false
+      properties.buffer_size = 4096
+      reader = Parquet::ArrowFileReader.new(@file.path, properties)
+      begin
+        properties.pre_buffer = true
+        properties.disable_buffered_stream
+        properties.buffer_size = 0
+        properties.unref
+        assert_equal(@table, reader.read_table)
+      ensure
+        reader.close
+        reader.unref
+      end
+    end

Review Comment:
   Could you remove this test? It seems that we can't write a handy test for 
this case. For example, we can't detect whether buffer is used or not by 
`read_table`.



##########
c_glib/test/parquet/test-arrow-file-reader.rb:
##########
@@ -39,6 +39,109 @@ def setup
     end
   end
 
+  sub_test_case(".new with properties") do
+    data("path" => :path, "stream" => :stream)
+    test("read") do |source_type|
+      properties = Parquet::ReaderProperties.new
+      properties.enable_buffered_stream
+      properties.pre_buffer = false
+      properties.buffer_size = 4096
+      source = if source_type == :path
+                 @file.path
+               else
+                 Arrow::FileInputStream.new(@file.path)
+               end
+      reader = Parquet::ArrowFileReader.new(source, properties)
+      begin
+        assert_equal(@table, reader.read_table)
+        assert_equal(build_table("a" => @a_array.slice(1, 1),
+                                 "b" => @b_array.slice(1, 1)),
+                     reader.read_row_group(1))
+      ensure
+        reader.close
+        reader.unref
+        source.unref if source_type == :stream
+      end
+    end
+
+    test("copies properties") do
+      properties = Parquet::ReaderProperties.new
+      properties.enable_buffered_stream
+      properties.pre_buffer = false
+      properties.buffer_size = 4096
+      reader = Parquet::ArrowFileReader.new(@file.path, properties)
+      begin
+        properties.pre_buffer = true
+        properties.disable_buffered_stream
+        properties.buffer_size = 0
+        properties.unref
+        assert_equal(@table, reader.read_table)
+      ensure
+        reader.close
+        reader.unref
+      end
+    end
+
+    test("retains source") do
+      properties = Parquet::ReaderProperties.new
+      source = Arrow::FileInputStream.new(@file.path)
+      reader = Parquet::ArrowFileReader.new(source, properties)
+      begin
+        assert_equal(source, reader.source)
+        source.unref
+        assert_equal(@table, reader.read_table)
+      ensure
+        reader.close
+        reader.unref
+      end
+    end

Review Comment:
   Could you remove this test? We can detect the "source isn't referred" 
problem by crash.



##########
ruby/red-parquet/test/test-arrow-file-reader.rb:
##########
@@ -29,6 +29,40 @@ def setup
     end
   end
 
+  sub_test_case(".open with properties") do
+    data("path" => :path, "stream" => :stream)
+    test("row groups") do |source_type|
+      properties = Parquet::ReaderProperties.new
+      properties.buffer_size = 4096
+      properties.enable_buffered_stream
+      properties.pre_buffer = false
+      assert_true(properties.buffered_stream_enabled?)
+      source = if source_type == :path
+                 @file.path
+               else
+                 Arrow::FileInputStream.new(@file.path)
+               end
+      reader = nil
+      begin
+        Parquet::ArrowFileReader.open(source, properties) do |opened_reader|
+          reader = opened_reader
+          properties.pre_buffer = true
+          properties.disable_buffered_stream
+          properties.buffer_size = 0
+          assert_equal([
+                         Arrow::Table.new(@schema, [[true]]),
+                         Arrow::Table.new(@schema, [[false]])
+                       ],
+                       reader.each_row_group.to_a)
+        end
+      ensure
+        # Release the memory-mapped path before Tempfile removes it on Windows.
+        reader&.unref
+        source.close if source_type == :stream
+      end
+    end
+  end

Review Comment:
   We don't need to add this test because this case is covered by GLib tests. 
If we add support `Parquet::ArrowFileReader.open(source, buffer_size: ...)` 
style API, we can add a test for the API.



##########
c_glib/parquet-glib/arrow-file-reader.cpp:
##########
@@ -426,3 +709,17 @@ gparquet_arrow_file_reader_get_raw(GParquetArrowFileReader 
*arrow_file_reader)
   auto priv = GPARQUET_ARROW_FILE_READER_GET_PRIVATE(arrow_file_reader);
   return priv->arrow_file_reader;
 }
+
+parquet::ReaderProperties
+gparquet_reader_properties_get_raw(GParquetReaderProperties *properties)
+{
+  auto priv = GPARQUET_READER_PROPERTIES_GET_PRIVATE(properties);
+  return priv->properties;
+}
+
+parquet::ArrowReaderProperties
+gparquet_reader_properties_get_arrow_raw(GParquetReaderProperties *properties)
+{
+  auto priv = GPARQUET_READER_PROPERTIES_GET_PRIVATE(properties);
+  return priv->arrow_properties;

Review Comment:
   Could you return a pointer instead of a value like 
`garrow_read_options_get_dictionary_memo_raw()`?
   
   ```suggestion
     return &(priv->arrow_properties);
   ```



##########
c_glib/test/parquet/test-reader-properties.rb:
##########
@@ -0,0 +1,51 @@
+# 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 TestParquetReaderProperties < Test::Unit::TestCase
+  def setup
+    omit("Parquet is required") unless defined?(::Parquet)
+    @properties = Parquet::ReaderProperties.new
+  end
+
+  def test_buffered_stream
+    assert_false(@properties.buffered_stream_enabled?)
+    assert_true(@properties.pre_buffer?)

Review Comment:
   Why do you test `pre_buffer?` in this test? I think that `test_pre_buffer` 
covers `pre_buffer?` cases.



##########
c_glib/test/parquet/test-reader-properties.rb:
##########
@@ -0,0 +1,51 @@
+# 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 TestParquetReaderProperties < Test::Unit::TestCase
+  def setup
+    omit("Parquet is required") unless defined?(::Parquet)
+    @properties = Parquet::ReaderProperties.new
+  end
+
+  def test_buffered_stream
+    assert_false(@properties.buffered_stream_enabled?)
+    assert_true(@properties.pre_buffer?)
+    @properties.enable_buffered_stream
+    assert_true(@properties.pre_buffer?)
+    assert_true(@properties.buffered_stream_enabled?)
+    @properties.pre_buffer = false
+    @properties.disable_buffered_stream
+    assert_false(@properties.pre_buffer?)
+    assert_false(@properties.buffered_stream_enabled?)
+  end
+
+  def test_pre_buffer
+    assert_true(@properties.pre_buffer?)
+    @properties.pre_buffer = false
+    assert_false(@properties.pre_buffer?)
+    assert_false(@properties.buffered_stream_enabled?)
+    @properties.pre_buffer = true
+    assert_true(@properties.pre_buffer?)
+  end
+
+  def test_buffer_size
+    assert_equal(16 * 1024, @properties.buffer_size)
+    @properties.buffer_size = 32 * 1024
+    assert_equal(32 * 1024, @properties.buffer_size)
+    assert_false(@properties.buffered_stream_enabled?)

Review Comment:
   Why do we need to check `buffered_stream_enabled?` in this test?



##########
c_glib/test/parquet/test-reader-properties.rb:
##########
@@ -0,0 +1,51 @@
+# 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 TestParquetReaderProperties < Test::Unit::TestCase
+  def setup
+    omit("Parquet is required") unless defined?(::Parquet)
+    @properties = Parquet::ReaderProperties.new
+  end
+
+  def test_buffered_stream
+    assert_false(@properties.buffered_stream_enabled?)

Review Comment:
   Could you use this for better failure message?
   
   ```suggestion
       assert do
         not @properties.buffered_stream_enabled?
       end
   ```



##########
c_glib/test/parquet/test-arrow-file-reader.rb:
##########
@@ -39,6 +39,109 @@ def setup
     end
   end
 
+  sub_test_case(".new with properties") do

Review Comment:
   Could you use this style like other tests?
   
   ```suggestion
     sub_test_case(".new(properties)") do
   ```



##########
c_glib/parquet-glib/arrow-file-reader.cpp:
##########
@@ -426,3 +709,17 @@ gparquet_arrow_file_reader_get_raw(GParquetArrowFileReader 
*arrow_file_reader)
   auto priv = GPARQUET_ARROW_FILE_READER_GET_PRIVATE(arrow_file_reader);
   return priv->arrow_file_reader;
 }
+
+parquet::ReaderProperties
+gparquet_reader_properties_get_raw(GParquetReaderProperties *properties)
+{
+  auto priv = GPARQUET_READER_PROPERTIES_GET_PRIVATE(properties);
+  return priv->properties;

Review Comment:
   Could you return a pointer instead of a value like 
`garrow_read_options_get_raw()`?
   
   ```suggestion
     return &(priv->properties);
   ```



##########
c_glib/test/parquet/test-arrow-file-reader.rb:
##########
@@ -39,6 +39,109 @@ def setup
     end
   end
 
+  sub_test_case(".new with properties") do
+    data("path" => :path, "stream" => :stream)
+    test("read") do |source_type|
+      properties = Parquet::ReaderProperties.new
+      properties.enable_buffered_stream
+      properties.pre_buffer = false
+      properties.buffer_size = 4096
+      source = if source_type == :path
+                 @file.path
+               else
+                 Arrow::FileInputStream.new(@file.path)
+               end
+      reader = Parquet::ArrowFileReader.new(source, properties)
+      begin
+        assert_equal(@table, reader.read_table)
+        assert_equal(build_table("a" => @a_array.slice(1, 1),
+                                 "b" => @b_array.slice(1, 1)),
+                     reader.read_row_group(1))
+      ensure
+        reader.close
+        reader.unref
+        source.unref if source_type == :stream
+      end
+    end
+
+    test("copies properties") do
+      properties = Parquet::ReaderProperties.new
+      properties.enable_buffered_stream
+      properties.pre_buffer = false
+      properties.buffer_size = 4096
+      reader = Parquet::ArrowFileReader.new(@file.path, properties)
+      begin
+        properties.pre_buffer = true
+        properties.disable_buffered_stream
+        properties.buffer_size = 0
+        properties.unref
+        assert_equal(@table, reader.read_table)
+      ensure
+        reader.close
+        reader.unref
+      end
+    end
+
+    test("retains source") do
+      properties = Parquet::ReaderProperties.new
+      source = Arrow::FileInputStream.new(@file.path)
+      reader = Parquet::ArrowFileReader.new(source, properties)
+      begin
+        assert_equal(source, reader.source)
+        source.unref
+        assert_equal(@table, reader.read_table)
+      ensure
+        reader.close
+        reader.unref
+      end
+    end
+
+    data("path" => :path, "stream" => :stream)
+    test("default properties") do |source_type|
+      source = if source_type == :path
+                 @file.path
+               else
+                 Arrow::FileInputStream.new(@file.path)
+               end
+      reader = Parquet::ArrowFileReader.new(source, nil)
+      begin
+        assert_equal(@table, reader.read_table)
+      ensure
+        reader.close
+        reader.unref
+        source.unref if source_type == :stream
+      end
+    end

Review Comment:
   Could you remove this test? This case is covered by other tests that don't 
pass properties explicitly.



-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to