-
Notifications
You must be signed in to change notification settings - Fork 2.3k
feat(codecs): Support more avro types #24774
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
43dfd88
8f2d0fd
6ea80e7
b41b736
490291a
8fb61ef
53a9071
20815d0
05045a9
88a117b
63ff827
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| The Avro codec now supports encoding and decoding Date, Fixed, TimeMillis, TimestampNanos, LocalTimestampNanos values. | ||
|
|
||
| authors: omwbennett |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -91,11 +91,8 @@ impl From<&AvroDeserializerOptions> for AvroSerializerOptions { | |
| pub struct AvroDeserializerOptions { | ||
| /// The Avro schema definition. | ||
| /// **Note**: The following [`apache_avro::types::Value`] variants are *not* supported: | ||
| /// * `Date` | ||
| /// * `Decimal` | ||
| /// * `Duration` | ||
| /// * `Fixed` | ||
| /// * `TimeMillis` | ||
| #[configurable(metadata( | ||
| docs::examples = r#"{ "type": "record", "name": "log", "fields": [{ "name": "message", "type": "string" }] }"#, | ||
| docs::additional_props_description = r#"Supports most avro data types, unsupported data types includes | ||
|
|
@@ -189,10 +186,8 @@ pub fn try_from(value: AvroValue) -> vector_common::Result<VrlValue> { | |
| Ok(VrlValue::Array(vector)) | ||
| } | ||
| AvroValue::Boolean(boolean) => Ok(VrlValue::from(boolean)), | ||
| AvroValue::Bytes(bytes) => Ok(VrlValue::from(bytes)), | ||
| AvroValue::Date(_) => Err(vector_common::Error::from( | ||
| "AvroValue::Date is not supported", | ||
| )), | ||
| AvroValue::Bytes(bytes) => Ok(VrlValue::Bytes(Bytes::from(bytes))), | ||
| AvroValue::Date(days) => Ok(VrlValue::from(days)), | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
For users configuring either Splunk HEC decoding path, AGENTS.md reference: AGENTS.md:L212-L212 Useful? React with 👍 / 👎. |
||
| AvroValue::Decimal(_) => Err(vector_common::Error::from( | ||
| "AvroValue::Decimal is not supported", | ||
| )), | ||
|
|
@@ -201,9 +196,7 @@ pub fn try_from(value: AvroValue) -> vector_common::Result<VrlValue> { | |
| "AvroValue::Duration is not supported", | ||
| )), | ||
| AvroValue::Enum(_, string) => Ok(VrlValue::from(string)), | ||
| AvroValue::Fixed(_, _) => Err(vector_common::Error::from( | ||
| "AvroValue::Fixed is not supported", | ||
| )), | ||
| AvroValue::Fixed(_, bytes) => Ok(VrlValue::Bytes(Bytes::from(bytes))), | ||
| AvroValue::Float(float) => Ok(VrlValue::from_f64_or_zero(float as f64)), | ||
| AvroValue::Int(int) => Ok(VrlValue::from(int)), | ||
| AvroValue::Long(long) => Ok(VrlValue::from(long)), | ||
|
|
@@ -220,9 +213,7 @@ pub fn try_from(value: AvroValue) -> vector_common::Result<VrlValue> { | |
| .map(|v| VrlValue::Object(v.into_iter().collect())), | ||
| AvroValue::String(string) => Ok(VrlValue::from(string)), | ||
| AvroValue::TimeMicros(time_micros) => Ok(VrlValue::from(time_micros)), | ||
| AvroValue::TimeMillis(_) => Err(vector_common::Error::from( | ||
| "AvroValue::TimeMillis is not supported", | ||
| )), | ||
| AvroValue::TimeMillis(time_millis) => Ok(VrlValue::from(time_millis)), | ||
| AvroValue::TimestampMicros(ts_micros) => Ok(VrlValue::from(ts_micros)), | ||
| AvroValue::TimestampMillis(ts_millis) => Ok(VrlValue::from(ts_millis)), | ||
| AvroValue::Union(_, v) => try_from(*v), | ||
|
|
@@ -232,12 +223,8 @@ pub fn try_from(value: AvroValue) -> vector_common::Result<VrlValue> { | |
| AvroValue::BigDecimal(_) => Err(vector_common::Error::from( | ||
| "AvroValue::BigDecimal is not supported", | ||
| )), | ||
| AvroValue::TimestampNanos(_) => Err(vector_common::Error::from( | ||
| "AvroValue::TimestampNanos is not supported", | ||
| )), | ||
| AvroValue::LocalTimestampNanos(_) => Err(vector_common::Error::from( | ||
| "AvroValue::LocalTimestampNanos is not supported", | ||
| )), | ||
| AvroValue::TimestampNanos(ts_nanos) => Ok(VrlValue::from(ts_nanos)), | ||
| AvroValue::LocalTimestampNanos(ts_nanos) => Ok(VrlValue::from(ts_nanos)), | ||
| } | ||
| } | ||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When an Avro
bytesfield contains arbitrary non-UTF-8 data, converting it toVrlValue::Byteshere makes the encoder's laterapache_avro::to_value(log)pass serialize it through VRL's lossy string representation. For example,[0xff, 0x00]is silently re-encoded as[0xef, 0xbf, 0xbd, 0x00]; the newFixedbranch has the same problem and can instead fail when replacement bytes change the fixed length. Avro binary values are not restricted to UTF-8, so the serializer must preserve VRL bytes through a schema-aware conversion rather than the lossy Serde path.Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @omwbennett, apologies for the delay. I spend a little time on this PR but this is actually an important issue. If you are still interesting in completing this, happy to help reviewing. Otherwise, I think we want to split this into smaller PRs.
The fix here is to do the following:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi, thanks for taking another look. I can split this up into smaller PRs.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Starting with #26000
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Next is the introduction of coerce_logical_types to support a few simpler logical types (date/timemillis): #26112
Will add support for the remaining logical types in a follow-up PR.