alamb commented on issue #879:
URL:
https://github.com/apache/arrow-datafusion/issues/879#issuecomment-932901002
@praveentiru I don't normally use the dataframe API (and for your case, the
SQL interface might work better).
But in any event, I tried to reproduce the problem you are having, and I was
not able to. Here is the program I used:
```rust
async fn test_cast() {
let mut ctx = ExecutionContext::new();
let month: Date32Array = vec![Some(1000)].into_iter().collect();
let total_orders: Int64Array = vec![Some(10)].into_iter().collect();
let missed_orders: Int64Array = vec![Some(3)].into_iter().collect();
let batch = RecordBatch::try_from_iter(vec![
("Month", Arc::new(month) as ArrayRef),
("Total Orders", Arc::new(total_orders) as ArrayRef),
("Missed Orders", Arc::new(missed_orders) as ArrayRef),
]).unwrap();
let m_order_schema = DFSchema::try_from_qualified_schema(
"m_orders",
batch.schema().as_ref()
).unwrap();
let t_order_schema = DFSchema::try_from_qualified_schema(
"t_orders",
batch.schema().as_ref()
).unwrap();
let table = MemTable::try_new(batch.schema(),
vec![vec![batch]]).unwrap();
let record_count = ctx.read_table(Arc::new(table)).unwrap();
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")]).unwrap();
result.show().await.unwrap();
}
```
And when I ran that code, it appears to produce the output you expected:
```
Starting tests
+------------+--------------+---------------+---------------+
| Month | Total Orders | Missed Orders | Service Level |
+------------+--------------+---------------+---------------+
| 1972-09-27 | 10 | 3 | 0.3 |
+------------+--------------+---------------+---------------+
```
--
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]