Skip to content

Commit c11641f

Browse files
allow type casting in static schema (#729)
if field is defined as float, below values (examples) can be accepted - 100,-100.45, 100.23, "200.45"
1 parent 0966b08 commit c11641f

File tree

2 files changed

+11
-5
lines changed

2 files changed

+11
-5
lines changed

server/src/event/format.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ pub trait EventFormat: Sized {
4242
self,
4343
schema: HashMap<String, Arc<Field>>,
4444
time_partition: Option<String>,
45+
static_schema_flag: Option<String>,
4546
) -> Result<(Self::Data, EventSchema, bool, Tags, Metadata), AnyError>;
4647
fn decode(data: Self::Data, schema: Arc<Schema>) -> Result<RecordBatch, AnyError>;
4748
fn into_recordbatch(
@@ -50,8 +51,11 @@ pub trait EventFormat: Sized {
5051
time_partition: Option<String>,
5152
static_schema_flag: Option<String>,
5253
) -> Result<(RecordBatch, bool), AnyError> {
53-
let (data, mut schema, is_first, tags, metadata) =
54-
self.to_data(storage_schema.clone(), time_partition)?;
54+
let (data, mut schema, is_first, tags, metadata) = self.to_data(
55+
storage_schema.clone(),
56+
time_partition,
57+
static_schema_flag.clone(),
58+
)?;
5559

5660
if get_field(&schema, DEFAULT_TAGS_KEY).is_some() {
5761
return Err(anyhow!("field {} is a reserved field", DEFAULT_TAGS_KEY));

server/src/event/format/json.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ impl EventFormat for Event {
4646
self,
4747
schema: HashMap<String, Arc<Field>>,
4848
time_partition: Option<String>,
49+
static_schema_flag: Option<String>,
4950
) -> Result<(Self::Data, Vec<Arc<Field>>, bool, Tags, Metadata), anyhow::Error> {
5051
let data = flatten_json_body(self.data, time_partition)?;
5152
let stream_schema = schema;
@@ -91,9 +92,10 @@ impl EventFormat for Event {
9192
},
9293
};
9394

94-
if value_arr
95-
.iter()
96-
.any(|value| fields_mismatch(&schema, value))
95+
if static_schema_flag.is_none()
96+
&& value_arr
97+
.iter()
98+
.any(|value| fields_mismatch(&schema, value))
9799
{
98100
return Err(anyhow!(
99101
"Could not process this event due to mismatch in datatype"

0 commit comments

Comments
 (0)