You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@avro.apache.org by "Doug Cutting (JIRA)" <ji...@apache.org> on 2012/11/05 19:42:12 UTC

[jira] [Commented] (AVRO-1188) External Schema Imports via AVSC Schema

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

Doug Cutting commented on AVRO-1188:
------------------------------------

In many cases we require that schemas are standalone, that they do not have external references.  For example, the schema included in a data file or transmitted to a remote server in RPC must be standalone.  For this reason we've generally suggested that folks use some sort of pre-processor when they need to include schemas.  The IDL compiler is one such pre-processor but one might also reasonably use cpp, m4 or some other pre-processor for this.

Note however that the Java schema parser remembers all named schemas previously parsed by the same schema.  Thus if one first parses your privacy.avsc above then post.avsc and/or event.avsc with the same parser, then the effect you desire is achieved.

http://avro.apache.org/docs/current/api/java/org/apache/avro/Schema.Parser.html

This facility is used, e.g., by the command-line schema compiler.  Schemas are processed in the order listed on the command line so that later schemas may depend on earlier schemas.  AVRO-983 changes Avro's Maven plugin so that schemas are processed by a single parser in directory-traversal order, permitting dependencies.

Would either of these features work for you?  If not, can you tell more about your use case?
                
> External Schema Imports via AVSC Schema
> ---------------------------------------
>
>                 Key: AVRO-1188
>                 URL: https://issues.apache.org/jira/browse/AVRO-1188
>             Project: Avro
>          Issue Type: New Feature
>          Components: java
>            Reporter: Sharmarke Aden
>
> There is no way for ".avsc" schema files to import types (i.e records, enums, etc) in external schema files. There's tremendous benefit in being able to do this as it would all for the sharing of common types between multiple schema files. Here's a use case that illustrates the typical usecase of this feature request.
> Suppose we have an enum called "Privacy" that we would like to share between multiple schemas:
> {code}
> //privacy.avsc
> { 
>   "type": "enum",
>   "name": "Privacy",
>   "symbols" : ["Public", "Private"]
> }
> {code}
> Now, if this feature was implemented one could import the above type into other schema files by doing something like this: 
> {code}
> //the post.avsc 
> {
>   "type": "record", 
>   "name": "Post",
>   "imports": ["privacy.avsc"] //you can import one or more schemas
>   "fields": [{
>               "name": "privacy", 
>               "type": [ "null", "Privacy"], //use imported Privacy type
>               "default": "Private"
>             }
>   ]
> }
> {code}
> Here's another schema file that also has a similar privacy concern:
> {code}
> //the event.avsc is another schema that also imports the privacy type
> {
>   "type": "record", 
>   "name": "Event",
>   "imports": ["privacy.avsc"] //it also imports the privacy schemas
>   "fields": [{
>               "name": "privacy", 
>               "type": [ "null", "Privacy"], //use imported Privacy type
>               "default": "Public"
>             }
>   ]
> }
> {code}
> IDL files are able to import external schemas and protocols and it would be very beneficial if schema files could import other schema files. 

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see: http://www.atlassian.com/software/jira