forked from apache/arrow
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
apacheGH-40402: [GLib] Add missing compute function options classes (a…
…pache#40403) ### 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. ### 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. ### Are these changes tested? Yes ### Are there any user-facing changes? Yes * GitHub Issue: apache#40402 Lead-authored-by: Sten Larsson <[email protected]> Co-authored-by: Sutou Kouhei <[email protected]> Signed-off-by: Sutou Kouhei <[email protected]>
- Loading branch information
1 parent
2a4df7a
commit bdd04c0
Showing
8 changed files
with
980 additions
and
0 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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_set_symbol | ||
@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) | ||
end | ||
end |