Skip to content
Permalink
Browse files
[AVRO-3516] Fix bugs in derive macro usage (#1683)
* bug fix and build fix

* remove uneeded component trait

* no hidden doc

* boolean schema

* fmt

* Reduce the enabled features only to the ones required by the test

Signed-off-by: Martin Tzvetanov Grigorov <mgrigorov@apache.org>

* Add an example for schema derivation

Signed-off-by: Martin Tzvetanov Grigorov <mgrigorov@apache.org>

* Pretty print the derived schema

Signed-off-by: Martin Tzvetanov Grigorov <mgrigorov@apache.org>

* [AVRO-3516] remove circular package dependency

* AVRO-3516: Remove the derive-compilation example

It cannot work as an 'example'
(#1683 (comment))

Signed-off-by: Martin Tzvetanov Grigorov <mgrigorov@apache.org>

Co-authored-by: Martin Tzvetanov Grigorov <mgrigorov@apache.org>
  • Loading branch information
jklamer and martin-g committed May 11, 2022
1 parent 41fbaa8 commit 3fafde2cf8dd4b3a34cf48347a346c436741ae91
Showing 4 changed files with 10 additions and 7 deletions.
@@ -743,11 +743,14 @@ pub use decimal::Decimal;
pub use duration::{Days, Duration, Millis, Months};
pub use error::Error;
pub use reader::{from_avro_datum, GenericSingleObjectReader, Reader, SpecificSingleObjectReader};
pub use schema::Schema;
pub use schema::{AvroSchema, Schema};
pub use ser::to_value;
pub use util::max_allocation_bytes;
pub use writer::{to_avro_datum, GenericSingleObjectWriter, SpecificSingleObjectWriter, Writer};

#[cfg(feature = "derive")]
pub use apache_avro_derive::*;

#[macro_use]
extern crate log;

@@ -39,6 +39,6 @@ proc-macro2 = "1.0.37"
serde_json = "1.0.79"

[dev-dependencies]
apache-avro = { version = "0.14.0", path = "../avro", features = ["derive"] }
apache-avro = { path = "../avro", features = ["derive"] }
proptest = "1.0.0"
serde = { version = "1.0.136", features = ["derive"] }
@@ -93,7 +93,7 @@ fn derive_avro_schema(input: &mut DeriveInput) -> Result<TokenStream, Vec<syn::E
let (impl_generics, ty_generics, where_clause) = input.generics.split_for_impl();
Ok(quote! {
impl #impl_generics apache_avro::schema::derive::AvroSchemaComponent for #ident #ty_generics #where_clause {
fn get_schema_in_ctxt(named_schemas: &mut HashMap<apache_avro::schema::Name, apache_avro::schema::Schema>, enclosing_namespace: &Option<String>) -> apache_avro::schema::Schema {
fn get_schema_in_ctxt(named_schemas: &mut std::collections::HashMap<apache_avro::schema::Name, apache_avro::schema::Schema>, enclosing_namespace: &Option<String>) -> apache_avro::schema::Schema {
let name = apache_avro::schema::Name::new(#full_schema_name).expect(&format!("Unable to parse schema name {}", #full_schema_name)[..]).fully_qualified_name(enclosing_namespace);
let enclosing_namespace = &name.namespace;
if named_schemas.contains_key(&name) {
@@ -220,7 +220,7 @@ fn type_to_schema_expr(ty: &Type) -> Result<TokenStream, Vec<syn::Error>> {
let type_string = p.path.segments.last().unwrap().ident.to_string();

let schema = match &type_string[..] {
"bool" => quote! {Schema::Boolean},
"bool" => quote! {apache_avro::schema::Schema::Boolean},
"i8" | "i16" | "i32" | "u8" | "u16" => quote! {apache_avro::schema::Schema::Int},
"i64" => quote! {apache_avro::schema::Schema::Long},
"f32" => quote! {apache_avro::schema::Schema::Float},
@@ -58,15 +58,15 @@ do
prepare_build
export RUST_LOG=apache_avro=debug
export RUST_BACKTRACE=1
cargo run --all-features --example generate_interop_data
cargo run --features snappy,zstandard,bzip,xz --example generate_interop_data
;;

interop-data-test)
prepare_build
echo "Running interop data tests"
cargo run --all-features --example test_interop_data
cargo run --features snappy,zstandard,bzip,xz --example test_interop_data
echo -e "\nRunning single object encoding interop data tests"
cargo run --all-features --example test_interop_single_object_encoding
cargo run --example test_interop_single_object_encoding
;;
*)
echo "Usage: $0 {lint|test|dist|clean|interop-data-generate|interop-data-test}" >&2

0 comments on commit 3fafde2

Please sign in to comment.