Return-Path: X-Original-To: archive-asf-public-internal@cust-asf2.ponee.io Delivered-To: archive-asf-public-internal@cust-asf2.ponee.io Received: from cust-asf.ponee.io (cust-asf.ponee.io [163.172.22.183]) by cust-asf2.ponee.io (Postfix) with ESMTP id 10ACE200CA5 for ; Sat, 27 May 2017 00:37:12 +0200 (CEST) Received: by cust-asf.ponee.io (Postfix) id 0F370160B9C; Fri, 26 May 2017 22:37:12 +0000 (UTC) Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by cust-asf.ponee.io (Postfix) with SMTP id 2EC1C160BD6 for ; Sat, 27 May 2017 00:37:11 +0200 (CEST) Received: (qmail 67805 invoked by uid 500); 26 May 2017 22:37:10 -0000 Mailing-List: contact dev-help@pig.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@pig.apache.org Delivered-To: mailing list dev@pig.apache.org Received: (qmail 67648 invoked by uid 500); 26 May 2017 22:37:10 -0000 Delivered-To: apmail-hadoop-pig-dev@hadoop.apache.org Received: (qmail 67633 invoked by uid 99); 26 May 2017 22:37:10 -0000 Received: from pnap-us-west-generic-nat.apache.org (HELO spamd4-us-west.apache.org) (209.188.14.142) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 26 May 2017 22:37:10 +0000 Received: from localhost (localhost [127.0.0.1]) by spamd4-us-west.apache.org (ASF Mail Server at spamd4-us-west.apache.org) with ESMTP id 9EFADC0145 for ; Fri, 26 May 2017 22:37:09 +0000 (UTC) X-Virus-Scanned: Debian amavisd-new at spamd4-us-west.apache.org X-Spam-Flag: NO X-Spam-Score: -99.202 X-Spam-Level: X-Spam-Status: No, score=-99.202 tagged_above=-999 required=6.31 tests=[KAM_ASCII_DIVIDERS=0.8, RP_MATCHES_RCVD=-0.001, SPF_PASS=-0.001, USER_IN_WHITELIST=-100] autolearn=disabled Received: from mx1-lw-eu.apache.org ([10.40.0.8]) by localhost (spamd4-us-west.apache.org [10.40.0.11]) (amavisd-new, port 10024) with ESMTP id CLyg5pbL0s8X for ; Fri, 26 May 2017 22:37:08 +0000 (UTC) Received: from mailrelay1-us-west.apache.org (mailrelay1-us-west.apache.org [209.188.14.139]) by mx1-lw-eu.apache.org (ASF Mail Server at mx1-lw-eu.apache.org) with ESMTP id 89BDB60DA8 for ; Fri, 26 May 2017 22:37:06 +0000 (UTC) Received: from jira-lw-us.apache.org (unknown [207.244.88.139]) by mailrelay1-us-west.apache.org (ASF Mail Server at mailrelay1-us-west.apache.org) with ESMTP id 4B89CE0A75 for ; Fri, 26 May 2017 22:37:05 +0000 (UTC) Received: from jira-lw-us.apache.org (localhost [127.0.0.1]) by jira-lw-us.apache.org (ASF Mail Server at jira-lw-us.apache.org) with ESMTP id C46CD2400A for ; Fri, 26 May 2017 22:37:04 +0000 (UTC) Date: Fri, 26 May 2017 22:37:04 +0000 (UTC) From: "Rohini Palaniswamy (JIRA)" To: pig-dev@hadoop.apache.org Message-ID: In-Reply-To: References: Subject: [jira] [Updated] (PIG-5115) Builtin AvroStorage generates incorrect avro schema when the same pig field name appears in the alias MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit X-JIRA-FingerPrint: 30527f35849b9dde25b450d4833f0394 archived-at: Fri, 26 May 2017 22:37:12 -0000 [ https://issues.apache.org/jira/browse/PIG-5115?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ] Rohini Palaniswamy updated PIG-5115: ------------------------------------ Fix Version/s: (was: 0.17.0) 0.18.0 > Builtin AvroStorage generates incorrect avro schema when the same pig field name appears in the alias > ----------------------------------------------------------------------------------------------------- > > Key: PIG-5115 > URL: https://issues.apache.org/jira/browse/PIG-5115 > Project: Pig > Issue Type: Bug > Affects Versions: 0.17.0 > Reporter: Anyi Li > Assignee: Anyi Li > Fix For: 0.18.0 > > Attachments: PIG-5115.patch > > > Pig ResourceSchema allows to use same field names but different types when they are not in the same level. The pig schema like > {quote} > data: {col1: (col2: (col1_data: chararray)),col2: {col2: (col2_data: chararray)}} > {quote} > Although _col2_ has been redefined, they are not appeared in the same level, it is a totally valid pig schema. > However, once it is translated by AvroStorage, it will throw exception > {noformat} > Can't redefine: col2 > at org.apache.pig.newplan.logical.visitor.InputOutputFileValidatorVisitor.visit(InputOutputFileValidatorVisitor.java:64) > at org.apache.pig.newplan.logical.relational.LOStore.accept(LOStore.java:66) > at org.apache.pig.newplan.DepthFirstWalker.depthFirst(DepthFirstWalker.java:64) > at org.apache.pig.newplan.DepthFirstWalker.depthFirst(DepthFirstWalker.java:66) > at org.apache.pig.newplan.DepthFirstWalker.depthFirst(DepthFirstWalker.java:66) > at org.apache.pig.newplan.DepthFirstWalker.walk(DepthFirstWalker.java:53) > at org.apache.pig.newplan.PlanVisitor.visit(PlanVisitor.java:52) > at org.apache.pig.newplan.logical.relational.LogicalPlan.validate(LogicalPlan.java:212) > at org.apache.pig.PigServer$Graph.compile(PigServer.java:1767) > at org.apache.pig.PigServer$Graph.access$300(PigServer.java:1443) > at org.apache.pig.PigServer.execute(PigServer.java:1356) > at org.apache.pig.PigServer.executeBatch(PigServer.java:415) > at org.apache.pig.PigServer.executeBatch(PigServer.java:398) > at org.apache.pig.tools.grunt.GruntParser.executeBatch(GruntParser.java:171) > at org.apache.pig.tools.grunt.GruntParser.parseStopOnError(GruntParser.java:234) > at org.apache.pig.tools.grunt.GruntParser.parseStopOnError(GruntParser.java:205) > at org.apache.pig.tools.grunt.Grunt.exec(Grunt.java:81) > at org.apache.pig.Main.run(Main.java:631) > at org.apache.pig.Main.main(Main.java:177) > Caused by: org.apache.avro.SchemaParseException: Can't redefine: col2 > at org.apache.avro.Schema$Names.put(Schema.java:1042) > at org.apache.avro.Schema$NamedSchema.writeNameRef(Schema.java:511) > at org.apache.avro.Schema$RecordSchema.toJson(Schema.java:626) > at org.apache.avro.Schema$ArraySchema.toJson(Schema.java:737) > at org.apache.avro.Schema$UnionSchema.toJson(Schema.java:814) > at org.apache.avro.Schema$RecordSchema.fieldsToJson(Schema.java:648) > at org.apache.avro.Schema$RecordSchema.toJson(Schema.java:635) > at org.apache.avro.Schema.toString(Schema.java:297) > at org.apache.avro.Schema.toString(Schema.java:287) > at org.apache.pig.builtin.AvroStorage.setOutputAvroSchema(AvroStorage.java:442) > at org.apache.pig.builtin.AvroStorage.checkSchema(AvroStorage.java:433) > at org.apache.pig.newplan.logical.visitor.InputOutputFileValidatorVisitor.visit(InputOutputFileValidatorVisitor.java:54) > ... 18 more > {noformat} > It is caused by a bug in AvroStorageSchemaConversionUtilities class which uses tuple name as GenericRecord name as well as the fieldname that wraps the record. > So it would like to produces the avro schema like the following > {noformat} > { > "type": "record", > "name": "data", > "fields": [ > { > "name": "col1", > "type": { > "type": "record", > "name": "col1_1", > "fields": [ > { > "name": "col2", > "type": { > "type": "record", > "name": "col2", > "fields": [ > { > "name": "col1_data", > "type": "string" > } > ] > } > } > ] > } > }, > { > "name": "col2", > "type": { > "type": "array", > "items": { > "type": "record", > "name": "col2", > "fields": [ > { > "name": "col2_data", > "type": "string" > } > ] > } > } > } > ] > } > {noformat} > But according to the avro 1.7.7 specs ([https://avro.apache.org/docs/1.7.7/spec.html#Names]), _col2_ has been defined as record and redefined as array later, it is an invalid schema, unless the fullname (namespace + name) is unique. > Since AvroStorageSchemaConversionUtilities will generate avro record if the pig schema is a tuple, we need a way to generate unique _recordName_. > {code} > public static Schema resourceSchemaToAvroSchema(final ResourceSchema rs, > String recordName, final String recordNameSpace, > final Map> definedRecordNames, > final Boolean doubleColonsToDoubleUnderscores) throws IOException { > if (rs == null) { > return null; > } > recordName = toAvroName(recordName, doubleColonsToDoubleUnderscores); > List fields = new ArrayList(); > Schema newSchema = Schema.createRecord( > recordName, null, recordNameSpace, false); > {code} > The AvroStorage class from piggybank solved this problem by defining a static method and generate unique _recordName_. We can implement the similar method for the builtin AvroStorage > -- This message was sent by Atlassian JIRA (v6.3.15#6346)