From 474162481148ead19561a5df6f1669fa94471e81 Mon Sep 17 00:00:00 2001 From: Tiago Campos <13822700+tiagogcampos@users.noreply.github.com> Date: Thu, 5 Sep 2024 22:35:59 +0100 Subject: [PATCH] fix: add validation when json format has unstructured flag enabled (#735) --- crates/arroyo-rpc/src/api_types/connections.rs | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/crates/arroyo-rpc/src/api_types/connections.rs b/crates/arroyo-rpc/src/api_types/connections.rs index ac6ec49cd..fccde33f9 100644 --- a/crates/arroyo-rpc/src/api_types/connections.rs +++ b/crates/arroyo-rpc/src/api_types/connections.rs @@ -283,6 +283,16 @@ impl ConnectionSchema { bail!("raw_string format requires a schema with a single field called `value` of type TEXT"); } } + Some(Format::Json(json_format)) => { + if json_format.unstructured + && (self.fields.len() != 1 + || self.fields.first().unwrap().field_type.r#type + != FieldType::Primitive(PrimitiveType::Json) + || self.fields.first().unwrap().field_name != "value") + { + bail!("json format with unstructured flag enabled requires a schema with a single field called `value` of type JSON"); + } + } _ => { // Right now only RawString has checks, but we may add checks for other formats in the future }