Skip to content

Commit 0655f3b

Browse files
authored
Sort inferred fields for first event (#450)
FileWriter expects sorted events so position of fields matter. This is because it looks for data using offsets. This fixes an issue where events sent during the first minute of server's operation were getting lost.
1 parent 3e5548d commit 0655f3b

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

server/src/event/format/json.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ use arrow_array::RecordBatch;
2424
use arrow_json::reader::{infer_json_schema_from_iterator, ReaderBuilder};
2525
use arrow_schema::{DataType, Field, Fields, Schema};
2626
use datafusion::arrow::util::bit_util::round_upto_multiple_of_64;
27+
use itertools::Itertools;
2728
use serde_json::Value;
2829
use std::{collections::HashMap, sync::Arc};
2930

@@ -73,7 +74,12 @@ impl EventFormat for Event {
7374
return Err(anyhow!("Could not merge schema of this event with that of the existing stream. {:?}", err));
7475
}
7576
is_first = true;
76-
infer_schema.fields.iter().cloned().collect()
77+
infer_schema
78+
.fields
79+
.iter()
80+
.cloned()
81+
.sorted_by(|a, b| a.name().cmp(b.name()))
82+
.collect()
7783
}
7884
Err(err) => {
7985
return Err(anyhow!(

0 commit comments

Comments
 (0)