This is an automated email from the ASF dual-hosted git repository.
kou 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 6ef9888 ARROW-2733: [GLib] Cast garrow_decimal128 to gint64
6ef9888 is described below
commit 6ef98885a02f7d2bc41ce5665bff52b720352a09
Author: yosuke shiro <[email protected]>
AuthorDate: Sat Jun 23 20:42:20 2018 +0900
ARROW-2733: [GLib] Cast garrow_decimal128 to gint64
Add garrow_decimal128_to_integer().
Author: yosuke shiro <[email protected]>
Closes #2157 from shiro615/cast-garrow-decimal128-to-gint64 and squashes
the following commits:
94b703ac [yosuke shiro] [GLib] Cast garrow_decimal128 to gint64
---
c_glib/arrow-glib/decimal.cpp | 15 +++++++++++++++
c_glib/arrow-glib/decimal.h | 1 +
c_glib/test/test-decimal.rb | 6 ++++++
3 files changed, 22 insertions(+)
diff --git a/c_glib/arrow-glib/decimal.cpp b/c_glib/arrow-glib/decimal.cpp
index 04787ab..9c0cf03 100644
--- a/c_glib/arrow-glib/decimal.cpp
+++ b/c_glib/arrow-glib/decimal.cpp
@@ -202,6 +202,21 @@ garrow_decimal128_negate(GArrowDecimal128 *decimal)
arrow_decimal->Negate();
}
+/**
+ * garrow_decimal128_to_integer:
+ * @decimal: A #GArrowDecimal128.
+ *
+ * Returns: The 64-bit integer representation of the decimal.
+ *
+ * Since: 0.10.0
+ */
+gint64
+garrow_decimal128_to_integer(GArrowDecimal128 *decimal)
+{
+ auto arrow_decimal = garrow_decimal128_get_raw(decimal);
+ return static_cast<int64_t>(*arrow_decimal);
+}
+
G_END_DECLS
GArrowDecimal128 *
diff --git a/c_glib/arrow-glib/decimal.h b/c_glib/arrow-glib/decimal.h
index 90cb247..ba9e18d 100644
--- a/c_glib/arrow-glib/decimal.h
+++ b/c_glib/arrow-glib/decimal.h
@@ -42,5 +42,6 @@ gchar *garrow_decimal128_to_string_scale(GArrowDecimal128
*decimal,
gchar *garrow_decimal128_to_string(GArrowDecimal128 *decimal);
void garrow_decimal128_abs(GArrowDecimal128 *decimal);
void garrow_decimal128_negate(GArrowDecimal128 *decimal);
+gint64 garrow_decimal128_to_integer(GArrowDecimal128 *decimal);
G_END_DECLS
diff --git a/c_glib/test/test-decimal.rb b/c_glib/test/test-decimal.rb
index 03e88cf..2528883 100644
--- a/c_glib/test/test-decimal.rb
+++ b/c_glib/test/test-decimal.rb
@@ -46,4 +46,10 @@ class TestDecimal128 < Test::Unit::TestCase
decimal.negate
assert_equal(positive_value, decimal.to_s)
end
+
+ def test_to_integer
+ integer_data = 999999999999999999
+ decimal = Arrow::Decimal128.new(integer_data)
+ assert_equal(integer_data, decimal.to_i)
+ end
end