Encode a `Value` as MessagePack bytes for JSON/Array/Set/Record storage. For `Value::String` input, the string is first parsed as JSON so that downstream JSON path operators see a real structure rather than an opaque string literal.
(value: &Value, col_name: &str)
| 17 | /// downstream JSON path operators see a real structure rather than an opaque |
| 18 | /// string literal. |
| 19 | fn encode_as_msgpack(value: &Value, col_name: &str) -> Result<Vec<u8>, ColumnarError> { |
| 20 | let to_encode: std::borrow::Cow<'_, Value> = match value { |
| 21 | Value::String(s) => { |
| 22 | let parsed = sonic_rs::from_str::<serde_json::Value>(s).map_err(|e| { |
| 23 | ColumnarError::JsonParse { |
| 24 | column: col_name.to_string(), |
| 25 | source: e, |
| 26 | } |
| 27 | })?; |
| 28 | std::borrow::Cow::Owned(Value::from(parsed)) |
| 29 | } |
| 30 | other => std::borrow::Cow::Borrowed(other), |
| 31 | }; |
| 32 | value_to_msgpack(&to_encode).map_err(|e| ColumnarError::MsgpackSerialize { |
| 33 | column: col_name.to_string(), |
| 34 | source: e, |
| 35 | }) |
| 36 | } |
| 37 | |
| 38 | /// Parse a PostgreSQL range literal into a structured Value. |
| 39 | /// |
no test coverage detected