This is an automated email from the ASF dual-hosted git repository. shiro pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/arrow.git
The following commit(s) were added to refs/heads/master by this push: new 6dbd1ec ARROW-3864: [GLib] Add support for allow-float-truncate cast option 6dbd1ec is described below commit 6dbd1ecfd081a7366068f1bcdbece612706ad6ed Author: Kouhei Sutou <k...@clear-code.com> AuthorDate: Sat Nov 24 22:49:29 2018 +0900 ARROW-3864: [GLib] Add support for allow-float-truncate cast option Author: Kouhei Sutou <k...@clear-code.com> Closes #3023 from kou/glib-add-allow-float-truncate-cast-options and squashes the following commits: 57611105 <Kouhei Sutou> Add support for allow-float-truncate cast option --- c_glib/arrow-glib/compute.cpp | 28 +++++++++++++++++++++++++--- c_glib/test/test-cast.rb | 17 +++++++++++++++++ 2 files changed, 42 insertions(+), 3 deletions(-) diff --git a/c_glib/arrow-glib/compute.cpp b/c_glib/arrow-glib/compute.cpp index ce427e6..2039eea 100644 --- a/c_glib/arrow-glib/compute.cpp +++ b/c_glib/arrow-glib/compute.cpp @@ -41,7 +41,8 @@ typedef struct GArrowCastOptionsPrivate_ { enum { PROP_0, PROP_ALLOW_INT_OVERFLOW, - PROP_ALLOW_TIME_TRUNCATE + PROP_ALLOW_TIME_TRUNCATE, + PROP_ALLOW_FLOAT_TRUNCATE }; G_DEFINE_TYPE_WITH_PRIVATE(GArrowCastOptions, @@ -68,6 +69,9 @@ garrow_cast_options_set_property(GObject *object, case PROP_ALLOW_TIME_TRUNCATE: priv->options.allow_time_truncate = g_value_get_boolean(value); break; + case PROP_ALLOW_FLOAT_TRUNCATE: + priv->options.allow_float_truncate = g_value_get_boolean(value); + break; default: G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec); break; @@ -89,6 +93,9 @@ garrow_cast_options_get_property(GObject *object, case PROP_ALLOW_TIME_TRUNCATE: g_value_set_boolean(value, priv->options.allow_time_truncate); break; + case PROP_ALLOW_FLOAT_TRUNCATE: + g_value_set_boolean(value, priv->options.allow_float_truncate); + break; default: G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec); break; @@ -103,13 +110,12 @@ garrow_cast_options_init(GArrowCastOptions *object) static void garrow_cast_options_class_init(GArrowCastOptionsClass *klass) { - GParamSpec *spec; - auto gobject_class = G_OBJECT_CLASS(klass); gobject_class->set_property = garrow_cast_options_set_property; gobject_class->get_property = garrow_cast_options_get_property; + GParamSpec *spec; /** * GArrowCastOptions:allow-int-overflow: * @@ -137,6 +143,20 @@ garrow_cast_options_class_init(GArrowCastOptionsClass *klass) FALSE, static_cast<GParamFlags>(G_PARAM_READWRITE)); g_object_class_install_property(gobject_class, PROP_ALLOW_TIME_TRUNCATE, spec); + + /** + * GArrowCastOptions:allow-float-truncate: + * + * Whether truncating float value is allowed or not. + * + * Since: 0.12.0 + */ + spec = g_param_spec_boolean("allow-float-truncate", + "Allow float truncate", + "Whether truncating float value is allowed or not", + FALSE, + static_cast<GParamFlags>(G_PARAM_READWRITE)); + g_object_class_install_property(gobject_class, PROP_ALLOW_FLOAT_TRUNCATE, spec); } /** @@ -161,6 +181,8 @@ garrow_cast_options_new_raw(arrow::compute::CastOptions *arrow_cast_options) auto cast_options = g_object_new(GARROW_TYPE_CAST_OPTIONS, "allow-int-overflow", arrow_cast_options->allow_int_overflow, + "allow-time-truncate", arrow_cast_options->allow_time_truncate, + "allow-float-truncate", arrow_cast_options->allow_float_truncate, NULL); return GARROW_CAST_OPTIONS(cast_options); } diff --git a/c_glib/test/test-cast.rb b/c_glib/test/test-cast.rb index 6c29e85..2512e05 100644 --- a/c_glib/test/test-cast.rb +++ b/c_glib/test/test-cast.rb @@ -65,4 +65,21 @@ class TestCast < Test::Unit::TestCase milli_array.cast(second_timestamp, options)) end end + + sub_test_case("allow-float-truncate") do + def test_default + require_gi(1, 42, 0) + assert_raise(Arrow::Error::Invalid) do + build_float_array([1.1]).cast(Arrow::Int8DataType.new) + end + end + + def test_true + options = Arrow::CastOptions.new + options.allow_float_truncate = true + int8_data_type = Arrow::Int8DataType.new + assert_equal(build_int8_array([1]), + build_float_array([1.1]).cast(int8_data_type, options)) + end + end end