kou commented on code in PR #4402:
URL: https://github.com/apache/arrow-adbc/pull/4402#discussion_r3418499228


##########
ruby/lib/adbc/database.rb:
##########
@@ -18,13 +18,20 @@
 module ADBC
   class Database
     class << self
-      def open(**options)
+      def new
+        database = super
+        database.set_load_flags(LoadFlags::DEFAULT)
+        database
+      end

Review Comment:
   In general,  we should not replace `new` class method in Ruby. We should 
replace `initialize` instance method in Ruby.
   
   BTW, how about setting the default load flags in GLib not Ruby?
   
   ```diff
   diff --git a/glib/adbc-glib/database.c b/glib/adbc-glib/database.c
   index 886b3474b..1225b3116 100644
   --- a/glib/adbc-glib/database.c
   +++ b/glib/adbc-glib/database.c
   @@ -75,6 +75,11 @@ GADBCDatabase* gadbc_database_new(GError** error) {
      AdbcStatusCode status_code = AdbcDatabaseNew(&(priv->adbc_database), 
&adbc_error);
      priv->initialized =
          gadbc_error_check(error, status_code, &adbc_error, 
"[adbc][database][new]");
   +  if (priv->initialized) {
   +    status_code =
   +      AdbcDriverManagerDatabaseSetLoadFlags(&(priv->adbc_database), 
GADBC_LOAD_FLAGS_DEFAULT, &adbc_error);
   +    priv->initialized = gadbc_error_check(error, status_code, &adbc_error, 
"[adbc][database][set-load-flags]");
   +  }
      if (!priv->initialized) {
        g_object_unref(database);
        return NULL;
   diff --git a/glib/adbc-glib/database.h b/glib/adbc-glib/database.h
   index 5f510b346..1c0464987 100644
   --- a/glib/adbc-glib/database.h
   +++ b/glib/adbc-glib/database.h
   @@ -48,7 +48,7 @@ typedef enum {
    } GADBCLoadFlags;
    
    /**
   - * GADBC_LOAD_FLAGAS_DEFAULT:
   + * GADBC_LOAD_FLAGS_DEFAULT:
     *
     * The default GADBCLoadFlags.
     *
   ```



##########
ruby/test/test-database.rb:
##########
@@ -0,0 +1,75 @@
+# 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 DatabaseTest < Test::Unit::TestCase
+  sub_test_case(".open") do
+    def test_default_load_flags
+      assert_nothing_raised do
+        ADBC::Database.open(driver: "adbc_driver_sqlite", uri: ":memory:") do 
|_database|
+        end
+      end
+    end
+
+    def test_load_flags_override
+      assert_nothing_raised do
+        ADBC::Database.open(driver: "adbc_driver_sqlite",
+                            uri: ":memory:",
+                            load_flags: ADBC::LoadFlags::DEFAULT) do 
|_database|
+        end
+      end
+    end
+
+    sub_test_case("manifest") do
+      def setup
+        @tmpdir = Dir.mktmpdir
+        File.write(File.join(@tmpdir, "testdriver.toml"), <<~TOML)
+          name = "test driver"
+          version = "0.1.0"
+
+          [Driver]
+          shared = "adbc_driver_sqlite"
+        TOML
+        @original_driver_path = ENV["ADBC_DRIVER_PATH"]
+        ENV["ADBC_DRIVER_PATH"] = @tmpdir
+      end
+
+      def teardown
+        ENV["ADBC_DRIVER_PATH"] = @original_driver_path
+        FileUtils.remove_entry(@tmpdir)
+      end

Review Comment:
   We can simplify this:
   
   ```suggestion
         def setup
           Dir.mktmpdir do |tmpdir|
             File.write(File.join(tmpdir, "testdriver.toml"), <<~TOML)
               name = "test driver"
               version = "0.1.0"
   
               [Driver]
               shared = "adbc_driver_sqlite"
             TOML
             driver_path, ENV["ADBC_DRIVER_PATH"] = ENV["ADBC_DRIVER_PATH"], 
tmpdir
             begin
               yield
             ensure
               ENV["ADBC_DRIVER_PATH"] = driver_path
             end
           end
         end
   ```



