This is an automated email from the ASF dual-hosted git repository. wesm 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 2e04089 ARROW-1736: [GLib] Add GArrowCastOptions:allow-time-truncate 2e04089 is described below commit 2e040896d59dfeea7b05bfc27915efbea59f7171 Author: Kouhei Sutou <k...@clear-code.com> AuthorDate: Thu Oct 26 13:52:23 2017 -0400 ARROW-1736: [GLib] Add GArrowCastOptions:allow-time-truncate Author: Kouhei Sutou <k...@clear-code.com> Closes #1253 from kou/glib-support-allow-time-truncate-cast-option and squashes the following commits: 609eaafb [Kouhei Sutou] [GLib] Add GArrowCastOptions:allow-time-truncate --- c_glib/arrow-glib/compute.cpp | 32 ++++++++++++++++++++++++++++++-- c_glib/test/test-cast.rb | 23 +++++++++++++++++++++++ 2 files changed, 53 insertions(+), 2 deletions(-) diff --git a/c_glib/arrow-glib/compute.cpp b/c_glib/arrow-glib/compute.cpp index 9134aa6..ce427e6 100644 --- a/c_glib/arrow-glib/compute.cpp +++ b/c_glib/arrow-glib/compute.cpp @@ -40,7 +40,8 @@ typedef struct GArrowCastOptionsPrivate_ { enum { PROP_0, - PROP_ALLOW_INT_OVERFLOW + PROP_ALLOW_INT_OVERFLOW, + PROP_ALLOW_TIME_TRUNCATE }; G_DEFINE_TYPE_WITH_PRIVATE(GArrowCastOptions, @@ -64,6 +65,9 @@ garrow_cast_options_set_property(GObject *object, case PROP_ALLOW_INT_OVERFLOW: priv->options.allow_int_overflow = g_value_get_boolean(value); break; + case PROP_ALLOW_TIME_TRUNCATE: + priv->options.allow_time_truncate = g_value_get_boolean(value); + break; default: G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec); break; @@ -82,6 +86,9 @@ garrow_cast_options_get_property(GObject *object, case PROP_ALLOW_INT_OVERFLOW: g_value_set_boolean(value, priv->options.allow_int_overflow); break; + case PROP_ALLOW_TIME_TRUNCATE: + g_value_set_boolean(value, priv->options.allow_time_truncate); + break; default: G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec); break; @@ -103,12 +110,33 @@ garrow_cast_options_class_init(GArrowCastOptionsClass *klass) gobject_class->set_property = garrow_cast_options_set_property; gobject_class->get_property = garrow_cast_options_get_property; - spec = g_param_spec_boolean("allow_int_overflow", + /** + * GArrowCastOptions:allow-int-overflow: + * + * Whether integer overflow is allowed or not. + * + * Since: 0.7.0 + */ + spec = g_param_spec_boolean("allow-int-overflow", "Allow int overflow", "Whether integer overflow is allowed or not", FALSE, static_cast<GParamFlags>(G_PARAM_READWRITE)); g_object_class_install_property(gobject_class, PROP_ALLOW_INT_OVERFLOW, spec); + + /** + * GArrowCastOptions:allow-time-truncate: + * + * Whether truncating time value is allowed or not. + * + * Since: 0.8.0 + */ + spec = g_param_spec_boolean("allow-time-truncate", + "Allow time truncate", + "Whether truncating time value is allowed or not", + FALSE, + static_cast<GParamFlags>(G_PARAM_READWRITE)); + g_object_class_install_property(gobject_class, PROP_ALLOW_TIME_TRUNCATE, spec); } /** diff --git a/c_glib/test/test-cast.rb b/c_glib/test/test-cast.rb index f32cd83..6c29e85 100644 --- a/c_glib/test/test-cast.rb +++ b/c_glib/test/test-cast.rb @@ -42,4 +42,27 @@ class TestCast < Test::Unit::TestCase options)) end end + + sub_test_case("allow-time-truncate") do + def test_default + require_gi(1, 42, 0) + after_epoch = 1504953190854 # 2017-09-09T10:33:10.854Z + second_timestamp = Arrow::TimestampDataType.new(:second) + assert_raise(Arrow::Error::Invalid) do + build_timestamp_array(:milli, [after_epoch]).cast(second_timestamp) + end + end + + def test_true + options = Arrow::CastOptions.new + options.allow_time_truncate = true + after_epoch_in_milli = 1504953190854 # 2017-09-09T10:33:10.854Z + second_array = build_timestamp_array(:second, + [after_epoch_in_milli / 1000]) + milli_array = build_timestamp_array(:milli, [after_epoch_in_milli]) + second_timestamp = Arrow::TimestampDataType.new(:second) + assert_equal(second_array, + milli_array.cast(second_timestamp, options)) + end + end end -- To stop receiving notification emails like this one, please contact ['"commits@arrow.apache.org" <commits@arrow.apache.org>'].