Home | About | Sematext search-lucene.com search-hadoop.com
 Search Hadoop and all its subprojects:

Switch to Plain View
Avro, mail # user - Make a copy of an avro record


+
Jeremy Lewi 2012-03-11, 20:40
+
easyvoip@... 2012-03-11, 20:52
+
Jeremy Lewi 2012-03-11, 21:22
+
James Baldassari 2012-03-12, 01:20
+
Jeremy Lewi 2012-03-12, 02:37
+
Jeremy Lewi 2012-03-12, 04:07
+
Jeremy Lewi 2012-03-12, 04:26
Copy link to this message
-
Re: Make a copy of an avro record
James Baldassari 2012-03-12, 05:22
If you want to make a deep copy of a specific record, the easiest way is
probably to use the Builder API,
e.g. GraphNodeData.newBuilder(recordToCopy).build().  This will create a
deep copy of 'recordToBuild' and then return it as a new GraphNodeData
object.  Keep in mind that the performance of the Builder API is not great
at the moment.  There are a couple of issues out there for improving this:

https://issues.apache.org/jira/browse/AVRO-985
https://issues.apache.org/jira/browse/AVRO-989

-James
On Mon, Mar 12, 2012 at 12:26 AM, Jeremy Lewi <[EMAIL PROTECTED]> wrote:

> Looks like when I upgraded to Java 7 it ran fine.
>
>
> On Sun, Mar 11, 2012 at 9:07 PM, Jeremy Lewi <[EMAIL PROTECTED]> wrote:
>
>> GenericData.deepCopy gives me an instance of GenericData.Record. How do I
>> convert this to an instance of my specific data (e.g GraphNodeData).
>>
>> It looks like the issue with the @override statement for the build might
>> have something to do with the fact that the specification for @Override
>> changed in jdk1.6 (see this post)
>>
>> http://stackoverflow.com/questions/2335655/why-is-javac-failing-on-override-annotation.
>>  However, I'm using java version 1.6.0_27 so I'm not sure why its not
>> working for me.
>>
>> To clarify, the statement
>> GraphNodeData copy = GraphNodeData.newBuilder(this.data).build()
>> Compiles fine, but generates a runtime warning
>> The method build() of type GraphNodeData.Builder must override a
>> superclass method
>>
>> J
>>
>>
>> On Sun, Mar 11, 2012 at 7:37 PM, Jeremy Lewi <[EMAIL PROTECTED]> wrote:
>>
>>> Thanks.
>>>
>>> J
>>>
>>>
>>> On Sun, Mar 11, 2012 at 6:20 PM, James Baldassari <[EMAIL PROTECTED]
>>> > wrote:
>>>
>>>> GenericData is a singleton.  You can use the static method
>>>> GenericData#get() to obtain the singleton instance:
>>>>
>>>>
>>>> http://avro.apache.org/docs/current/api/java/org/apache/avro/generic/GenericData.html#get()
>>>>
>>>> -James
>>>>
>>>>
>>>> On Sun, Mar 11, 2012 at 5:22 PM, Jeremy Lewi <[EMAIL PROTECTED]> wrote:
>>>>
>>>>> Yes. How do I instantiate an instance of GenericData though? It looks
>>>>> like its constructors are protected.
>>>>>
>>>>> Thanks
>>>>> J
>>>>>
>>>>>
>>>>> On Sun, Mar 11, 2012 at 1:52 PM, <[EMAIL PROTECTED]> wrote:
>>>>>
>>>>>> There is deepcopy method on genericdata I think
>>>>>>
>>>>>> I used it to create deep copies of the avro data
>>>>>>
>>>>>> Sent from my iPhone
>>>>>>
>>>>>> On Mar 11, 2012, at 3:40 PM, Jeremy Lewi <[EMAIL PROTECTED]> wrote:
>>>>>>
>>>>>> > Hi,
>>>>>> >
>>>>>> > In java, I'd like to make a deep copy of an avro record.
>>>>>> >
>>>>>> > Looking at the code that the avro compiler generates it looks like
>>>>>> the way to do this for records of type GraphNodeData
>>>>>> > would be
>>>>>> > GraphNodeData copy >>>>>> GraphNodeData.newBuilder(existing_value).build();
>>>>>> >
>>>>>> > where GraphNodeData is the name of my avro record.
>>>>>> >
>>>>>> > Unfortunately, this generates a compile time error because
>>>>>> > the method GraphNodeData.build  is decorated with "@Override" but
>>>>>> it apparently does not override any method.
>>>>>> > Deleting "@Override" makes the code work. Unfortunately, I would
>>>>>> have to do this every time I regenerated my avro classes from the schema.
>>>>>> >
>>>>>> > Am I doing something wrong or should I file a bug?
>>>>>> >
>>>>>> > Thanks
>>>>>> > J
>>>>>>
>>>>>
>>>>>
>>>>
>>>
>>
>
+
Doug Cutting 2012-03-12, 16:05
+
Jeremy Lewi 2012-03-12, 16:27
+
Scott Carey 2012-03-12, 17:20
+
Doug Cutting 2012-03-12, 17:42
+
Jeremy Lewi 2012-03-12, 18:09
+
Doug Cutting 2012-03-12, 18:45
+
Scott Carey 2012-03-12, 22:38