(
&self,
header: Option<&Header>,
reader_schema: Option<&AvroSchema>,
)
| 1033 | } |
| 1034 | |
| 1035 | fn make_decoder( |
| 1036 | &self, |
| 1037 | header: Option<&Header>, |
| 1038 | reader_schema: Option<&AvroSchema>, |
| 1039 | ) -> Result<Decoder, AvroError> { |
| 1040 | if let Some(hdr) = header { |
| 1041 | let writer_schema = hdr.schema()?.ok_or_else(|| { |
| 1042 | AvroError::ParseError("No Avro schema present in file header".into()) |
| 1043 | })?; |
| 1044 | let projected_reader_schema = self |
| 1045 | .projection |
| 1046 | .as_deref() |
| 1047 | .map(|projection| { |
| 1048 | let base_schema = if let Some(reader_schema) = reader_schema { |
| 1049 | reader_schema.clone() |
| 1050 | } else { |
| 1051 | let raw = hdr.get(SCHEMA_METADATA_KEY).ok_or_else(|| { |
| 1052 | AvroError::ParseError( |
| 1053 | "No Avro schema present in file header".to_string(), |
| 1054 | ) |
| 1055 | })?; |
| 1056 | let json_string = std::str::from_utf8(raw) |
| 1057 | .map_err(|e| { |
| 1058 | AvroError::ParseError(format!( |
| 1059 | "Invalid UTF-8 in Avro schema header: {e}" |
| 1060 | )) |
| 1061 | })? |
| 1062 | .to_string(); |
| 1063 | AvroSchema::new(json_string) |
| 1064 | }; |
| 1065 | base_schema.project(projection) |
| 1066 | }) |
| 1067 | .transpose()?; |
| 1068 | let effective_reader_schema = projected_reader_schema.as_ref().or(reader_schema); |
| 1069 | let record_decoder = |
| 1070 | self.make_record_decoder_from_schemas(&writer_schema, effective_reader_schema)?; |
| 1071 | return Ok(Decoder::from_parts( |
| 1072 | self.batch_size, |
| 1073 | record_decoder, |
| 1074 | None, |
| 1075 | IndexMap::new(), |
| 1076 | FingerprintAlgorithm::Rabin, |
| 1077 | )); |
| 1078 | } |
| 1079 | let store = self.writer_schema_store.as_ref().ok_or_else(|| { |
| 1080 | AvroError::ParseError("Writer schema store required for raw Avro".into()) |
| 1081 | })?; |
| 1082 | let fingerprints = store.fingerprints(); |
| 1083 | if fingerprints.is_empty() { |
| 1084 | return Err(AvroError::ParseError( |
| 1085 | "Writer schema store must contain at least one schema".into(), |
| 1086 | )); |
| 1087 | } |
| 1088 | let start_fingerprint = self |
| 1089 | .active_fingerprint |
| 1090 | .or_else(|| fingerprints.first().copied()) |
| 1091 | .ok_or_else(|| { |
| 1092 | AvroError::ParseError("Could not determine initial schema fingerprint".into()) |
no test coverage detected