##########
ruby/test/test-database.rb:
##########
@@ -0,0 +1,75 @@
+# 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 DatabaseTest < Test::Unit::TestCase
+  sub_test_case(".open") do
+    def test_default_load_flags
+      assert_nothing_raised do
+        ADBC::Database.open(driver: "adbc_driver_sqlite", uri: ":memory:") do 
|_database|
+        end
+      end

Review Comment:
   We don't need this because other test such as 
https://github.com/apache/arrow-adbc/blob/cd6e396f413ad075f6c87f089e09d0aae0ce4626/ruby/test/test-connection.rb#L24-L30
 covers this.



##########
ruby/test/test-database.rb:
##########
@@ -0,0 +1,75 @@
+# 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 DatabaseTest < Test::Unit::TestCase
+  sub_test_case(".open") do
+    def test_default_load_flags
+      assert_nothing_raised do
+        ADBC::Database.open(driver: "adbc_driver_sqlite", uri: ":memory:") do 
|_database|
+        end
+      end
+    end
+
+    def test_load_flags_override
+      assert_nothing_raised do
+        ADBC::Database.open(driver: "adbc_driver_sqlite",
+                            uri: ":memory:",
+                            load_flags: ADBC::LoadFlags::DEFAULT) do 
|_database|
+        end
+      end
+    end
+
+    sub_test_case("manifest") do
+      def setup
+        @tmpdir = Dir.mktmpdir
+        File.write(File.join(@tmpdir, "testdriver.toml"), <<~TOML)
+          name = "test driver"
+          version = "0.1.0"
+
+          [Driver]
+          shared = "adbc_driver_sqlite"
+        TOML
+        @original_driver_path = ENV["ADBC_DRIVER_PATH"]
+        ENV["ADBC_DRIVER_PATH"] = @tmpdir
+      end
+
+      def teardown
+        ENV["ADBC_DRIVER_PATH"] = @original_driver_path
+        FileUtils.remove_entry(@tmpdir)
+      end
+
+      def test_search_env_finds_driver
+        assert_nothing_raised do
+          ADBC::Database.open(driver: "testdriver",
+                              uri: ":memory:",
+                              load_flags: ADBC::LoadFlags::SEARCH_ENV) do 
|_database|
+          end
+        end
+      end
+
+      def test_no_flags_cannot_find_driver
+        error = assert_raise_kind_of(ADBC::Error) do
+          ADBC::Database.open(driver: "testdriver",
+                              uri: ":memory:",
+                              load_flags: ADBC::LoadFlags.new(0)) do 
|_database|
+          end
+        end
+        assert_match(/not enabled at run time/, error.message)

Review Comment:
   How about asserting more specific error class instead of error message?
   
   ```suggestion
           assert_raise(ADBC::Error::NotFound) do
             ADBC::Database.open(driver: "testdriver",
                                 uri: ":memory:",
                                 load_flags: ADBC::LoadFlags.new(0)) do 
|_database|
             end
           end
   ```



##########
ruby/test/test-database.rb:
##########
@@ -0,0 +1,75 @@
+# 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 DatabaseTest < Test::Unit::TestCase
+  sub_test_case(".open") do
+    def test_default_load_flags
+      assert_nothing_raised do
+        ADBC::Database.open(driver: "adbc_driver_sqlite", uri: ":memory:") do 
|_database|
+        end
+      end
+    end
+
+    def test_load_flags_override
+      assert_nothing_raised do
+        ADBC::Database.open(driver: "adbc_driver_sqlite",
+                            uri: ":memory:",
+                            load_flags: ADBC::LoadFlags::DEFAULT) do 
|_database|
+        end
+      end
+    end
+
+    sub_test_case("manifest") do
+      def setup
+        @tmpdir = Dir.mktmpdir
+        File.write(File.join(@tmpdir, "testdriver.toml"), <<~TOML)
+          name = "test driver"
+          version = "0.1.0"
+
+          [Driver]
+          shared = "adbc_driver_sqlite"
+        TOML
+        @original_driver_path = ENV["ADBC_DRIVER_PATH"]
+        ENV["ADBC_DRIVER_PATH"] = @tmpdir
+      end
+
+      def teardown
+        ENV["ADBC_DRIVER_PATH"] = @original_driver_path
+        FileUtils.remove_entry(@tmpdir)
+      end
+
+      def test_search_env_finds_driver
+        assert_nothing_raised do
+          ADBC::Database.open(driver: "testdriver",
+                              uri: ":memory:",
+                              load_flags: ADBC::LoadFlags::SEARCH_ENV) do 
|_database|
+          end
+        end

