praveentiru opened a new issue #879:
URL: https://github.com/apache/arrow-datafusion/issues/879


   Posted from stackoverflow: [Original 
post](https://stackoverflow.com/questions/68750346/rust-datafusion-float-operations-in-dataframe-select)
   I am calculating fraction of orders that were not filled from a large list 
of order lines. I am using datafusion crate to perform analysis. I want to 
build a table that looks as shown below:
   
   ```
   +--------+--------------+---------------+--------------+
   | Month  | Total Orders | Missed Orders | Missed Ratio |
   +--------+--------------+---------------+--------------+
   | 201803 | 10           | 3             | 0.3          |
   +--------+--------------+---------------+--------------+
   ```
   
   To achieve this I have return following code:
   ```
       let result = record_count
           .select(vec![col("Month"), 
               col("Total Orders"), 
               col("Missed Orders"),
               (col("Missed Orders").cast_to(&DataType::Float64, 
&m_order_schema).unwrap() / col("Total Orders").cast_to(&DataType::Float64, 
&t_order_schema).unwrap()).alias("Service Level")])?;
   ```
   The total orders and missed orders column as integers so, I am casting them 
to float to get fraction. But, Service Level column comes out as integer with 
all zeros. Result looks as shown below:
   ```
   +--------+--------------+---------------+--------------+
   | Month  | Total Orders | Missed Orders | Missed Ratio |
   +--------+--------------+---------------+--------------+
   | 201803 | 10           | 3             | 0            |
   +--------+--------------+---------------+--------------+
   ```
   
   Question: How to perform floating point operations with integer columns?


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