You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@avro.apache.org by "ASF GitHub Bot (Jira)" <ji...@apache.org> on 2021/09/06 13:24:00 UTC

[jira] [Work logged] (AVRO-3182) Avro in Java cannot parse the union schema from C#

     [ https://issues.apache.org/jira/browse/AVRO-3182?focusedWorklogId=646961&page=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-646961 ]

ASF GitHub Bot logged work on AVRO-3182:
----------------------------------------

                Author: ASF GitHub Bot
            Created on: 06/Sep/21 13:23
            Start Date: 06/Sep/21 13:23
    Worklog Time Spent: 10m 
      Work Description: RyanSkraba commented on pull request #1303:
URL: https://github.com/apache/avro/pull/1303#issuecomment-913648616


   Thanks for the contribution!


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@avro.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Issue Time Tracking
-------------------

            Worklog Id:     (was: 646961)
    Remaining Estimate: 0h
            Time Spent: 10m

> Avro in Java cannot parse the union schema from C#
> --------------------------------------------------
>
>                 Key: AVRO-3182
>                 URL: https://issues.apache.org/jira/browse/AVRO-3182
>             Project: Apache Avro
>          Issue Type: Bug
>          Components: csharp, java
>    Affects Versions: 1.10.2
>            Reporter: Shawn Wu
>            Assignee: Shawn Wu
>            Priority: Critical
>             Fix For: 1.11.0
>
>          Time Spent: 10m
>  Remaining Estimate: 0h
>
> Version: 1.10.2
>  
> I need to transfer data from C# to Java.
> When I use Avro in C#, I found [Schema.ToString() in C#|https://github.com/apache/avro/blob/master/lang/csharp/src/apache/main/Schema/Schema.cs#L272] for union schema will add an extra *type* property in JSON string.
> However, the correct union schema is a JSON array.
> This is my test code in C#:
> {code:java}
> var columnCountSchema = Schema.Parse("{\"type\":\"record\",\"name\":\"columnCount\",\"namespace\":\"avro.test.header\",\"fields\":[{\"name\":\"columnCount\",\"type\":\"int\"}]}");
> var errorMessageSchema = Schema.Parse("{\"type\":\"record\",\"name\":\"errorMessage\",\"namespace\":\"avro.test.header\",\"fields\":[{\"name\":\"errorMessage\",\"type\":[\"string\",\"null\"]}]}");
> var schema = Schema.Parse($"[{columnCountSchema},{errorMessageSchema}]");
> Console.WriteLine(schema.ToString());{code}
> The output:
> {code:java}
> {"type":[{"type":"record","name":"columnCount","namespace":"avro.test.header","fields":[{"name":"columnCount","type":"int"}]},{"type":"record","name":"errorMessage","namespace":"avro.test.header","fields":[{"name":"errorMessage","type":["string","null"]}]}]}
> {code}
>  
> When I use Avro in C# to parse this union schema JSON string, it is correct. [Schema.ParseJson() in C#|https://github.com/apache/avro/blob/master/lang/csharp/src/apache/main/Schema/Schema.cs#L203]
> But when I use Avro in Java to parse the union schema in Stream from C#, there is the following error message:
> {code:java}
> org.apache.avro.SchemaParseException: No type: {"type":[{"type":"record","name":"columnCount","namespace":"avro.test.header","fields":[{"name":"columnCount","type":"int"}]},{"type":"record","name":"errorMessage","namespace":"avro.test.header","fields":[{"name":"errorMessage","type":["string","null"]}]}]}org.apache.avro.SchemaParseException: No type: {"type":[{"type":"record","name":"columnCount","namespace":"avro.test.header","fields":[{"name":"columnCount","type":"int"}]},{"type":"record","name":"errorMessage","namespace":"avro.test.header","fields":[{"name":"errorMessage","type":["string","null"]}]}]} at org.apache.avro.Schema.getRequiredText(Schema.java:1784) at org.apache.avro.Schema.parse(Schema.java:1637) at org.apache.avro.Schema$Parser.parse(Schema.java:1425) at org.apache.avro.Schema$Parser.parse(Schema.java:1413) at org.apache.avro.file.DataFileStream.initialize(DataFileStream.java:130) at org.apache.avro.file.DataFileStream.<init>(DataFileStream.java:90) at avro.AvroService.read(AvroService.java:68) at avro.AvroService$1.onResponse(AvroService.java:144) at okhttp3.internal.connection.RealCall$AsyncCall.run(RealCall.kt:519) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624) at java.lang.Thread.run(Thread.java:748)
> {code}
> I think this format of union schema should be supported in Java.
>  



--
This message was sent by Atlassian Jira
(v8.3.4#803005)