[ 
https://issues.apache.org/jira/browse/AVRO-3331?focusedWorklogId=719356&page=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-719356
 ]

ASF GitHub Bot logged work on AVRO-3331:
----------------------------------------

                Author: ASF GitHub Bot
            Created on: 02/Feb/22 13:14
            Start Date: 02/Feb/22 13:14
    Worklog Time Spent: 10m 
      Work Description: tschilling-natzka commented on a change in pull request 
#1501:
URL: https://github.com/apache/avro/pull/1501#discussion_r797586473



##########
File path: lang/rust/src/decimal.rs
##########
@@ -45,30 +67,271 @@ impl Decimal {
         let sign_byte = 0xFF * u8::from(self.value.sign() == Sign::Minus);
         let mut decimal_bytes = vec![sign_byte; len];
         let raw_bytes = self.value.to_signed_bytes_be();
-        let num_raw_bytes = raw_bytes.len();
-        let start_byte_index = 
len.checked_sub(num_raw_bytes).ok_or(Error::SignExtend {
+        let raw_bytes_len = raw_bytes.len();
+        let start_byte_index = 
len.checked_sub(raw_bytes_len).ok_or(Error::SignExtend {
             requested: len,
-            needed: num_raw_bytes,
+            needed: raw_bytes_len,
         })?;
         decimal_bytes[start_byte_index..].copy_from_slice(&raw_bytes);
         Ok(decimal_bytes)
     }
+
+    pub fn from_f64(decimal: f64) -> AvroResult<Self> {

Review comment:
       I'm not convinced this method should be provided. Looking at the 
`rust_decimal` library it seems to be rather complicated to implement 
correctly: 
[Decimal::from_f64](https://docs.rs/rust_decimal/1.21.0/src/rust_decimal/decimal.rs.html#1861)
   
   I think `from_bytes(bytes, scale, precision)` makes sense. And something 
based on integers would make sense:
   
   ```rust
   from_i128(mantissa: i128, scale: u32, precision: u32)
   ```
   If users want to convert from `f64` they can go via `rust_decimal`.




-- 
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]


Issue Time Tracking
-------------------

    Worklog Id:     (was: 719356)
    Time Spent: 0.5h  (was: 20m)

> Rust: Cannot extract Decimal value
> ----------------------------------
>
>                 Key: AVRO-3331
>                 URL: https://issues.apache.org/jira/browse/AVRO-3331
>             Project: Apache Avro
>          Issue Type: Bug
>          Components: rust
>            Reporter: Thomas Schilling
>            Assignee: Martin Tzvetanov Grigorov
>            Priority: Major
>              Labels: pull-request-available
>          Time Spent: 0.5h
>  Remaining Estimate: 0h
>
> The [Decimal|https://docs.rs/avro-rs/latest/avro_rs/struct.Decimal.html] type 
> (as of 0.13) doesn't have any methods or trait implementations that allow 
> users to extract the value. The only workaround I could think of would be to 
> parse the output of the `Debug` implementation. But that's clearly very 
> inefficient and fragile.
> The (unreleased?) version 0.14 also seems to have the same issue 
> ([source|https://github.com/apache/avro/blob/master/lang/rust/src/decimal.rs]).
> It might just be enough to make the {{to_vec }}method public and specify how 
> to interpret the result vector.



--
This message was sent by Atlassian Jira
(v8.20.1#820001)

Reply via email to