Skip to content

Conversation

@jklamer
Copy link
Contributor

@jklamer jklamer commented May 10, 2022

Silly build mistake I made: was not able to use derive macro without including in lib.rs.
+
Need to qualify HashMap in derive macro for use in contexts where hash map not imported.

results in being able to use as:

use apache_avro::AvroSchema;
use serde::{Serialize, Deserialize};

#[derive(Debug, Serialize, Deserialize, AvroSchema)]
struct A {
    a : i64,
    b: String,
}

@github-actions github-actions bot added the Rust label May 10, 2022
jklamer and others added 3 commits May 9, 2022 22:08
Signed-off-by: Martin Tzvetanov Grigorov <mgrigorov@apache.org>
@github-actions github-actions bot added the build label May 10, 2022
Copy link
Member

@martin-g martin-g left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please create a JIRA issue for the bug and update the title of the PR to include AVRO-1234: ...
Also the commit messages should be prefixed with AVRO-1234:

I could do these ^^ too!

@martin-g
Copy link
Member

@jklamer Since derive is not a default feature I've expected that the new example should not compile without --features derive but it does! What do I miss ?

Signed-off-by: Martin Tzvetanov Grigorov <mgrigorov@apache.org>
@martin-g martin-g force-pushed the jklamer/FixDeriveExport branch from 443dbcd to 2310477 Compare May 10, 2022 06:14
@martin-g martin-g closed this May 10, 2022
@martin-g martin-g reopened this May 10, 2022
Signed-off-by: Martin Tzvetanov Grigorov <mgrigorov@apache.org>
@jklamer
Copy link
Contributor Author

jklamer commented May 11, 2022

@martin-g I think the examples and other tests run in dev mode where the apache_avro_derive is a dependency directly so didn't need to be imported into avro/src/lib.rs like we have to now! Thats my guess at least. Making JIRA now.

@jklamer jklamer changed the title Fix bugs in derive macro usage [AVRO-3516] Fix bugs in derive macro usage May 11, 2022
@martin-g
Copy link
Member

Good guess!
I've extracted the code in a separate app and now it indeed fails with:

   Compiling derive-test v0.1.0 (/home/martin/tmp/rust/derive-test)
error: cannot find derive macro `AvroSchema` in this scope
 --> src/main.rs:6:41
  |
6 | #[derive(Debug, Serialize, Deserialize, AvroSchema)]
  |                                         ^^^^^^^^^^
  |
note: `AvroSchema` is imported here, but it is only a trait, without a derive macro
 --> src/main.rs:2:5
  |
2 | use apache_avro::AvroSchema;
  |     ^^^^^^^^^^^^^^^^^^^^^^^

error[E0599]: no function or associated item named `get_schema` found for struct `A` in the current scope
  --> src/main.rs:14:42
   |
7  | struct A {
   | -------- function or associated item `get_schema` not found for this
...
14 |     println!("Derived schema: {:#?}", A::get_schema());
   |                                          ^^^^^^^^^^ function or associated item not found in `A`
   |
   = help: items from traits can only be used if the trait is implemented and in scope
   = note: the following trait defines an item `get_schema`, perhaps you need to implement it:
           candidate #1: `AvroSchema`

For more information about this error, try `rustc --explain E0599`.
error: could not compile `derive-test` due to 2 previous errors

I will remove the new example and merge!

@martin-g
Copy link
Member

Hm. It still fails the same way even after adding apache-avro-derive = { version= "0.14.0", path = "/home/martin/git/apache/avro/lang/rust/avro_derive" } to [dependencies] ...

@martin-g
Copy link
Member

martin-g commented May 11, 2022

Using just apache-avro = { version= "0.14.0", path = "/home/martin/git/apache/avro/lang/rust/avro", features=[ "derive"] } works fine!

But listing both dependencies explicitly

[dependencies]
apache-avro-derive = { version= "0.14.0", path = "/home/martin/git/apache/avro/lang/rust/avro_derive" }
apache-avro = { version= "0.14.0", path = "/home/martin/git/apache/avro/lang/rust/avro"}

does not.
Update: It doesn't because it is behind a feature that needs to be enabled!

martin-g added a commit to jklamer/avro that referenced this pull request May 11, 2022
It cannot work as an 'example'
(apache#1683 (comment))

Signed-off-by: Martin Tzvetanov Grigorov <mgrigorov@apache.org>
It cannot work as an 'example'
(apache#1683 (comment))

Signed-off-by: Martin Tzvetanov Grigorov <mgrigorov@apache.org>
@martin-g martin-g force-pushed the jklamer/FixDeriveExport branch from fda07f7 to ed31668 Compare May 11, 2022 19:10
@martin-g martin-g merged commit 3fafde2 into apache:master May 11, 2022
martin-g added a commit that referenced this pull request May 11, 2022
* 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>
(cherry picked from commit 3fafde2)
@martin-g
Copy link
Member

Thank you, @jklamer !

martin-g added a commit to apache/avro-rs that referenced this pull request Sep 23, 2024
* 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'
(apache/avro#1683 (comment))

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

Co-authored-by: Martin Tzvetanov Grigorov <mgrigorov@apache.org>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants