You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@arrow.apache.org by ko...@apache.org on 2019/01/09 00:28:14 UTC
[arrow] branch master updated: ARROW-4175: [GLib] Add support for
decimal compare operators
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 420c949 ARROW-4175: [GLib] Add support for decimal compare operators
420c949 is described below
commit 420c949fd4e593fb0303954092b3d8a46a7aa864
Author: Yosuke Shiro <yo...@gmail.com>
AuthorDate: Wed Jan 9 09:28:03 2019 +0900
ARROW-4175: [GLib] Add support for decimal compare operators
Author: Yosuke Shiro <yo...@gmail.com>
Author: Kouhei Sutou <ko...@clear-code.com>
Closes #3346 from shiro615/glib-add-support-for-decimal-compare-operators and squashes the following commits:
28871fd6 <Kouhei Sutou> Fix documents
e81d4146 <Yosuke Shiro> Unify test case comparisons
0791c4f1 <Yosuke Shiro> Use rubyish method name
54f46039 <Yosuke Shiro> Add a test for equal
943c2364 <Yosuke Shiro> Rename 'more than' to 'greater than'
181e0544 <Yosuke Shiro> Add support for decimal compare operators
---
c_glib/arrow-glib/decimal128.cpp | 98 +++++++++++++++++++++++++++++++++++++++-
c_glib/arrow-glib/decimal128.h | 15 ++++++
c_glib/test/test-decimal128.rb | 97 +++++++++++++++++++++++++++++++++++++++
3 files changed, 209 insertions(+), 1 deletion(-)
diff --git a/c_glib/arrow-glib/decimal128.cpp b/c_glib/arrow-glib/decimal128.cpp
index d87a501..a49dba5 100644
--- a/c_glib/arrow-glib/decimal128.cpp
+++ b/c_glib/arrow-glib/decimal128.cpp
@@ -141,7 +141,8 @@ garrow_decimal128_new_integer(const gint64 data)
* @decimal: A #GArrowDecimal128.
* @other_decimal: A #GArrowDecimal128 to be compared.
*
- * Returns: %TRUE if both of them is the same value, %FALSE otherwise.
+ * Returns: %TRUE if the decimal is equal to the other decimal, %FALSE
+ * otherwise.
*
* Since: 0.12.0
*/
@@ -155,6 +156,101 @@ garrow_decimal128_equal(GArrowDecimal128 *decimal,
}
/**
+ * garrow_decimal128_not_equal:
+ * @decimal: A #GArrowDecimal128.
+ * @other_decimal: A #GArrowDecimal128 to be compared.
+ *
+ * Returns: %TRUE if the decimal isn't equal to the other decimal,
+ * %FALSE otherwise.
+ *
+ * Since: 0.12.0
+ */
+gboolean
+garrow_decimal128_not_equal(GArrowDecimal128 *decimal,
+ GArrowDecimal128 *other_decimal)
+{
+ const auto arrow_decimal = garrow_decimal128_get_raw(decimal);
+ const auto arrow_other_decimal = garrow_decimal128_get_raw(other_decimal);
+ return *arrow_decimal != *arrow_other_decimal;
+}
+
+/**
+ * garrow_decimal128_less_than:
+ * @decimal: A #GArrowDecimal128.
+ * @other_decimal: A #GArrowDecimal128 to be compared.
+ *
+ * Returns: %TRUE if the decimal is less than the other decimal,
+ * %FALSE otherwise.
+ *
+ * Since: 0.12.0
+ */
+gboolean
+garrow_decimal128_less_than(GArrowDecimal128 *decimal,
+ GArrowDecimal128 *other_decimal)
+{
+ const auto arrow_decimal = garrow_decimal128_get_raw(decimal);
+ const auto arrow_other_decimal = garrow_decimal128_get_raw(other_decimal);
+ return *arrow_decimal < *arrow_other_decimal;
+}
+
+/**
+ * garrow_decimal128_less_than_or_equal:
+ * @decimal: A #GArrowDecimal128.
+ * @other_decimal: A #GArrowDecimal128 to be compared.
+ *
+ * Returns: %TRUE if the decimal is less than the other decimal
+ * or equal to the other decimal, %FALSE otherwise.
+ *
+ * Since: 0.12.0
+ */
+gboolean
+garrow_decimal128_less_than_or_equal(GArrowDecimal128 *decimal,
+ GArrowDecimal128 *other_decimal)
+{
+ const auto arrow_decimal = garrow_decimal128_get_raw(decimal);
+ const auto arrow_other_decimal = garrow_decimal128_get_raw(other_decimal);
+ return *arrow_decimal <= *arrow_other_decimal;
+}
+
+/**
+ * garrow_decimal128_greater_than:
+ * @decimal: A #GArrowDecimal128.
+ * @other_decimal: A #GArrowDecimal128 to be compared.
+ *
+ * Returns: %TRUE if the decimal is greater than the other decimal,
+ * %FALSE otherwise.
+ *
+ * Since: 0.12.0
+ */
+gboolean
+garrow_decimal128_greater_than(GArrowDecimal128 *decimal,
+ GArrowDecimal128 *other_decimal)
+{
+ const auto arrow_decimal = garrow_decimal128_get_raw(decimal);
+ const auto arrow_other_decimal = garrow_decimal128_get_raw(other_decimal);
+ return *arrow_decimal > *arrow_other_decimal;
+}
+
+/**
+ * garrow_decimal128_greater_than_or_equal:
+ * @decimal: A #GArrowDecimal128.
+ * @other_decimal: A #GArrowDecimal128 to be compared.
+ *
+ * Returns: %TRUE if the decimal is greater than the other decimal
+ * or equal to the other decimal, %FALSE otherwise.
+ *
+ * Since: 0.12.0
+ */
+gboolean
+garrow_decimal128_greater_than_or_equal(GArrowDecimal128 *decimal,
+ GArrowDecimal128 *other_decimal)
+{
+ const auto arrow_decimal = garrow_decimal128_get_raw(decimal);
+ const auto arrow_other_decimal = garrow_decimal128_get_raw(other_decimal);
+ return *arrow_decimal >= *arrow_other_decimal;
+}
+
+/**
* garrow_decimal128_to_string_scale:
* @decimal: A #GArrowDecimal128.
* @scale: The scale of the decimal.
diff --git a/c_glib/arrow-glib/decimal128.h b/c_glib/arrow-glib/decimal128.h
index e8fa599..e7601a4 100644
--- a/c_glib/arrow-glib/decimal128.h
+++ b/c_glib/arrow-glib/decimal128.h
@@ -41,6 +41,21 @@ GArrowDecimal128 *garrow_decimal128_new_integer(const gint64 data);
GARROW_AVAILABLE_IN_0_12
gboolean garrow_decimal128_equal(GArrowDecimal128 *decimal,
GArrowDecimal128 *other_decimal);
+GARROW_AVAILABLE_IN_0_12
+gboolean garrow_decimal128_not_equal(GArrowDecimal128 *decimal,
+ GArrowDecimal128 *other_decimal);
+GARROW_AVAILABLE_IN_0_12
+gboolean garrow_decimal128_less_than(GArrowDecimal128 *decimal,
+ GArrowDecimal128 *other_decimal);
+GARROW_AVAILABLE_IN_0_12
+gboolean garrow_decimal128_less_than_or_equal(GArrowDecimal128 *decimal,
+ GArrowDecimal128 *other_decimal);
+GARROW_AVAILABLE_IN_0_12
+gboolean garrow_decimal128_greater_than(GArrowDecimal128 *decimal,
+ GArrowDecimal128 *other_decimal);
+GARROW_AVAILABLE_IN_0_12
+gboolean garrow_decimal128_greater_than_or_equal(GArrowDecimal128 *decimal,
+ GArrowDecimal128 *other_decimal);
gchar *garrow_decimal128_to_string_scale(GArrowDecimal128 *decimal,
gint32 scale);
gchar *garrow_decimal128_to_string(GArrowDecimal128 *decimal);
diff --git a/c_glib/test/test-decimal128.rb b/c_glib/test/test-decimal128.rb
index 99f1912..de9453c 100644
--- a/c_glib/test/test-decimal128.rb
+++ b/c_glib/test/test-decimal128.rb
@@ -106,4 +106,101 @@ class TestDecimal128 < Test::Unit::TestCase
decimal1.divide(decimal2)
end
end
+
+ def test_equal
+ decimal = Arrow::Decimal128.new(10)
+ other_decimal1 = Arrow::Decimal128.new(10)
+ other_decimal2 = Arrow::Decimal128.new(11)
+ assert_equal([
+ true,
+ false,
+ ],
+ [
+ decimal == other_decimal1,
+ decimal == other_decimal2,
+ ])
+ end
+
+ def test_not_equal
+ require_gi_bindings(3, 3, 1)
+ decimal = Arrow::Decimal128.new(10)
+ other_decimal1 = Arrow::Decimal128.new(10)
+ other_decimal2 = Arrow::Decimal128.new(11)
+ assert_equal([
+ false,
+ true,
+ ],
+ [
+ decimal != other_decimal1,
+ decimal != other_decimal2,
+ ])
+ end
+
+ def test_less_than
+ require_gi_bindings(3, 3, 1)
+ decimal = Arrow::Decimal128.new(10)
+ other_decimal1 = Arrow::Decimal128.new(11)
+ other_decimal2 = Arrow::Decimal128.new(9)
+ assert_equal([
+ true,
+ false,
+ false
+ ],
+ [
+ decimal < other_decimal1,
+ decimal < other_decimal2,
+ decimal < decimal,
+ ])
+ end
+
+ def test_less_than_or_equal
+ require_gi_bindings(3, 3, 1)
+ decimal = Arrow::Decimal128.new(10)
+ other_decimal1 = Arrow::Decimal128.new(11)
+ other_decimal2 = Arrow::Decimal128.new(9)
+ assert_equal([
+ true,
+ false,
+ true
+ ],
+ [
+ decimal <= other_decimal1,
+ decimal <= other_decimal2,
+ decimal <= decimal
+ ])
+ end
+
+ def test_greater_than
+ require_gi_bindings(3, 3, 1)
+ decimal = Arrow::Decimal128.new(10)
+ other_decimal1 = Arrow::Decimal128.new(11)
+ other_decimal2 = Arrow::Decimal128.new(9)
+ assert_equal([
+ false,
+ true,
+ false
+ ],
+ [
+ decimal > other_decimal1,
+ decimal > other_decimal2,
+ decimal > decimal
+ ])
+ end
+
+ def test_greater_than_or_equal
+ require_gi_bindings(3, 3, 1)
+ decimal = Arrow::Decimal128.new(10)
+ other_decimal1 = Arrow::Decimal128.new(11)
+ other_decimal2 = Arrow::Decimal128.new(9)
+ assert_equal([
+ false,
+ true,
+ true
+ ],
+ [
+ decimal >= other_decimal1,
+ decimal >= other_decimal2,
+ decimal >= decimal
+ ])
+ end
end