kou commented on code in PR #48704:
URL: https://github.com/apache/arrow/pull/48704#discussion_r2656939435


##########
ruby/red-arrow-format/lib/arrow-format/array.rb:
##########
@@ -309,40 +309,57 @@ def to_a
   end
 
   class DecimalArray < FixedSizeBinaryArray
-  end
-
-  class Decimal128Array < DecimalArray
     def to_a
       byte_width = @type.byte_width
-      buffer_types = [:u64, :s64] # TODO: big endian support
+      buffer_types = [:u64] * (byte_width / 8 - 1) + [:s64]
       values = 0.step(@size * byte_width - 1, byte_width).collect do |offset|
         @values_buffer.get_values(buffer_types, offset)
       end
       apply_validity(values).collect do |value|
         if value.nil?
           nil
         else
-          low, high = value
-          BigDecimal(format_value(low, high))
+          BigDecimal(format_value(value))
         end
       end
     end
 
     private
-    def format_value(low, high)
+    def format_value(components)
+      highest = components.last
       width = @type.precision
-      width += 1 if high < 0
-      value = (high << 64) + low
-      string = value.to_s.ljust(width, "0")
+      width += 1 if highest < 0
+      value = 0
+      components.reverse_each do |component|
+        value = (value << 64) + component
+      end
+      string = value.to_s
       if @type.scale < 0
         string << ("0" * [email protected])

Review Comment:
   Yes. `123` + `scale: -3` is `123000`.
   
   BTW, why did you try `"0" * -4`? In this context, `@type.scale` is negative. 
So `"0" * --4` should be tried for the case.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to