Return-Path: X-Original-To: apmail-crunch-dev-archive@www.apache.org Delivered-To: apmail-crunch-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 D408718597 for ; Thu, 23 Jul 2015 12:42:05 +0000 (UTC) Received: (qmail 84385 invoked by uid 500); 23 Jul 2015 12:42:05 -0000 Delivered-To: apmail-crunch-dev-archive@crunch.apache.org Received: (qmail 84325 invoked by uid 500); 23 Jul 2015 12:42:05 -0000 Mailing-List: contact dev-help@crunch.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@crunch.apache.org Delivered-To: mailing list dev@crunch.apache.org Received: (qmail 84023 invoked by uid 500); 23 Jul 2015 12:42:05 -0000 Delivered-To: apmail-incubator-crunch-dev@incubator.apache.org Received: (qmail 84017 invoked by uid 99); 23 Jul 2015 12:42:05 -0000 Received: from arcas.apache.org (HELO arcas.apache.org) (140.211.11.28) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 23 Jul 2015 12:42:05 +0000 Date: Thu, 23 Jul 2015 12:42:05 +0000 (UTC) From: "Adric Eckstein (JIRA)" To: crunch-dev@incubator.apache.org Message-ID: In-Reply-To: References: Subject: [jira] [Commented] (CRUNCH-547) AvroType operators can create nested unions 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/CRUNCH-547?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=14638738#comment-14638738 ] Adric Eckstein commented on CRUNCH-547: --------------------------------------- Patch looks good. This fixes the issue. More generally, is it necessary to force the values to be nullable when creating a table type? Should this be optional? > AvroType operators can create nested unions > ------------------------------------------- > > Key: CRUNCH-547 > URL: https://issues.apache.org/jira/browse/CRUNCH-547 > Project: Crunch > Issue Type: Bug > Components: IO > Reporter: Adric Eckstein > Attachments: CRUNCH-547.patch > > > When using avro reflection to create PTypes, the type might represent a union type, as specified by the @Union annotation. Derived types from this, such as tableOf() and collections() will create a null union from this (already union) type and create a nested union which throws an AvroRuntimeException. > @org.apache.avro.reflect.Union({ Foo1.class, Foo2.class }) > public static interface Foo { > public String getFoo(); > } > public static class Foo1 implements Foo { > private final Double value = 1.0; > @Override > public String getFoo() { > return value.toString(); > } > } > public static class Foo2 implements Foo { > private final Integer value = 2; > @Override > public String getFoo() { > return value.toString(); > } > } > Schema schema = ReflectData.get().getSchema(Foo.class); > AvroType ptype = Avros.reflects(Foo.class, schema); > Avros.tableOf(Avros.strings(), ptype); > Avros.collections(ptype); > Exception in thread "main" org.apache.avro.AvroRuntimeException: Nested union: [["double","string"],"null"] > ... > Seems like the methods Avros.allowNulls() and AvroTableType.nullable() both are calling Schema.createUnion(unionSchema, nullSchema), and could add an extra case statement to use the already existing union schema. -- This message was sent by Atlassian JIRA (v6.3.4#6332)