Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Namespace of fixed type in record not renamed #192

Open
steve-e opened this issue Jan 31, 2024 · 0 comments
Open

Namespace of fixed type in record not renamed #192

steve-e opened this issue Jan 31, 2024 · 0 comments

Comments

@steve-e
Copy link

steve-e commented Jan 31, 2024

I have a record with a fixed type. Both have the record and the fixed type have namespaces set.
I can rename the namespace of the record with avrohugger, but not the namespace of the fixed type

Example avro schema.

{
  "type": "record",
  "name": "same_name",
  "namespace": "namespace.conflict",
  "fields": [
    {
      "name": "search_results",
      "type": [
        "null",
        {
          "type": "fixed",
          "name": "fixed",
          "namespace": "namespace.conflict.same_name.search_results",
          "size": 16,
          "logicalType": "decimal",
          "precision": 38,
          "scale": 0
        }
      ],
      "default": null
    }
  ]
}

Unit test demonstrating the issue

class SpecificSameRecordNameAsNamespaceSpec extends mutable.Specification {
  "a Generator" should {
    "generate files that compile even if the name of a record is the same as the name of a namespace" in {
      val infile = new java.io.File("avrohugger-core/src/test/avro/SpecificSameRecordNameAsNamespace.avsc")
      val gen = new Generator(SpecificRecord, avroScalaCustomNamespace = Map(
        "namespace.conflict.same_name" -> "namespace.renamed",
        "namespace.conflict" -> "namespace.no_conflict"
      ))
      val outDir = gen.defaultOutputDir + "/specific"
      gen.fileToFile(infile, outDir)
      val sourceRecord = scala.io.Source.fromFile(s"$outDir/namespace/no_conflict/same_name.scala").mkString
      sourceRecord ==== util.Util.readFile("avrohugger-core/src/test/expected/specific/namespace/no_conflict/same_name.scala")
      val sourceFixedType = scala.io.Source.fromFile(s"$outDir/namespace/renamed/fixed.scala").mkString
      sourceFixedType ==== util.Util.readFile("avrohugger-core/src/test/expected/specific/namespace/renamed/fixed.scala")
    }
  }
}

This test fails because the fixed type is not renamed and so is written to the un-renamed directory

[info] a Generator should
[error]   ! generate files that compile even if the name of a record is the same as the name of a namespace
[error]    java.io.FileNotFoundException: target/generated-sources/specific/namespace/renamed/fixed.scala (No such file or directory) (SpecificSameRecordNameAsNamespaceSpec.scala:19)
> find target/generated-sources/ -name "*scala"
target/generated-sources//specific/namespace/no_conflict/same_name.scala
target/generated-sources//specific/namespace/conflict/same_name/search_results/fixed.scala

For my use case, renaming only the record's namespace solved the issue I had (which is that the generated class FQN was the same as the fixed type package for this schema, resulting in compilation error for generated code).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant