[
https://issues.apache.org/jira/browse/AVRO-3752?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17719986#comment-17719986
]
Fedor Telnov commented on AVRO-3752:
------------------------------------
[~mgrigorov]
It seems that problem only occurs with complex types included in union schema,
as shown below. For instance, if we change enum to string, we won't see any
annoying logs.
Here is an example of test case that floods logging:
```
#[test]
fn logging_test() -> anyhow::Result<()> {
struct SimpleLogger;
impl Log for SimpleLogger {
fn enabled(&self, _metadata: &log::Metadata) -> bool {
true
}
fn log(&self, record: &log::Record) {
println!("\{:?}", record)
}
fn flush(&self) {}
}
log::set_logger(&SimpleLogger)
.map(|()| log::set_max_level(LevelFilter::Info))
.unwrap();
// we'll match string against this schema, as you can see it's the last
variant.
let raw_schema = r#"{
"type": "record",
"name": "root",
"fields": [
\{"name": "union", "type": ["null", "int", "boolean", {"type":
"enum", "symbols": ["A"], "name": "enum"}]}
]
}"#;
let schema_as_val =
serde_json::from_str::<serde_json::Value>(raw_schema)?;
let schema = Schema::parse(&schema_as_val)?;
let raw_value = r#"\{"union": "A"}"#;
let json_value: serde_json::Value = serde_json::from_str(raw_value)?;
let avro_value: apache_avro::types::Value = json_value.into();
avro_value.resolve(&schema)?;
Ok(())
}
```
> [Rust] Logging flood during Union resolving
> -------------------------------------------
>
> Key: AVRO-3752
> URL: https://issues.apache.org/jira/browse/AVRO-3752
> Project: Apache Avro
> Issue Type: Improvement
> Components: rust
> Reporter: Fedor Telnov
> Priority: Minor
>
> I'm going to speak about Rust implementation(crate) of Avro named
> "apache-avro"([crates.io|[https://crates.io/crates/apache-avro]).]
> Currently, union resolving is implemented as "iterate through listed schemas
> and find the first that matches given value". Process of finding requires
> schemas validation against that value. Validation method contains single
> "error!" macro invocation.
> So, even if union contains relevant schema as variant, previous bad matches
> would throw error! log macro. In result, with big unions, you get a flooded
> logs.
> My proposition is to write separate "validate" method that won't invoke
> error! macro and use it during union resolution.
> UPD: It seems that problem only occurs when complex types are included in
> union schema, see example in comments.
--
This message was sent by Atlassian Jira
(v8.20.10#820010)