Return-Path: X-Original-To: apmail-avro-dev-archive@www.apache.org Delivered-To: apmail-avro-dev-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 9DED1DB80 for ; Tue, 14 May 2013 22:43:16 +0000 (UTC) Received: (qmail 96051 invoked by uid 500); 14 May 2013 22:43:16 -0000 Delivered-To: apmail-avro-dev-archive@avro.apache.org Received: (qmail 95860 invoked by uid 500); 14 May 2013 22:43:16 -0000 Mailing-List: contact dev-help@avro.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@avro.apache.org Delivered-To: mailing list dev@avro.apache.org Received: (qmail 95845 invoked by uid 99); 14 May 2013 22:43:16 -0000 Received: from arcas.apache.org (HELO arcas.apache.org) (140.211.11.28) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 14 May 2013 22:43:16 +0000 Date: Tue, 14 May 2013 22:43:16 +0000 (UTC) From: "Doug Cutting (JIRA)" To: dev@avro.apache.org Message-ID: In-Reply-To: References: Subject: [jira] [Commented] (AVRO-1245) Add Merging Functionality to Generated Builders MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit X-JIRA-FingerPrint: 30527f35849b9dde25b450d4833f0394 [ https://issues.apache.org/jira/browse/AVRO-1245?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13657627#comment-13657627 ] Doug Cutting commented on AVRO-1245: ------------------------------------ I think Scott's approach might be a little easier to write and maintain. The could share much of their logic if we implement a walker that supports rewriting values, then replaceNullsWithDefaults might be written as something like: {code} new Walker(schema, model).rewrite(thirdPartyRecord, new RewriterBase(model) { Object rewrite(Field field, Object value) { return value == null ? getModel().getDefaultValue(field); : value; } }); {code} Otherwise merge() would get more and more complex as new options are added. A walker might be implemented that combined other walkers, so that multiple rewrites could be done in a single pass. We might re-implement DeepCopy as a rewriter. > Add Merging Functionality to Generated Builders > ----------------------------------------------- > > Key: AVRO-1245 > URL: https://issues.apache.org/jira/browse/AVRO-1245 > Project: Avro > Issue Type: Improvement > Components: java > Affects Versions: 1.7.3 > Environment: Linux Mint 32-bit, Java 7, Avro 1.7.3 > Reporter: Sharmarke Aden > Priority: Minor > > Suppose I have a record with the following schema and default values: > {code} > { > "type": "record", > "namespace": "test", > "name": "User", > "fields": [ > { > "name": "user", > "type": ["null", "string"], > "default": null > }, > { > "name": "privacy", > "type": [ > { > "type": "enum", > "name": "Privacy", > "namespace": "test", > "symbols": ["Public", "Private"] > }, > "null" > ], > "default": "Private" > } > ] > } > {code} > Now suppose I have a record supplied to me by a third party whose privacy field value is null. Currently if you call "Builder.newBuilder(thirdPartyRecord)" it simply creates a new record with same values as the source record (privacy is null in the newly created builder). > It's very important that the privacy value be set and so ideally I would like to perform a merge to mitigate any issues with default values being absent in the source record. I would like to propose that a new enhancement be added to the Builder to support merging of a source record to a new record. Perhaps something like this: > {code} > // recordWithoutDefaults record passed in. > User.Builder builder = User.newBuilder(); > //ignore null values in the source record if the schema has a default > //value for the field > boolean ignoreNull = true; > //ignore empty string values in the source record for string field > //types with default field values > boolean ignoreEmptyString = true; > //while this is simple and useful in my use-case perhaps there's a > //better/refined way of supporting veracious merging models > builder.merge(recordWithoutDefaults, ignoreNull, ignoreEmptyString); > {code} -- 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