jiangzhx commented on issue #5635:
URL:
https://github.com/apache/arrow-datafusion/issues/5635#issuecomment-1477217345
@BubbaJoe i still working on your "getting an error when calling
record_batches_to_json_rows on the queries:"
something so weird.
```
let sql = "SELECT to_timestamp(a) as u from t"; //fine
// let sql = "SELECT to_date(a) as u from t"; //fine
// let sql = "SELECT to_date(a) as u from t group by u"; //got
error
// let sql = "SELECT to_timestamp(a) as u from t group by u"; //got
error
let batches = ctx.sql(sql).await?.collect().await.unwrap();
let list: Vec<_> = record_batches_to_json_rows(&batches)?; //got
error here
```
also i write a testcase for record_batches_to_json_rows,look like everything
works fine.
```
#[cfg(test)]
mod tests {
use arrow::array::Date32Builder;
use arrow::json::writer::record_batches_to_json_rows;
use arrow::json::LineDelimitedWriter;
use arrow::record_batch::RecordBatch;
use arrow_schema::{DataType, Field, Schema};
use chrono::DateTime;
use serde_json::Value;
use std::sync::Arc;
#[test]
fn work_well() {
let mut builder = Date32Builder::new();
builder.append_value(
i32::try_from(
DateTime::parse_from_rfc3339("2021-02-04T05:01:14.274000+00:00")
.unwrap()
.timestamp()
/ (60 * 60 * 24),
)
.unwrap(),
);
builder.append_value(
i32::try_from(
DateTime::parse_from_rfc3339("2023-03-05T05:01:14.274000+00:00")
.unwrap()
.timestamp()
/ (60 * 60 * 24),
)
.unwrap(),
);
let arr_date32 = builder.finish();
let schema = Schema::new(vec![Field::new("date32", DataType::Date32,
true)]);
let schema = Arc::new(schema);
let batch = RecordBatch::try_new(schema,
vec![Arc::new(arr_date32)]).unwrap();
let mut buf = Vec::new();
{
let mut writer = LineDelimitedWriter::new(&mut buf);
writer.write_batches(&[batch.clone()]).unwrap();
}
let actual: Vec<Option<Value>> = buf
.split(|b| *b == b'\n')
.map(|s| (!s.is_empty()).then(||
serde_json::from_slice(s).unwrap()))
.collect();
println!("{:?}", actual);
//everything works fine.
let rows = record_batches_to_json_rows(&vec![batch]);
}
}
```
--
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]