[ https://issues.apache.org/jira/browse/ARROW-1736?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16220894#comment-16220894 ]
ASF GitHub Bot commented on ARROW-1736: --------------------------------------- wesm closed pull request #1253: ARROW-1736: [GLib] Add GArrowCastOptions:allow-time-truncate URL: https://github.com/apache/arrow/pull/1253 This is a PR merged from a forked repository. As GitHub hides the original diff on merge, it is displayed below for the sake of provenance: As this is a foreign pull request (from a fork), the diff is supplied below (as it won't show otherwise due to GitHub magic): diff --git a/c_glib/arrow-glib/compute.cpp b/c_glib/arrow-glib/compute.cpp index 9134aa675..ce427e616 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 f32cd83cc..6c29e85f1 100644 --- a/c_glib/test/test-cast.rb +++ b/c_glib/test/test-cast.rb @@ -42,4 +42,27 @@ def test_true 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 ---------------------------------------------------------------- This is an automated message from the Apache Git Service. To respond to the message, please log on GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: us...@infra.apache.org > [GLib] Add GArrowCastOptions:allow-time-truncate > ------------------------------------------------ > > Key: ARROW-1736 > URL: https://issues.apache.org/jira/browse/ARROW-1736 > Project: Apache Arrow > Issue Type: New Feature > Components: GLib > Reporter: Kouhei Sutou > Assignee: Kouhei Sutou > Labels: pull-request-available > Fix For: 0.8.0 > > -- This message was sent by Atlassian JIRA (v6.4.14#64029)