jecsand838 commented on code in PR #8292:
URL: https://github.com/apache/arrow-rs/pull/8292#discussion_r2337928702
##########
arrow-avro/src/codec.rs:
##########
@@ -193,6 +200,224 @@ impl AvroDataType {
pub fn nullability(&self) -> Option<Nullability> {
self.nullability
}
+
+ #[inline]
+ fn parse_default_literal(&self, default_json: &Value) ->
Result<AvroLiteral, ArrowError> {
+ fn expect_string<'v>(
+ default_json: &'v Value,
+ data_type: &str,
+ ) -> Result<&'v str, ArrowError> {
+ match default_json {
+ Value::String(s) => Ok(s.as_str()),
+ _ => Err(ArrowError::SchemaError(format!(
+ "Default value must be a JSON string for {data_type}"
+ ))),
+ }
+ }
+
+ fn parse_bytes_default(
+ default_json: &Value,
+ expected_len: Option<usize>,
+ ) -> Result<Vec<u8>, ArrowError> {
+ let s = expect_string(default_json, "bytes/fixed logical types")?;
+ let mut out = Vec::with_capacity(s.len());
+ for ch in s.chars() {
+ let cp = ch as u32;
+ if cp > 0xFF {
+ return Err(ArrowError::SchemaError(format!(
+ "Invalid codepoint U+{cp:04X} in bytes/fixed default;
must be ≤ 0xFF"
+ )));
+ }
+ out.push(cp as u8);
+ }
+ if let Some(len) = expected_len {
+ if out.len() != len {
+ return Err(ArrowError::SchemaError(format!(
+ "Default length {} does not match expected fixed size
{len}",
+ out.len(),
+ )));
+ }
+ }
+ Ok(out)
+ }
+
+ fn parse_json_i64(default_json: &Value, data_type: &str) ->
Result<i64, ArrowError> {
+ match default_json {
+ Value::Number(n) => n.as_i64().ok_or_else(|| {
+ ArrowError::SchemaError(format!("Default {data_type} must
be an integer"))
+ }),
+ _ => Err(ArrowError::SchemaError(format!(
+ "Default {data_type} must be a JSON integer"
+ ))),
+ }
+ }
+
+ fn parse_json_f64(default_json: &Value, data_type: &str) ->
Result<f64, ArrowError> {
+ match default_json {
+ Value::Number(n) => n.as_f64().ok_or_else(|| {
+ ArrowError::SchemaError(format!("Default {data_type} must
be a number"))
+ }),
+ _ => Err(ArrowError::SchemaError(format!(
+ "Default {data_type} must be a JSON number"
+ ))),
+ }
+ }
+
+ // Handle JSON nulls per-spec: allowed only for `null` type or unions
with null FIRST
Review Comment:
That's a really good catch. I was planning to bring in `NullSecond` support
here as a part of the full Dense `Union` type decoding support I'm finishing up
right now. Which is why I left the comment calling it out.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]