()
| 381 | |
| 382 | #[test] |
| 383 | fn test_header() { |
| 384 | let header = decode_file(&arrow_test_data("avro/alltypes_plain.avro")); |
| 385 | let schema_json = header.get(SCHEMA_METADATA_KEY).unwrap(); |
| 386 | let expected = br#"{"type":"record","name":"topLevelRecord","fields":[{"name":"id","type":["int","null"]},{"name":"bool_col","type":["boolean","null"]},{"name":"tinyint_col","type":["int","null"]},{"name":"smallint_col","type":["int","null"]},{"name":"int_col","type":["int","null"]},{"name":"bigint_col","type":["long","null"]},{"name":"float_col","type":["float","null"]},{"name":"double_col","type":["double","null"]},{"name":"date_string_col","type":["bytes","null"]},{"name":"string_col","type":["bytes","null"]},{"name":"timestamp_col","type":[{"type":"long","logicalType":"timestamp-micros"},"null"]}]}"#; |
| 387 | assert_eq!(schema_json, expected); |
| 388 | let schema: Schema<'_> = serde_json::from_slice(schema_json).unwrap(); |
| 389 | let field = AvroField::try_from(&schema).unwrap(); |
| 390 | |
| 391 | assert_eq!( |
| 392 | field.field(), |
| 393 | Field::new( |
| 394 | "topLevelRecord", |
| 395 | DataType::Struct(Fields::from(vec![ |
| 396 | Field::new("id", DataType::Int32, true), |
| 397 | Field::new("bool_col", DataType::Boolean, true), |
| 398 | Field::new("tinyint_col", DataType::Int32, true), |
| 399 | Field::new("smallint_col", DataType::Int32, true), |
| 400 | Field::new("int_col", DataType::Int32, true), |
| 401 | Field::new("bigint_col", DataType::Int64, true), |
| 402 | Field::new("float_col", DataType::Float32, true), |
| 403 | Field::new("double_col", DataType::Float64, true), |
| 404 | Field::new("date_string_col", DataType::Binary, true), |
| 405 | Field::new("string_col", DataType::Binary, true), |
| 406 | Field::new( |
| 407 | "timestamp_col", |
| 408 | DataType::Timestamp(TimeUnit::Microsecond, Some("+00:00".into())), |
| 409 | true |
| 410 | ), |
| 411 | ])), |
| 412 | false |
| 413 | ) |
| 414 | .with_metadata(HashMap::from([( |
| 415 | AVRO_NAME_METADATA_KEY.to_string(), |
| 416 | AVRO_ROOT_RECORD_DEFAULT_NAME.to_string() |
| 417 | )])) |
| 418 | ); |
| 419 | |
| 420 | assert_eq!( |
| 421 | u128::from_le_bytes(header.sync()), |
| 422 | 226966037233754408753420635932530907102 |
| 423 | ); |
| 424 | |
| 425 | let header = decode_file(&arrow_test_data("avro/fixed_length_decimal.avro")); |
| 426 | |
| 427 | let meta: Vec<_> = header |
| 428 | .metadata() |
| 429 | .map(|(k, _)| std::str::from_utf8(k).unwrap()) |
| 430 | .collect(); |
| 431 | |
| 432 | assert_eq!( |
| 433 | meta, |
| 434 | &["avro.schema", "org.apache.spark.version", "avro.codec"] |
| 435 | ); |
| 436 | |
| 437 | let schema_json = header.get(SCHEMA_METADATA_KEY).unwrap(); |
| 438 | let expected = br#"{"type":"record","name":"topLevelRecord","fields":[{"name":"value","type":[{"type":"fixed","name":"fixed","namespace":"topLevelRecord.value","size":11,"logicalType":"decimal","precision":25,"scale":2},"null"]}]}"#; |
| 439 | assert_eq!(schema_json, expected); |
| 440 | let _schema: Schema<'_> = serde_json::from_slice(schema_json).unwrap(); |
nothing calls this directly
no test coverage detected