avrohugger icon indicating copy to clipboard operation
avrohugger copied to clipboard

AVDL imports don't handle transitive deps / wrong file order

Open mariussoutier opened this issue 8 years ago • 18 comments

I've encountered a problem with transitive AVDL imports that don't work because of the file order.

This works:

A.avdl
B.avdl -> import idl "A.avdl";
C.avdl -> import idl "B.avdl";

This doesn't:

A.avdl -> import idl "B.avdl";
B.avdl -> import idl "C.avdl";
C.avdl

Error message is NoSuchElementException: key not found.

mariussoutier avatar Jan 11 '17 15:01 mariussoutier

@mariussoutier Sorry to leave you hanging so long! I tried to reproduce the error with sbt-avrohugger 0.13.0, but both cases seem to succeed for me. (I tried with everything in the same namespaces, and then with everything in different namespaces and still everything worked, but I didn't check combos exhaustively); https://github.com/julianpeeters/avrohugger-transitive-dependencies-error

julianpeeters avatar Feb 06 '17 04:02 julianpeeters

No problem, I also started to write a PR, but got distracted. I also wasn't sure how to access the imports.

Funny, when I check out your project and run sbt compile, I get exactly the error from this ticket:

[info] Compiling Avro IDL /Users/mariussoutier/Workspace/avrohugger-transitive-dependencies-error/src/main/avro/A.avdl
[trace] Stack trace suppressed: run last avro:generate for the full output.
[error] (avro:generate) java.util.NoSuchElementException: key not found: {"type":"record","name":"C","namespace":"test","fields":[{"name":"number","type":"int"}]}
[error] Total time: 0 s, completed Feb 6, 2017 1:21:38 PM

mariussoutier avatar Feb 06 '17 12:02 mariussoutier

lol

"Oooohhhhh yeaaaahhhh...", my brain finally says, "...filesystems". I'll see about a AVDLFilesorter in addition to the existing AVSCFilesorter

julianpeeters avatar Feb 07 '17 08:02 julianpeeters

Wait, are you on Linux and the files are in a different order?

mariussoutier avatar Feb 07 '17 09:02 mariussoutier

Yes, the files are in different order on OSX vs Linux. I'm on AWS and I couldn't fully deduce how the files are ordered, but it's definitely not alphabetical. I dug deep into this and the file order is a direct results of File.listFiles(). A stop gap measure that at least orders alphabetically would be an improvement for now as least the ordering would be platform independent.

jon-morra-zefr avatar Feb 07 '17 17:02 jon-morra-zefr

'fraid so. Apparently OSX is alphabetical, Ubuntu 16.04 (laughing about ) is not 🤷‍♂️ ... the AVSC filesorter sorts files before sorting files, to ensure a standardized input order across filesystems.

julianpeeters avatar Feb 07 '17 17:02 julianpeeters

Ok, I'll be switching to Linux soon, this will be interesting...

I checked my branch and what I couldn't figure out was how to get all imports. There only seems to be one? https://github.com/julianpeeters/sbt-avrohugger/compare/master...mariussoutier:avdl-sorter

mariussoutier avatar Feb 07 '17 17:02 mariussoutier

That's a damn good question. I needed similar info for idl -> adt generation, and couldn't figure it out, ended up grabbing the imports myself: https://github.com/julianpeeters/avrohugger/blob/master/avrohugger-core/src/main/scala/input/parsers/IdlImportParser.scala#L19

I'm very open to however/whenever we want to handle this. A few thoughts:

  • Ideally, perhaps now or in the future, we'd probably want figure out how to use avro's method (for accuracy and to let them maintain it).
  • sbt-avrohugger depending on avrohugger's IdlImportParser seems fine too for now.
  • One day, the AvscFileSorter (and presumedly the incipient AvdlFileSorter) will probably move to avrohugger (to be more generally accessible).
  • I like Jon's stop gap, I suspect that the full solution would also benefit from standardizing the input.

julianpeeters avatar Feb 08 '17 01:02 julianpeeters

I've committed a PR for this, let me know what you guys think.

jon-morra-zefr avatar Feb 08 '17 03:02 jon-morra-zefr

@julianpeeters We could move AvscFileSorters to Avrohugger right now, there's already a PR #54.

@jon-morra-zefr You would have to parse AVSCs as well, no? Julian's parser provides this.

mariussoutier avatar Feb 08 '17 09:02 mariussoutier

@mariussoutier I don't understand why I'd have to parse AVSCs as well? There's already a file sorter that does this. I would think that the next step after validating AVDL's work correctly is to write file sorters for the other types in FileWriter, namely ".avro" and ".avpr" files.

jon-morra-zefr avatar Feb 08 '17 14:02 jon-morra-zefr

Yeah right, I forgot you're just sorting alphabetically.

mariussoutier avatar Feb 08 '17 14:02 mariussoutier

I'm not just sorting alphabetically. The PR I submitted actually reads the imports and sorts them correctly. It's certainly not perfect (ie the code just uses a regex to find the imports), but it works on non trivial test cases.

jon-morra-zefr avatar Feb 08 '17 14:02 jon-morra-zefr

I haven't confirmed the tests yet, but Jon's PR is looking promising to me.

I take your points though, Marius, and I think it comes down to urgency vs completeness:

  • would be nice to move filesorter to avrohugger
  • would be nice to handle idls that import avscs (etc.) as well as avdls

Since this is blocking, and we're still < 1.0.0, I'd vote for merging this in as-is, and creating a issue to track the remaining work. Feel free to vote/comment; without objections/more code, I'll aim to merge tonight or next.

julianpeeters avatar Feb 08 '17 16:02 julianpeeters

Yeah let's make it work first, then make it beautiful.

mariussoutier avatar Feb 09 '17 09:02 mariussoutier

Looking good. avrohugger/sbt-avrohugger 0.15.0 up at sonatype, syncing with maven central soon. :+1:

julianpeeters avatar Feb 13 '17 11:02 julianpeeters

Great!

mariussoutier avatar Feb 13 '17 13:02 mariussoutier

Reopening to track remaining detail: Avdl filesorter should handle idls that import avscs (etc.) as well as avdls

julianpeeters avatar Feb 14 '17 04:02 julianpeeters