[ 
https://issues.apache.org/jira/browse/AVRO-2883?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17524494#comment-17524494
 ] 

ASF subversion and git services commented on AVRO-2883:
-------------------------------------------------------

Commit fd0df76dce4cc058261f31b2bf7c86accc3b0e32 in avro's branch 
refs/heads/branch-1.11 from Zoltan Csizmadia
[ https://gitbox.apache.org/repos/asf?p=avro.git;h=fd0df76dc ]

AVRO-2883: Fix namespace mapping (#1610)

* Remove unused package references

* Replace namespace in text schema

* Remove namespace mapping

* Add unit tests

* Match namespace mapping used in ticket

* Make ReplaceMappedNamespacesInSchema private

* Mark NamespaceMapping obsolete

Co-authored-by: Zoltan Csizmadia <csizmad...@valassis.com>
(cherry picked from commit cf0cb14de5498cf420265217e8f4d3a84dd2f4a4)


> Avrogen (csharp) namespace mapping missing for references
> ---------------------------------------------------------
>
>                 Key: AVRO-2883
>                 URL: https://issues.apache.org/jira/browse/AVRO-2883
>             Project: Apache Avro
>          Issue Type: Bug
>          Components: csharp
>            Reporter: Thomas Vigh Sørensen
>            Assignee: Zoltan Csizmadia
>            Priority: Major
>              Labels: pull-request-available
>          Time Spent: 1h 50m
>  Remaining Estimate: 0h
>
> When using *avrogen* for generating C# models from a schemafile, the 
> *--namespace* option doesn't behave as expected, if the model refers to other 
> types (currently only tested with enums). 
> When running 
> {code:java}
> avrogen -s file.avsc . --namespace my.avro.ns:my.csharp.ns
> {code}
> the actual namespace of the generated C# files is changed to *my.csharp.ns*, 
> but any references between the models are not updated with the correct 
> namespace.
>  
> Given a schemafile containing:
> {code:json}
> {
>   "type" : "record",
>   "name" : "TestModel",
>   "namespace" : "my.avro.ns",
>   "fields" : [ {
>     "name" : "eventType",
>     "type" : {
>       "type" : "enum",
>       "name" : "EventType",
>       "symbols" : [ "CREATE", "UPDATE", "DELETE" ]
>     }
>   } ]
> }
> {code}
> And running 
> {code:java}
> avrogen -s models.avsc . --namespace my.avro.ns:my.csharp.ns
> {code}
>  
> Will produce the following *EventType.cs*
> {code:c#}
> namespace my.csharp.ns
> {
>       using System;
>       using System.Collections.Generic;
>       using System.Text;
>       using Avro;
>       using Avro.Specific;
>       
>       public enum EventType
>       {
>               CREATE,
>               UPDATE,
>               DELETE,
>       }
> }
> {code}
>  
> and the following *TestModel.cs*
> {code:c#}
> namespace my.csharp.ns
> {
>       using System;
>       using System.Collections.Generic;
>       using System.Text;
>       using Avro;
>       using Avro.Specific;
>       
>       public partial class TestModel : ISpecificRecord
>       {
>               public static Schema _SCHEMA = 
> Avro.Schema.Parse("{\"type\":\"record\",\"name\":\"TestModel\",\"namespace\":\"my.avro.ns\",\"fields\":[{\"name\":\"e"
>  +
>                               
> "ventType\",\"type\":{\"type\":\"enum\",\"name\":\"EventType\",\"namespace\":\"my.avro.ns\",\"sym"
>  +
>                               
> "bols\":[\"CREATE\",\"UPDATE\",\"DELETE\"]}}]}");
>               private my.avro.ns.EventType _eventType;
>                // More generated code
>         }
> }
> {code}
> Notice how the namespace is set correctly to *my.csharp.ns* in both files, 
> but the namespace of the referenced *EventType* in *TestModel.cs* is 
> incorrect.
>  
> Example of expected output (*TestModel.cs*):
> {code:c#}
> namespace my.csharp.ns
> {
>       using System;
>       using System.Collections.Generic;
>       using System.Text;
>       using Avro;
>       using Avro.Specific;
>       
>       public partial class TestModel : ISpecificRecord
>       {
>               public static Schema _SCHEMA = 
> Avro.Schema.Parse("{\"type\":\"record\",\"name\":\"TestModel\",\"namespace\":\"my.avro.ns\",\"fields\":[{\"name\":\"e"
>  +
>                               
> "ventType\",\"type\":{\"type\":\"enum\",\"name\":\"EventType\",\"namespace\":\"my.avro.ns\",\"sym"
>  +
>                               
> "bols\":[\"CREATE\",\"UPDATE\",\"DELETE\"]}}]}");
>               private my.csharp.ns.EventType _eventType;
>                // More generated code
>         }
> }
> {code}
>  
> Code for reproducing the issue can be found at: 
> [https://github.com/FuKe/avrogen-namespace-bug]



--
This message was sent by Atlassian Jira
(v8.20.7#820007)

Reply via email to