AVRO-3248: Rust: Support named types in UnionSchema#1396
AVRO-3248: Rust: Support named types in UnionSchema#1396martin-g merged 9 commits intoapache:masterfrom
Conversation
| /// of its corresponding schema | ||
| /// This allows schema-less encoding, as well as schema resolution while | ||
| /// reading values. | ||
| Union(i32, Box<Value>), |
There was a problem hiding this comment.
Why i32 ? Could we have negative values ?
There was a problem hiding this comment.
I see, it just follows the way Value::Enum is implemented.
I'll take a deeper look why i32 is used there. It also leads to a lot of casting later.
|
I am interested in this change. Didn't compile for me. Maybe I did something wrong ? |
|
I start working on this PR! |
previously union does not support named types, and we will get error if we add 2 records into 1 UnionSchema.
Signed-off-by: Martin Tzvetanov Grigorov <mgrigorov@apache.org>
Signed-off-by: Martin Tzvetanov Grigorov <mgrigorov@apache.org>
717e114 to
f82e1e7
Compare
|
@praetp Please try the PR now! It is fixed and rebased to latest master! |
Signed-off-by: Martin Tzvetanov Grigorov <mgrigorov@apache.org>
| Err(de::Error::custom("A record must have a least one field")), | ||
| |item| match (item.0.as_ref(), &item.1) { | ||
| ("type", Value::String(x)) => Ok(( | ||
| ("type", Value::String(x)) | ("type", Value::Enum(_, x)) => Ok(( |
There was a problem hiding this comment.
This change does not look related to this PR.
@lulitao1997 Why did you make it ?
lang/rust/src/types.rs
Outdated
| // Find the first match in the reader schema. | ||
| let (_, inner) = schema.find_schema(&v).ok_or(Error::FindUnionVariant)?; | ||
| Ok(Value::Union(Box::new(v.resolve(inner)?))) | ||
| // FIXME: this is wrong when the union consists of multiple same records that have different names |
There was a problem hiding this comment.
True, but I wonder how big a problem it is ?
The name and doc might be wrong but the fields will be the same, so the application logic should work.
lang/rust/src/types.rs
Outdated
| { | ||
| fn from(value: Option<T>) -> Self { | ||
| Self::Union(Box::new(value.map_or_else(|| Self::Null, Into::into))) | ||
| // NOTE: this is incorrect in case first type in union is not "none" |
There was a problem hiding this comment.
This seems incorrect also when the union has more than two items.
And looks like a stopper for this PR.
There was a problem hiding this comment.
Ignore this comment! I misunderstood it the first time!
It looks OK to me!
Signed-off-by: Martin Tzvetanov Grigorov <mgrigorov@apache.org>
|
Thank you for the contribution, @lulitao1997 ! |
* AVRO-3248: Rust: Support named types in UnionSchema previously union does not support named types, and we will get error if we add 2 records into 1 UnionSchema. * AVRO-3248: Fix a typo in error message * AVRO-3248: Give better names for the schemata as string * AVRO-3248: More better names for variables * AVRO-3248: Code formatting * AVRO-3248 Fix formatting & build Signed-off-by: Martin Tzvetanov Grigorov <mgrigorov@apache.org> * AVRO-3248: Fix generate_interop_data and formatting Signed-off-by: Martin Tzvetanov Grigorov <mgrigorov@apache.org> * AVRO-3248: Fix some regressions after the rebase to master Signed-off-by: Martin Tzvetanov Grigorov <mgrigorov@apache.org> * AVRO-3248 Fix the position in the Union for the Double value Signed-off-by: Martin Tzvetanov Grigorov <mgrigorov@apache.org> Co-authored-by: Martin Grigorov <martin-g@users.noreply.github.com> Co-authored-by: Martin Tzvetanov Grigorov <mgrigorov@apache.org> (cherry picked from commit 49c6e10)
change Value::Union to value it holds and its position in the type list,
this allows us to
Make sure you have checked all steps below.
Jira
Tests
Commits