{"record":{"id":"5486e1d2a5ad7023","repo":"risingwavelabs/risingwave","slug":"must-have-exactly-1-buffer-in-a-jsonb-array","errorCode":null,"errorMessage":"Must have exactly 1 buffer in a jsonb array","messagePattern":"Must have exactly 1 buffer in a jsonb array","errorType":"error_code","errorClass":"ArrayError","httpStatus":null,"severity":"error","filePath":"src/common/src/array/jsonb_array.rs","lineNumber":110,"sourceCode":"        Self::ArrayType {\n            bitmap: self.bitmap.finish(),\n            data: self.builder.finish(),\n        }\n    }\n}\n\nimpl JsonbArrayBuilder {\n    pub fn writer(&mut self) -> JsonbWriter<'_> {\n        JsonbWriter::new(self)\n    }\n}\n\nimpl JsonbArray {\n    /// Loads a `JsonbArray` from a protobuf array.\n    ///\n    /// See also `JsonbArray::to_protobuf`.\n    pub fn from_protobuf(array: &PbArray) -> ArrayResult<ArrayImpl> {\n        ensure!(\n            array.values.len() == 1,\n            \"Must have exactly 1 buffer in a jsonb array\"\n        );\n        let arr = JsonbArray {\n            bitmap: array.get_null_bitmap()?.into(),\n            data: jsonbb::Value::from_bytes(&array.values[0].body),\n        };\n        Ok(arr.into())\n    }\n}\n\nimpl Array for JsonbArray {\n    type Builder = JsonbArrayBuilder;\n    type OwnedItem = JsonbVal;\n    type RefItem<'a> = JsonbRef<'a>;\n\n    unsafe fn raw_value_at_unchecked(&self, idx: usize) -> Self::RefItem<'_> {\n        JsonbRef(self.data.as_array().unwrap().get(idx).unwrap())","sourceCodeStart":92,"sourceCodeEnd":128,"githubUrl":"https://github.com/risingwavelabs/risingwave/blob/6469eb736d691e8e9b8a419a57edd6429ca77417/src/common/src/array/jsonb_array.rs#L92-L128","documentation":"`JsonbArray::from_protobuf` requires that the protobuf array carries exactly one values buffer whose `body` holds the serialized jsonbb bytes. If `array.values.len() != 1`, the jsonb payload is malformed for this array type and decoding is aborted with this message.","triggerScenarios":"Calling `JsonbArray::from_protobuf(&pb_array)` when `pb_array.values` is empty or contains more than one buffer (e.g. a buffer produced by a non-jsonb array type was mislabeled as Jsonb).","commonSituations":"Schema/type mismatches where a column's array type changed but old data remains; corrupted or hand-built protobuf arrays; writing a jsonb array with `to_protobuf` from a mismatched struct.","solutions":["Ensure the jsonb array is serialized via `JsonbArray::to_protobuf`, which always emits exactly one values buffer.","Check that the column type in the stream plan matches the actual data type (Jsonb) before deserialization.","If data came from an older version, re-ingest or migrate rather than decoding directly.","Validate `array.values.len() == 1` upstream and return a clearer error."],"exampleFix":"// before\nlet arr = JsonbArray::from_protobuf(&pb_array)?;\n// after\nensure!(pb_array.values.len() == 1, \"jsonb array requires exactly 1 buffer, got {}\", pb_array.values.len());\nlet arr = JsonbArray::from_protobuf(&pb_array)?;","handlingStrategy":"validation","validationCode":"if pb_array.values.len() != 1 { return Err(\"jsonb array requires exactly 1 buffer\".into()); }","typeGuard":"fn is_single_buffer_jsonb(a: &PbArray) -> bool {\n    a.array_type == PbArrayType::Jsonb as i32 && a.values.len() == 1\n}","tryCatchPattern":null,"preventionTips":["Always serialize jsonb arrays via JsonbArray::to_protobuf","Assert array_type matches the decoding array type before from_protobuf","Never hand-build PbArray for jsonb data"],"tags":["rust","array","jsonb","deserialization"],"backgroundTag":"unexpected-response-shape","analyzedSha":"6469eb736d691e8e9b8a419a57edd6429ca77417","analyzedAt":"2026-09-11T21:06:21.487Z","contentChangedAt":"2026-09-11T21:06:21.487Z","schemaVersion":2},"datasetVersion":"2026-09-14T16:17:12.679Z"}