You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@avro.apache.org by mg...@apache.org on 2022/05/11 19:34:59 UTC

[avro] branch branch-1.11 updated: [AVRO-3516] Fix bugs in derive macro usage (#1683)

This is an automated email from the ASF dual-hosted git repository.

mgrigorov pushed a commit to branch branch-1.11
in repository https://gitbox.apache.org/repos/asf/avro.git


The following commit(s) were added to refs/heads/branch-1.11 by this push:
     new 2b16e71ca [AVRO-3516] Fix bugs in derive macro usage  (#1683)
2b16e71ca is described below

commit 2b16e71ca773dd6c0e75aa06c8d86926ed8e1012
Author: Jack Klamer <jf...@gmail.com>
AuthorDate: Wed May 11 14:33:24 2022 -0500

    [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 <mg...@apache.org>
    
    * Add an example for schema derivation
    
    Signed-off-by: Martin Tzvetanov Grigorov <mg...@apache.org>
    
    * Pretty print the derived schema
    
    Signed-off-by: Martin Tzvetanov Grigorov <mg...@apache.org>
    
    * [AVRO-3516] remove circular package dependency
    
    * AVRO-3516: Remove the derive-compilation example
    
    It cannot work as an 'example'
    (https://github.com/apache/avro/pull/1683#issuecomment-1123119783)
    
    Signed-off-by: Martin Tzvetanov Grigorov <mg...@apache.org>
    
    Co-authored-by: Martin Tzvetanov Grigorov <mg...@apache.org>
    (cherry picked from commit 3fafde2cf8dd4b3a34cf48347a346c436741ae91)
---
 lang/rust/avro/src/lib.rs        | 5 ++++-
 lang/rust/avro_derive/Cargo.toml | 2 +-
 lang/rust/avro_derive/src/lib.rs | 4 ++--
 lang/rust/build.sh               | 6 +++---
 4 files changed, 10 insertions(+), 7 deletions(-)

diff --git a/lang/rust/avro/src/lib.rs b/lang/rust/avro/src/lib.rs
index 104f9a5d7..8b53f1635 100644
--- a/lang/rust/avro/src/lib.rs
+++ b/lang/rust/avro/src/lib.rs
@@ -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;
 
diff --git a/lang/rust/avro_derive/Cargo.toml b/lang/rust/avro_derive/Cargo.toml
index 2dfe2e733..7b417467b 100644
--- a/lang/rust/avro_derive/Cargo.toml
+++ b/lang/rust/avro_derive/Cargo.toml
@@ -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"] }
diff --git a/lang/rust/avro_derive/src/lib.rs b/lang/rust/avro_derive/src/lib.rs
index 149f85eaa..abba0e195 100644
--- a/lang/rust/avro_derive/src/lib.rs
+++ b/lang/rust/avro_derive/src/lib.rs
@@ -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},
diff --git a/lang/rust/build.sh b/lang/rust/build.sh
index c7caffbc5..e8f9bf69f 100755
--- a/lang/rust/build.sh
+++ b/lang/rust/build.sh
@@ -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