Skip to content

Commit 184b208

Browse files
author
Devdutt Shenoi
committed
doc: improve explainer
1 parent 7cd9536 commit 184b208

File tree

2 files changed

+16
-14
lines changed

2 files changed

+16
-14
lines changed

src/response.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,10 @@
1616
*
1717
*/
1818

19-
use crate::{handlers::http::query::QueryError, utils::arrow::record_batches_to_json};
2019
use datafusion::arrow::record_batch::RecordBatch;
21-
use serde_json::{json, Map, Value};
20+
use serde_json::{json, Value};
21+
22+
use crate::{handlers::http::query::QueryError, utils::arrow::record_batches_to_json};
2223

2324
pub struct QueryResponse {
2425
pub records: Vec<RecordBatch>,
@@ -28,9 +29,9 @@ pub struct QueryResponse {
2829
}
2930

3031
impl QueryResponse {
31-
/// TODO: maybe this can be futher optimized by directly converting `arrow` to `serde_json` instead of serializing to bytes
32+
/// Convert into a JSON response
3233
pub fn to_json(&self) -> Result<Value, QueryError> {
33-
let mut json: Vec<Map<String, Value>> = record_batches_to_json(&self.records)?;
34+
let mut json = record_batches_to_json(&self.records)?;
3435

3536
if self.fill_null {
3637
for object in json.iter_mut() {

src/utils/arrow/mod.rs

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -22,20 +22,20 @@ use std::{
2222
sync::Arc,
2323
};
2424

25+
use arrow::error::Result;
2526
use arrow_array::{ArrayRef, RecordBatch, StringArray, TimestampMillisecondArray, UInt64Array};
26-
use arrow_schema::{ArrowError, DataType, Field, Schema, TimeUnit};
27+
use arrow_schema::{DataType, Field, Schema, TimeUnit};
2728
use arrow_select::take::take;
29+
pub use batch_adapter::adapt_batch;
2830
use chrono::{DateTime, Utc};
2931
use itertools::Itertools;
30-
31-
pub mod batch_adapter;
32-
pub mod flight;
33-
34-
pub use batch_adapter::adapt_batch;
3532
use serde_json::{Map, Value};
3633

3734
use crate::event::DEFAULT_TIMESTAMP_KEY;
3835

36+
pub mod batch_adapter;
37+
pub mod flight;
38+
3939
/// Converts a slice of record batches to JSON.
4040
///
4141
/// # Arguments
@@ -46,9 +46,10 @@ use crate::event::DEFAULT_TIMESTAMP_KEY;
4646
/// * Result<Vec<Map<String, Value>>>
4747
///
4848
/// A vector of JSON objects representing the record batches.
49-
pub fn record_batches_to_json(
50-
records: &[RecordBatch],
51-
) -> Result<Vec<Map<String, Value>>, ArrowError> {
49+
///
50+
/// TODO: maybe this can be futher optimized by directly converting `arrow`
51+
/// to an in-memory type instead of serializing to bytes.
52+
pub fn record_batches_to_json(records: &[RecordBatch]) -> Result<Vec<Map<String, Value>>> {
5253
let buf = vec![];
5354
let mut writer = arrow_json::ArrayWriter::new(buf);
5455
for record in records {
@@ -101,7 +102,7 @@ pub fn add_parseable_fields(
101102
rb: RecordBatch,
102103
p_timestamp: DateTime<Utc>,
103104
p_custom_fields: &HashMap<String, String>,
104-
) -> Result<RecordBatch, ArrowError> {
105+
) -> Result<RecordBatch> {
105106
// Return Result for proper error handling
106107

107108
// Add custom fields in sorted order

0 commit comments

Comments
 (0)