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

Method parse

src/avro/src/schema.rs:653–699  ·  view source on GitHub ↗

Parse a `serde_json::map::Map` into a `Name`.

(complex: &Map<String, Value>)

Source from the content-addressed store, hash-verified

651
652 /// Parse a `serde_json::map::Map` into a `Name`.
653 pub fn parse(complex: &Map<String, Value>) -> Result<Self, AvroError> {
654 let name = complex
655 .name()
656 .ok_or_else(|| ParseSchemaError::new("No `name` field"))?;
657 if name.is_empty() {
658 return Err(ParseSchemaError::new(format!(
659 "Name cannot be the empty string: {:?}",
660 complex
661 ))
662 .into());
663 }
664
665 let (namespace, name) = if let Some(index) = name.rfind('.') {
666 let computed_namespace = name[..index].to_owned();
667 let computed_name = name[index + 1..].to_owned();
668 if let Some(provided_namespace) = complex.string("namespace") {
669 if provided_namespace != computed_namespace {
670 warn!(
671 "Found dots in name {}, updating to namespace {} and name {}",
672 name, computed_namespace, computed_name
673 );
674 }
675 }
676 (Some(computed_namespace), computed_name)
677 } else {
678 (complex.string("namespace"), name)
679 };
680
681 Self::validate(&name)?;
682
683 let aliases: Option<Vec<String>> = complex
684 .get("aliases")
685 .and_then(|aliases| aliases.as_array())
686 .and_then(|aliases| {
687 aliases
688 .iter()
689 .map(|alias| alias.as_str())
690 .map(|alias| alias.map(|a| a.to_string()))
691 .collect::<Option<_>>()
692 });
693
694 Ok(Name {
695 name,
696 namespace,
697 aliases,
698 })
699 }
700
701 /// Parses a name from a simple string.
702 pub fn parse_simple(name: &str) -> Result<Self, AvroError> {

Callers 15

id_from_secret_nameMethod · 0.45
readMethod · 0.45
test_encode_empty_arrayFunction · 0.45
test_encode_empty_mapFunction · 0.45
parse_with_referencesMethod · 0.45
test_from_avro_datumFunction · 0.45
test_null_unionFunction · 0.45
test_reader_streamFunction · 0.45

Calls 14

parse_innerMethod · 0.80
unwrapMethod · 0.80
validateFunction · 0.70
nameMethod · 0.45
is_emptyMethod · 0.45
to_ownedMethod · 0.45
stringMethod · 0.45
getMethod · 0.45
mapMethod · 0.45
iterMethod · 0.45
as_strMethod · 0.45
to_stringMethod · 0.45

Tested by 11

test_encode_empty_arrayFunction · 0.36
test_encode_empty_mapFunction · 0.36
test_from_avro_datumFunction · 0.36
test_null_unionFunction · 0.36
test_reader_streamFunction · 0.36