You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@arrow.apache.org by "stenlarsson (via GitHub)" <gi...@apache.org> on 2024/03/07 16:03:37 UTC

[PR] GH-40402: [GLib] Add missing compute function options classes [arrow]

stenlarsson opened a new pull request, #40403:
URL: https://github.com/apache/arrow/pull/40403

   <!--
   Thanks for opening a pull request!
   If this is your first pull request you can find detailed information on how 
   to contribute here:
     * [New Contributor's Guide](https://arrow.apache.org/docs/dev/developers/guide/step_by_step/pr_lifecycle.html#reviews-and-merge-of-the-pull-request)
     * [Contributing Overview](https://arrow.apache.org/docs/dev/developers/overview.html)
   
   
   If this is not a [minor PR](https://github.com/apache/arrow/blob/main/CONTRIBUTING.md#Minor-Fixes). Could you open an issue for this pull request on GitHub? https://github.com/apache/arrow/issues/new/choose
   
   Opening GitHub issues ahead of time contributes to the [Openness](http://theapacheway.com/open/#:~:text=Openness%20allows%20new%20users%20the,must%20happen%20in%20the%20open.) of the Apache Arrow project.
   
   Then could you also rename the pull request title in the following format?
   
       GH-${GITHUB_ISSUE_ID}: [${COMPONENT}] ${SUMMARY}
   
   or
   
       MINOR: [${COMPONENT}] ${SUMMARY}
   
   In the case of PARQUET issues on JIRA the title also supports:
   
       PARQUET-${JIRA_ISSUE_ID}: [${COMPONENT}] ${SUMMARY}
   
   -->
   
   ### Rationale for this change
   
   In most cases the options to compute functions are optional, but there are cases where they are required. The following compute functions are not possible to use in Ruby because the required options classes are missing from the GLib bindings:
   
   * `split_pattern`
   * `strftime` (can technically be used)
   * `strptime`
   * `struct_field`
   
   There are probably more functions that cannot be used, but this is a start.
   
   <!--
    Why are you proposing this change? If this is already explained clearly in the issue then this section is not needed.
    Explaining clearly why changes are proposed helps reviewers understand your changes and offer better suggestions for fixes.  
   -->
   
   ### What changes are included in this PR?
   
   The following GLib classes are added:
   
   * `GArrowSplitPatternOptions`
   * `GArrowStrftimeOptions`
   * `GArrowStrptimeOptions`
   * `GArrowStructFieldOptions`
   
   To be able to return an error, a separate function for setting the field_ref on StructFieldOptions is used instead of a set_property function.
   
   <!--
   There is no need to duplicate the description in the issue here but it is sometimes worth providing a summary of the individual changes in this PR.
   -->
   
   ### Are these changes tested?
   
   Yes
   
   <!--
   We typically require tests for all PRs in order to:
   1. Prevent the code from being accidentally broken by subsequent changes
   2. Serve as another way to document the expected behavior of the code
   
   If tests are not included in your PR, please explain why (for example, are they covered by existing tests)?
   -->
   
   ### Are there any user-facing changes?
   
   Yes
   
   <!--
   If there are user-facing changes then we may require documentation to be updated before approving the PR.
   -->
   
   <!--
   If there are any breaking changes to public APIs, please uncomment the line below and explain which changes are breaking.
   -->
   <!-- **This PR includes breaking changes to public APIs.** -->
   
   <!--
   Please uncomment the line below (and provide explanation) if the changes fix either (a) a security vulnerability, (b) a bug that caused incorrect or invalid data to be produced, or (c) a bug that causes a crash (even when the API contract is upheld). We use this to highlight fixes to issues that may affect users without their knowledge. For this reason, fixing bugs that cause errors don't count, since those are usually obvious.
   -->
   <!-- **This PR contains a "Critical Fix".** -->


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


Re: [PR] GH-40402: [GLib] Add missing compute function options classes [arrow]

Posted by "github-actions[bot] (via GitHub)" <gi...@apache.org>.
github-actions[bot] commented on PR #40403:
URL: https://github.com/apache/arrow/pull/40403#issuecomment-1983843298

   :warning: GitHub issue #40402 **has been automatically assigned in GitHub** to PR creator.


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


Re: [PR] GH-40402: [GLib] Add missing compute function options classes [arrow]

Posted by "kou (via GitHub)" <gi...@apache.org>.
kou commented on code in PR #40403:
URL: https://github.com/apache/arrow/pull/40403#discussion_r1517160018


##########
c_glib/arrow-glib/compute.cpp:
##########
@@ -240,6 +241,16 @@ G_BEGIN_DECLS
  * #GArrowRunEndEncodeOptions is a class to customize the
  * `run_end_encode` function.
  *
+ * #GArrowStrptimeOptions is a class to customize the `strptime` function.
+ *
+ * #GArrowStrftimeOptions is a class to customize the `strftime` function.
+ *
+ * #GArrowSplitPatternOptions is a class to customize the `split_pattern` and
+ *  `split_pattern_regex` functions.
+ *
+ * #GArrowStructFieldOptions is a class to customize the `struct_field`
+ *  function.

Review Comment:
   ```suggestion
    * function.
   ```



##########
c_glib/test/test-split-pattern-options.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 TestSplitPatternOptions < Test::Unit::TestCase
+  include Helper::Buildable
+
+  def setup
+    @options = Arrow::SplitPatternOptions.new
+  end
+
+  def test_pattern_property
+    assert_equal("", @options.pattern)
+    @options.pattern = "foo"
+    assert_equal("foo", @options.pattern)
+  end
+
+  def test_max_splits_property
+    assert_equal(-1, @options.max_splits)
+    @options.max_splits = 1
+    assert_equal(1, @options.max_splits)
+  end
+
+  def test_reverse_property
+    assert do
+      !@options.reverse?
+    end
+    @options.reverse = true
+    assert do
+      @options.reverse?
+    end
+  end
+
+  def test_split_pattern_regex_function
+    args = [
+      Arrow::ArrayDatum.new(build_string_array(["hello world"])),
+    ]
+    @options.pattern = "[lo]+"
+    split_pattern_regex_function = Arrow::Function.find("split_pattern_regex")
+    assert_equal(build_list_array(Arrow::StringDataType.new, [["he", " w", "r", "d"]]),
+      split_pattern_regex_function.execute(args, @options).value)

Review Comment:
   ```suggestion
                    split_pattern_regex_function.execute(args, @options).value)
   ```



##########
c_glib/test/test-struct-field-options.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 TestStructFieldOptions < Test::Unit::TestCase
+  include Helper::Buildable
+
+  def setup
+    @options = Arrow::StructFieldOptions.new
+  end
+
+  def test_default
+    assert_equal("", @options.field_ref)
+  end
+
+  def test_set_string
+    @options.field_ref = "foo"
+    assert_equal("foo", @options.field_ref)
+  end
+
+  def test_sset_ymbol

Review Comment:
   ```suggestion
     def test_set_symbol
   ```



##########
c_glib/test/test-struct-field-options.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 TestStructFieldOptions < Test::Unit::TestCase
+  include Helper::Buildable
+
+  def setup
+    @options = Arrow::StructFieldOptions.new
+  end
+
+  def test_default
+    assert_equal("", @options.field_ref)
+  end
+
+  def test_set_string
+    @options.field_ref = "foo"
+    assert_equal("foo", @options.field_ref)
+  end
+
+  def test_sset_ymbol
+    @options.field_ref = :foo
+    assert_equal("foo", @options.field_ref)
+  end
+
+  def test_set_dot_path
+    @options.field_ref = ".foo.bar"
+    assert_equal(".foo.bar", @options.field_ref)
+  end
+
+  def test_set_invalid
+    message = "[struct-field-options][set-field-ref]: Invalid: Dot path '[foo]' contained an unterminated index"
+    assert_raise(Arrow::Error::Invalid.new(message)) do
+      @options.field_ref = "[foo]"
+    end
+  end
+
+  def test_struct_field_function
+    fields = [
+      Arrow::Field.new("score", Arrow::Int8DataType.new),
+      Arrow::Field.new("enabled", Arrow::BooleanDataType.new),
+    ]
+    structs = [
+      {
+        "score" => -29,
+        "enabled" => true,
+      },
+      {
+        "score" => 2,
+        "enabled" => false,
+      },
+      nil,
+    ]
+    args = [
+      Arrow::ArrayDatum.new(build_struct_array(fields, structs)),
+    ]
+    @options.field_ref = "score"
+    struct_field_function = Arrow::Function.find("struct_field")
+    assert_equal(build_int8_array([-29, 2, nil]),
+      struct_field_function.execute(args, @options).value)

Review Comment:
   ```suggestion
                    struct_field_function.execute(args, @options).value)
   ```



##########
c_glib/arrow-glib/compute.cpp:
##########
@@ -240,6 +241,16 @@ G_BEGIN_DECLS
  * #GArrowRunEndEncodeOptions is a class to customize the
  * `run_end_encode` function.
  *
+ * #GArrowStrptimeOptions is a class to customize the `strptime` function.
+ *
+ * #GArrowStrftimeOptions is a class to customize the `strftime` function.
+ *
+ * #GArrowSplitPatternOptions is a class to customize the `split_pattern` and
+ *  `split_pattern_regex` functions.

Review Comment:
   ```suggestion
    * `split_pattern_regex` functions.
   ```



##########
c_glib/test/test-strptime-options.rb:
##########
@@ -0,0 +1,57 @@
+# 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 TestStrptimeOptions < Test::Unit::TestCase
+  include Helper::Buildable
+
+  def setup
+    @options = Arrow::StrptimeOptions.new
+  end
+
+  def test_format_property
+    assert_equal("", @options.format)
+    @options.format = "%Y-%m-%d"
+    assert_equal("%Y-%m-%d", @options.format)
+  end
+
+  def test_unit_property
+    assert_equal(Arrow::TimeUnit::MICRO, @options.unit)
+    @options.unit = :nano
+    assert_equal(Arrow::TimeUnit::NANO, @options.unit)
+  end
+
+  def test_error_is_null_property
+    assert do
+      !@options.error_is_null?
+    end
+    @options.error_is_null = true
+    assert do
+      @options.error_is_null?
+    end
+  end
+
+  def test_strptime_function
+    args = [
+      Arrow::ArrayDatum.new(build_string_array(["2017-09-09T10:33:10"])),
+    ]
+    @options.format = "%Y-%m-%dT%H:%M:%S"
+    @options.unit = :milli
+    strptime_function = Arrow::Function.find("strptime")
+    assert_equal(build_timestamp_array(:milli, [1504953190000]),
+      strptime_function.execute(args, @options).value)

Review Comment:
   ```suggestion
                   strptime_function.execute(args, @options).value)
   ```



##########
c_glib/arrow-glib/compute.cpp:
##########
@@ -2773,6 +2784,7 @@ garrow_filter_options_get_property(GObject *object,
   }
 }
 
+

Review Comment:
   ```suggestion
   ```



##########
c_glib/test/test-strftime-options.rb:
##########
@@ -0,0 +1,47 @@
+# 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 TestStrftimeOptions < Test::Unit::TestCase
+  include Helper::Buildable
+
+  def setup
+    @options = Arrow::StrftimeOptions.new
+  end
+
+  def test_format_property
+    assert_equal("%Y-%m-%dT%H:%M:%S", @options.format)
+    @options.format = "%Y-%m-%d"
+    assert_equal("%Y-%m-%d", @options.format)
+  end
+
+  def test_locale_property
+    assert_equal("C", @options.locale)
+    @options.locale = "sv_SE.UTF-8"
+    assert_equal("sv_SE.UTF-8", @options.locale)
+  end
+
+  def test_strftime_function
+    omit("Missing tzdata on Windows") if Gem.win_platform?
+    args = [
+      Arrow::ArrayDatum.new(build_timestamp_array(:milli, [1504953190854])),
+    ]
+    @options.format = "%Y-%m-%d"
+    strftime_function = Arrow::Function.find("strftime")
+    assert_equal(build_string_array(["2017-09-09"]),
+      strftime_function.execute(args, @options).value)

Review Comment:
   ```suggestion
                    strftime_function.execute(args, @options).value)
   ```



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


Re: [PR] GH-40402: [GLib] Add missing compute function options classes [arrow]

Posted by "conbench-apache-arrow[bot] (via GitHub)" <gi...@apache.org>.
conbench-apache-arrow[bot] commented on PR #40403:
URL: https://github.com/apache/arrow/pull/40403#issuecomment-1985679610

   After merging your PR, Conbench analyzed the 7 benchmarking runs that have been run so far on merge-commit bdd04c0d470e193a8e4cb0fc1aa71eaa4cfb1197.
   
   There were 2 benchmark results indicating a performance regression:
   
   - Commit Run on `ursa-i9-9960x` at [2024-03-08 09:49:01Z](https://conbench.ursa.dev/compare/runs/ca22c55a599346feac666c3f452c0ffa...4cd6c49c388f4824a5806ca8bc1029f0/)
     - [`tpch` (R) with engine=arrow, format=native, language=R, memory_map=False, query_id=TPCH-17, scale_factor=10](https://conbench.ursa.dev/compare/benchmarks/065ead6c81107d658000ead56807bec7...065eaf742883731d8000dda71c7cf7ef)
     - [`tpch` (R) with engine=arrow, format=native, language=R, memory_map=False, query_id=TPCH-17, scale_factor=1](https://conbench.ursa.dev/compare/benchmarks/065ead69a1ac7167800084adbc43b65e...065eaf700bd4717c8000ab7f5c692f1b)
   
   The [full Conbench report](https://github.com/apache/arrow/runs/22437384102) has more details. It also includes information about 1 possible false positive for unstable benchmarks that are known to sometimes produce them.


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


Re: [PR] GH-40402: [GLib] Add missing compute function options classes [arrow]

Posted by "kou (via GitHub)" <gi...@apache.org>.
kou commented on code in PR #40403:
URL: https://github.com/apache/arrow/pull/40403#discussion_r1517164461


##########
c_glib/test/test-strptime-options.rb:
##########
@@ -0,0 +1,57 @@
+# 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 TestStrptimeOptions < Test::Unit::TestCase
+  include Helper::Buildable
+
+  def setup
+    @options = Arrow::StrptimeOptions.new
+  end
+
+  def test_format_property
+    assert_equal("", @options.format)
+    @options.format = "%Y-%m-%d"
+    assert_equal("%Y-%m-%d", @options.format)
+  end
+
+  def test_unit_property
+    assert_equal(Arrow::TimeUnit::MICRO, @options.unit)
+    @options.unit = :nano
+    assert_equal(Arrow::TimeUnit::NANO, @options.unit)
+  end
+
+  def test_error_is_null_property
+    assert do
+      !@options.error_is_null?
+    end
+    @options.error_is_null = true
+    assert do
+      @options.error_is_null?
+    end
+  end
+
+  def test_strptime_function
+    args = [
+      Arrow::ArrayDatum.new(build_string_array(["2017-09-09T10:33:10"])),
+    ]
+    @options.format = "%Y-%m-%dT%H:%M:%S"
+    @options.unit = :milli
+    strptime_function = Arrow::Function.find("strptime")
+    assert_equal(build_timestamp_array(:milli, [1504953190000]),
+                strptime_function.execute(args, @options).value)

Review Comment:
   ```suggestion
                    strptime_function.execute(args, @options).value)
   ```



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


Re: [PR] GH-40402: [GLib] Add missing compute function options classes [arrow]

Posted by "kou (via GitHub)" <gi...@apache.org>.
kou merged PR #40403:
URL: https://github.com/apache/arrow/pull/40403


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