You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@avro.apache.org by Roger Hoover <ro...@gmail.com> on 2015/04/09 17:29:00 UTC

How to join two records?

Hi,

If I have a two records of type A and B as below and want to join them
similar to "SELECT *" in SQL to produce a record of type AB, is there an
simple way to do this with Avro without writing code to copy each field
individually?  It's like a reverse projection.  I want to take to disjoint
projections of AB and merge them to create an AB record.

I appreciate any help.

Thanks,

Roger

{
  "name": "A",
  "type": "record",
  "namespace": "fubar",
  "fields": [{"name": "a", "type" : "int"}]
}

{
  "name": "B",
  "type": "record",
  "namespace": "fubar",
  "fields": [{"name": "b", "type" : "int"}]
}

{
  "name": "AB",
  "type": "record",
  "namespace": "fubar",
  "fields": [{"name": "a", "type" : "int"}, {"name": "b", "type" : "int"}]
}

Json to Avro

Posted by Marius <m....@googlemail.com>.
Hello,

i want to convert a json file (or even xml) into avro. The problem is 
that the file is deeply nested and for reasons i can't define an avsc 
before parsing and instead the avsc schould b build uring converting. Is 
there any possibility to do so in Python 3?

Greetings,

Marius

Re: How to join two records?

Posted by Roger Hoover <ro...@gmail.com>.
In case this helps anyone, I created a simple class to do the join and it
works nicely for my use case.  If there's already a library function for
this, let me know.

Example (
https://github.com/Quantiply/rico/blob/master/avro-serde/src/test/java/com/quantiply/avro/JoinTest.java#L44-L52
):

        GenericRecord in1 = getIn1();
        GenericRecord in2 = getIn2();

        GenericRecord joined = new Join(getJoinedSchema())
                .merge(in1)
                .merge(in2)
                .getBuilder()
                .set("charlie", "blah blah")
                .build();

Class is here:
https://github.com/Quantiply/rico/blob/master/avro-serde/src/main/java/com/quantiply/avro/Join.java

Cheers,

Roger

On Thu, Apr 9, 2015 at 8:29 AM, Roger Hoover <ro...@gmail.com> wrote:

> Hi,
>
> If I have a two records of type A and B as below and want to join them
> similar to "SELECT *" in SQL to produce a record of type AB, is there an
> simple way to do this with Avro without writing code to copy each field
> individually?  It's like a reverse projection.  I want to take to disjoint
> projections of AB and merge them to create an AB record.
>
> I appreciate any help.
>
> Thanks,
>
> Roger
>
> {
>   "name": "A",
>   "type": "record",
>   "namespace": "fubar",
>   "fields": [{"name": "a", "type" : "int"}]
> }
>
> {
>   "name": "B",
>   "type": "record",
>   "namespace": "fubar",
>   "fields": [{"name": "b", "type" : "int"}]
> }
>
> {
>   "name": "AB",
>   "type": "record",
>   "namespace": "fubar",
>   "fields": [{"name": "a", "type" : "int"}, {"name": "b", "type" : "int"}]
> }
>