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 24f83be ARROW-4632: [Ruby] Add BigDecimal#to_arrow
24f83be is described below
commit 24f83be6e241f3f8464a49c6c45d486a7c4e4bc9
Author: Kenta Murata <[email protected]>
AuthorDate: Wed Feb 20 11:05:01 2019 +0900
ARROW-4632: [Ruby] Add BigDecimal#to_arrow
Author: Kenta Murata <[email protected]>
Closes #3709 from mrkn/ruby_bigdecimal_to_arrow and squashes the following
commits:
28e7f89b <Kenta Murata> Fix test code following the review comments
0cab2720 <Kenta Murata> Add BigDecimal#to_arrow
---
ruby/red-arrow/lib/arrow/bigdecimal-extension.rb | 24 ++++++++++++++++++++++
.../lib/arrow/decimal128-array-builder.rb | 4 ++--
ruby/red-arrow/test/test-bigdecimal.rb | 24 ++++++++++++++++++++++
3 files changed, 50 insertions(+), 2 deletions(-)
diff --git a/ruby/red-arrow/lib/arrow/bigdecimal-extension.rb
b/ruby/red-arrow/lib/arrow/bigdecimal-extension.rb
new file mode 100644
index 0000000..a663f70
--- /dev/null
+++ b/ruby/red-arrow/lib/arrow/bigdecimal-extension.rb
@@ -0,0 +1,24 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements. See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership. The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied. See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+require "bigdecimal"
+
+class BigDecimal
+ def to_arrow
+ Arrow::Decimal128.new(to_s)
+ end
+end
diff --git a/ruby/red-arrow/lib/arrow/decimal128-array-builder.rb
b/ruby/red-arrow/lib/arrow/decimal128-array-builder.rb
index 9a849d4..cdf1696 100644
--- a/ruby/red-arrow/lib/arrow/decimal128-array-builder.rb
+++ b/ruby/red-arrow/lib/arrow/decimal128-array-builder.rb
@@ -15,7 +15,7 @@
# specific language governing permissions and limitations
# under the License.
-require "bigdecimal"
+require "arrow/bigdecimal-extension"
module Arrow
class Decimal128ArrayBuilder
@@ -36,7 +36,7 @@ module Arrow
when Float
value = Decimal128.new(value.to_s)
when BigDecimal
- value = Decimal128.new(value.to_s)
+ value = value.to_arrow
end
append_value_raw(value)
end
diff --git a/ruby/red-arrow/test/test-bigdecimal.rb
b/ruby/red-arrow/test/test-bigdecimal.rb
new file mode 100644
index 0000000..3874a38
--- /dev/null
+++ b/ruby/red-arrow/test/test-bigdecimal.rb
@@ -0,0 +1,24 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements. See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership. The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied. See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+class BigDecimalTest < Test::Unit::TestCase
+ test("#to_arrow") do
+ arrow_decimal = BigDecimal("3.14").to_arrow
+ assert_equal(Arrow::Decimal128.new("3.14"),
+ BigDecimal("3.14").to_arrow)
+ end
+end