avro-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Thiruvalluvan M. G. (JIRA)" <j...@apache.org>
Subject [jira] Updated: (AVRO-261) Allow Schemas to be immutable
Date Fri, 05 Feb 2010 03:32:28 GMT

     [ https://issues.apache.org/jira/browse/AVRO-261?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel

Thiruvalluvan M. G. updated AVRO-261:

    Attachment: AVRO-261.patch

Google's immutablemap seems promising. But I think I found a solution without using immutable

AVRO-388 added the _name_ field to _Schema.Field_. Schema.getFields(), which is a _LinkedHashMap<String,
Field>_ is used for two purposes:
   - To iterate over the Fields. Since the _Field_ now has name, this use can be handled by
a _List<Field>_. That is _getFields()_ can return _List<Field>_.
   - To get the Field for a given fieldname. This is a much less frequent use case. This can
be achieved by adding a _getField(String)_ method in _Schema_. To implement it, we'll can
a Map<String, Field> inside _RecordSchema_, but this map is not exposed outside _RecordSchema_.

The _getFieldSchemas()_ method is longer required as its purpose can be served by the two
methods (_List<Field> getFields()_ and _Field getField(String)_ above.

As a consequence _setFields()_ can now take a _List<Field>_ instead of _LinkedHashMap<String,

To solve the problem with setProp(), I renamed it to addProp() and changed its semantics to
allow only addition of new properties (no deletion or update)

It turns out that the code in many places have become simpler with these changes.

There is no performance impact. I tested with both pre- and post-AVRO-388 GenericDatumReader.

> Allow Schemas to be immutable
> -----------------------------
>                 Key: AVRO-261
>                 URL: https://issues.apache.org/jira/browse/AVRO-261
>             Project: Avro
>          Issue Type: New Feature
>          Components: java
>            Reporter: Kevin Oliver
>            Assignee: Thiruvalluvan M. G.
>            Priority: Minor
>         Attachments: AVRO-261.patch, AVRO-261.patch
> It would be nice if there was the ability to have an immutable Schema in java. 
> Without this, it makes sharing schemas risky. Also, with this, we could (lazily) cache
the hashCode which is a fairly expensive operation today, especially on something like a record.

This message is automatically generated by JIRA.
You can reply to this email to add a comment to the issue online.

View raw message