MCPcopy Create free account
hub / github.com/apache/arrow-rs / make_decoder

Method make_decoder

arrow-avro/src/reader/mod.rs:1035–1146  ·  view source on GitHub ↗
(
        &self,
        header: Option<&Header>,
        reader_schema: Option<&AvroSchema>,
    )

Source from the content-addressed store, hash-verified

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())

Callers 2

buildMethod · 0.45
build_decoderMethod · 0.45

Calls 13

fingerprintsMethod · 0.80
firstMethod · 0.80
lookupMethod · 0.80
fingerprint_algorithmMethod · 0.80
schemaMethod · 0.45
cloneMethod · 0.45
getMethod · 0.45
projectMethod · 0.45
as_refMethod · 0.45
is_emptyMethod · 0.45
lenMethod · 0.45

Tested by

no test coverage detected