Review Comment:
   `assert_nothing_raised` is meaningless. Let's use a real assertion:
   
   ```suggestion
           ADBC::Database.open(driver: "testdriver",
                               uri: ":memory:",
                               load_flags: ADBC::LoadFlags::SEARCH_ENV) do 
|database|
             database.connect do |connection|                          
                 assert_equal([
                        Arrow::Table.new("1" => Arrow::Int64Array.new([1])),
                        -1,
                      ],
                      connection.query("SELECT 1"))                    
             end
           end
   ```



##########
ruby/lib/adbc/database.rb:
##########
@@ -18,13 +18,20 @@
 module ADBC
   class Database
     class << self
-      def open(**options)
+      def new
+        database = super
+        database.set_load_flags(LoadFlags::DEFAULT)
+        database
+      end
+
+      def open(load_flags: nil, **options)
         database = new
         need_release = true
         begin
           options.each do |key, value|
-            database.set_option(key, value)
+            database.set_option(key.to_s, value)

Review Comment:
   Do we need this `.to_s`?



##########
ruby/test/test-database.rb:
##########
@@ -0,0 +1,75 @@
+# 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 DatabaseTest < Test::Unit::TestCase
+  sub_test_case(".open") do
+    def test_default_load_flags
+      assert_nothing_raised do
+        ADBC::Database.open(driver: "adbc_driver_sqlite", uri: ":memory:") do 
|_database|
+        end
+      end
+    end
+
+    def test_load_flags_override
+      assert_nothing_raised do
+        ADBC::Database.open(driver: "adbc_driver_sqlite",
+                            uri: ":memory:",
+                            load_flags: ADBC::LoadFlags::DEFAULT) do 
|_database|
+        end
+      end
+    end
+
+    sub_test_case("manifest") do
+      def setup
+        @tmpdir = Dir.mktmpdir
+        File.write(File.join(@tmpdir, "testdriver.toml"), <<~TOML)
+          name = "test driver"
+          version = "0.1.0"
+
+          [Driver]
+          shared = "adbc_driver_sqlite"
+        TOML
+        @original_driver_path = ENV["ADBC_DRIVER_PATH"]
+        ENV["ADBC_DRIVER_PATH"] = @tmpdir
+      end
+
+      def teardown
+        ENV["ADBC_DRIVER_PATH"] = @original_driver_path
+        FileUtils.remove_entry(@tmpdir)
+      end
+
+      def test_search_env_finds_driver
+        assert_nothing_raised do
+          ADBC::Database.open(driver: "testdriver",
+                              uri: ":memory:",
+                              load_flags: ADBC::LoadFlags::SEARCH_ENV) do 
|_database|
+          end
+        end
+      end
+
+      def test_no_flags_cannot_find_driver
+        error = assert_raise_kind_of(ADBC::Error) do
+          ADBC::Database.open(driver: "testdriver",
+                              uri: ":memory:",
+                              load_flags: ADBC::LoadFlags.new(0)) do 
|_database|

Review Comment:
   We can simplify this:
   
   ```suggestion
                                 load_flags: 0) do |_database|
   ```



##########
ruby/test/test-database.rb:
##########
@@ -0,0 +1,75 @@
+# 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 DatabaseTest < Test::Unit::TestCase
+  sub_test_case(".open") do
+    def test_default_load_flags
+      assert_nothing_raised do
+        ADBC::Database.open(driver: "adbc_driver_sqlite", uri: ":memory:") do 
|_database|
+        end
+      end
+    end
+
+    def test_load_flags_override
+      assert_nothing_raised do
+        ADBC::Database.open(driver: "adbc_driver_sqlite",
+                            uri: ":memory:",
+                            load_flags: ADBC::LoadFlags::DEFAULT) do 
|_database|
+        end
+      end
+    end

Review Comment:
   We can remove this because `manifest` test case covers this case.



-- 
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