MCPcopy Create free account
hub / github.com/MaterializeInc/materialize / parse_complex

Method parse_complex

src/avro/src/schema.rs:1075–1113  ·  view source on GitHub ↗

Parse a `serde_json::Value` representing a complex Avro type into a `Schema`. Avro supports "recursive" definition of types. e.g: {"type": {"type": "string"}}

(
        &mut self,
        default_namespace: &str,
        complex: &Map<String, Value>,
    )

Source from the content-addressed store, hash-verified

1073 /// Avro supports "recursive" definition of types.
1074 /// e.g: {"type": {"type": "string"}}
1075 fn parse_complex(
1076 &mut self,
1077 default_namespace: &str,
1078 complex: &Map<String, Value>,
1079 ) -> Result<SchemaPieceOrNamed, AvroError> {
1080 match complex.get("type") {
1081 Some(&Value::String(ref t)) => Ok(match t.as_str() {
1082 "record" | "enum" | "fixed" => SchemaPieceOrNamed::Named(self.parse_named_type(
1083 t,
1084 default_namespace,
1085 complex,
1086 )?),
1087 "array" => SchemaPieceOrNamed::Piece(self.parse_array(default_namespace, complex)?),
1088 "map" => SchemaPieceOrNamed::Piece(self.parse_map(default_namespace, complex)?),
1089 "bytes" => SchemaPieceOrNamed::Piece(Self::parse_bytes(complex)?),
1090 "int" => SchemaPieceOrNamed::Piece(Self::parse_int(complex)?),
1091 "long" => SchemaPieceOrNamed::Piece(Self::parse_long(complex)?),
1092 "string" => SchemaPieceOrNamed::Piece(Self::from_string(complex)),
1093 other => {
1094 let name = FullName {
1095 name: other.into(),
1096 namespace: default_namespace.into(),
1097 };
1098 if let Some(idx) = self.indices.get(&name) {
1099 SchemaPieceOrNamed::Named(*idx)
1100 } else {
1101 SchemaPieceOrNamed::Piece(Schema::parse_primitive(t.as_str())?)
1102 }
1103 }
1104 }),
1105 Some(&Value::Object(ref data)) => match data.get("type") {
1106 Some(value) => self.parse_inner(default_namespace, value),
1107 None => Err(
1108 ParseSchemaError::new(format!("Unknown complex type: {:?}", complex)).into(),
1109 ),
1110 },
1111 _ => Err(ParseSchemaError::new("No `type` in complex type").into()),
1112 }
1113 }
1114
1115 /// Parse a `serde_json::Value` representing a Avro record type into a
1116 /// `Schema`.

Callers 1

parse_inner_implMethod · 0.80

Calls 8

parse_intFunction · 0.85
parse_named_typeMethod · 0.80
parse_innerMethod · 0.80
parse_bytesFunction · 0.50
getMethod · 0.45
as_strMethod · 0.45
parse_arrayMethod · 0.45
parse_mapMethod · 0.45

Tested by

no test coverage detected