[
https://issues.apache.org/jira/browse/AVRO-3197?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17415026#comment-17415026
]
Guðjón commented on AVRO-3197:
------------------------------
Hi, sure thing.
I have attached a file `weather.avro` that has a schema that has a field of
time string but logical type timestamp-millis. It is written using this snippet
of code using the fastavro python library.
{code:python}
from fastavro import writer, reader, parse_schema
schema = { "doc": "A weather reading.", "name": "Weather", "namespace": "test",
"type": "record", "fields": [ {"name": "station", "type": "string"}, {"name":
"time", "type": "string", "logicalType": "timestamp-millis"}, ],}
parsed_schema = parse_schema(schema)
records = [
{u"station": u"011990-99999", u"time": "1433269388"},
{u"station": u"011990-99999", u"time": "1433270389"},
{u"station": u"011990-99999", u"time": "1433273379"},
{u"station": u"012650-99999", u"time": "1433275478"},
]
with open("weather.avro", "wb") as out:
writer(out, parsed_schema, records)
{code}
Then if I try to read it using `avro-rs` I get the error described.
{code:rust}
use avro_rs::Reader;
pub fn read_avro_file() -> anyhow::Result<()> {
let reader = Reader::new(std::fs::File::open("weather.avro")?)?;
for value in reader {
println!("{:?}", value.unwrap());
}
Ok(())
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_file_read() {
let res = read_avro_file();
}
}
{code}
The actual error is `Err(Unexpected `type` "string" variant for `logicalType`)`
> Rust: Disable logical type on failure
> -------------------------------------
>
> Key: AVRO-3197
> URL: https://issues.apache.org/jira/browse/AVRO-3197
> Project: Apache Avro
> Issue Type: Wish
> Reporter: Guðjón
> Priority: Minor
> Attachments: weather.avro
>
>
> I have a file containing avro records along with a schema. The schema
> contains a field that unfortunately has the type `String` but logical type
> `timestamp-millis`. The Java implementation of the avro spec doesn't complain
> and simply treats this field as a string, but the rust implementation will
> return an error since the string type doesn't match with the logical type of
> timestamp (long).
> I wonder if there could be a possibility to optionally disregard the logical
> type if this failure is encountered.
--
This message was sent by Atlassian Jira
(v8.3.4#803005)