From commits-return-1156-apmail-avro-commits-archive=avro.apache.org@avro.apache.org Fri Dec 9 20:27:56 2011 Return-Path: X-Original-To: apmail-avro-commits-archive@www.apache.org Delivered-To: apmail-avro-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id C7B5E79F4 for ; Fri, 9 Dec 2011 20:27:56 +0000 (UTC) Received: (qmail 63265 invoked by uid 500); 9 Dec 2011 20:27:56 -0000 Delivered-To: apmail-avro-commits-archive@avro.apache.org Received: (qmail 63218 invoked by uid 500); 9 Dec 2011 20:27:56 -0000 Mailing-List: contact commits-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 commits@avro.apache.org Received: (qmail 63211 invoked by uid 99); 9 Dec 2011 20:27:55 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 09 Dec 2011 20:27:55 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=5.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 09 Dec 2011 20:27:52 +0000 Received: from eris.apache.org (localhost [127.0.0.1]) by eris.apache.org (Postfix) with ESMTP id BE15823889DA for ; Fri, 9 Dec 2011 20:27:30 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r1212611 - in /avro/trunk: ./ lang/java/avro/src/main/java/org/apache/avro/ lang/java/compiler/src/main/javacc/org/apache/avro/compiler/idl/ lang/java/compiler/src/test/idl/input/ lang/java/compiler/src/test/idl/output/ lang/java/ipc/src/te... Date: Fri, 09 Dec 2011 20:27:30 -0000 To: commits@avro.apache.org From: cutting@apache.org X-Mailer: svnmailer-1.0.8-patched Message-Id: <20111209202730.BE15823889DA@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: cutting Date: Fri Dec 9 20:27:29 2011 New Revision: 1212611 URL: http://svn.apache.org/viewvc?rev=1212611&view=rev Log: AVRO-972. Java: Add support for Infinity and NaN as default values for float and double. Modified: avro/trunk/CHANGES.txt avro/trunk/lang/java/avro/src/main/java/org/apache/avro/Schema.java avro/trunk/lang/java/compiler/src/main/javacc/org/apache/avro/compiler/idl/idl.jj avro/trunk/lang/java/compiler/src/test/idl/input/simple.avdl avro/trunk/lang/java/compiler/src/test/idl/output/simple.avpr avro/trunk/lang/java/ipc/src/test/java/org/apache/avro/TestSchema.java Modified: avro/trunk/CHANGES.txt URL: http://svn.apache.org/viewvc/avro/trunk/CHANGES.txt?rev=1212611&r1=1212610&r2=1212611&view=diff ============================================================================== --- avro/trunk/CHANGES.txt (original) +++ avro/trunk/CHANGES.txt Fri Dec 9 20:27:29 2011 @@ -14,6 +14,11 @@ Avro 1.6.2 (unreleased) AVRO-953. Python: Permit users to override HTTP path in RPC. (Craig Landry via cutting) + AVRO-972. Java: Add support for Infinity and NaN as default values + for float and double. Since JSON does not permit these as numeric + types, we use the strings "NaN", "Infinity" and "-Infinity" in + schemas. These are also permitted in IDL. (cutting) + BUG FIXES AVRO-962. Java: Fix Maven plugin to support string type override. Modified: avro/trunk/lang/java/avro/src/main/java/org/apache/avro/Schema.java URL: http://svn.apache.org/viewvc/avro/trunk/lang/java/avro/src/main/java/org/apache/avro/Schema.java?rev=1212611&r1=1212610&r2=1212611&view=diff ============================================================================== --- avro/trunk/lang/java/avro/src/main/java/org/apache/avro/Schema.java (original) +++ avro/trunk/lang/java/avro/src/main/java/org/apache/avro/Schema.java Fri Dec 9 20:27:29 2011 @@ -41,6 +41,7 @@ import org.codehaus.jackson.JsonParseExc import org.codehaus.jackson.JsonParser; import org.codehaus.jackson.JsonGenerator; import org.codehaus.jackson.map.ObjectMapper; +import org.codehaus.jackson.node.DoubleNode; /** An abstract data type. *

A schema may be one of: @@ -443,14 +444,19 @@ public abstract class Schema { Field that = (Field) other; return (name.equals(that.name)) && (schema.equals(that.schema)) && - (defaultValue == null - ? that.defaultValue == null - : (defaultValue.equals(that.defaultValue))) && - (order.equals(that.order)) && + defaultValueEquals(that.defaultValue) && props.equals(that.props); } public int hashCode() { return name.hashCode() + schema.computeHash(); } + private boolean defaultValueEquals(JsonNode thatDefaultValue) { + if (defaultValue == null) + return thatDefaultValue == null; + if (Double.isNaN(defaultValue.getValueAsDouble())) + return Double.isNaN(thatDefaultValue.getValueAsDouble()); + return defaultValue.equals(thatDefaultValue); + } + @Override public String toString() { return name + " type:" + schema.type + " pos:" + position; @@ -1137,8 +1143,15 @@ public abstract class Schema { JsonNode orderNode = field.get("order"); if (orderNode != null) order = Field.Order.valueOf(orderNode.getTextValue().toUpperCase()); + JsonNode defaultValue = field.get("default"); + if (defaultValue != null + && (Type.FLOAT.equals(fieldSchema.getType()) + || Type.DOUBLE.equals(fieldSchema.getType())) + && defaultValue.isTextual()) + defaultValue = + new DoubleNode(Double.valueOf(defaultValue.getTextValue())); Field f = new Field(fieldName, fieldSchema, - fieldDoc, field.get("default"), order); + fieldDoc, defaultValue, order); Iterator i = field.getFieldNames(); while (i.hasNext()) { // add field props String prop = i.next(); Modified: avro/trunk/lang/java/compiler/src/main/javacc/org/apache/avro/compiler/idl/idl.jj URL: http://svn.apache.org/viewvc/avro/trunk/lang/java/compiler/src/main/javacc/org/apache/avro/compiler/idl/idl.jj?rev=1212611&r1=1212610&r2=1212611&view=diff ============================================================================== --- avro/trunk/lang/java/compiler/src/main/javacc/org/apache/avro/compiler/idl/idl.jj (original) +++ avro/trunk/lang/java/compiler/src/main/javacc/org/apache/avro/compiler/idl/idl.jj Fri Dec 9 20:27:29 2011 @@ -228,7 +228,8 @@ TOKEN : | < FLOATING_POINT_LITERAL: ("-")? - ( | ) + ( "NaN" | "Infinity" | + | ) > | < #DECIMAL_FLOATING_POINT_LITERAL: Modified: avro/trunk/lang/java/compiler/src/test/idl/input/simple.avdl URL: http://svn.apache.org/viewvc/avro/trunk/lang/java/compiler/src/test/idl/input/simple.avdl?rev=1212611&r1=1212610&r2=1212611&view=diff ============================================================================== --- avro/trunk/lang/java/compiler/src/test/idl/input/simple.avdl (original) +++ avro/trunk/lang/java/compiler/src/test/idl/input/simple.avdl Fri Dec 9 20:27:29 2011 @@ -42,6 +42,9 @@ protocol Simple { @foo("bar") MD5 hash; union { MD5, null} @aliases(["hash", "hsh"]) nullableHash; + + double value = NaN; + float average = -Infinity; } error TestError { Modified: avro/trunk/lang/java/compiler/src/test/idl/output/simple.avpr URL: http://svn.apache.org/viewvc/avro/trunk/lang/java/compiler/src/test/idl/output/simple.avpr?rev=1212611&r1=1212610&r2=1212611&view=diff ============================================================================== --- avro/trunk/lang/java/compiler/src/test/idl/output/simple.avpr (original) +++ avro/trunk/lang/java/compiler/src/test/idl/output/simple.avpr Fri Dec 9 20:27:29 2011 @@ -35,6 +35,14 @@ "name" : "nullableHash", "type" : [ "MD5", "null" ], "aliases" : [ "hash", "hsh" ] + }, { + "name" : "value", + "type" : "double", + "default" : "NaN" + }, { + "name" : "average", + "type" : "float", + "default" : "-Infinity" } ] }, { "type" : "error", Modified: avro/trunk/lang/java/ipc/src/test/java/org/apache/avro/TestSchema.java URL: http://svn.apache.org/viewvc/avro/trunk/lang/java/ipc/src/test/java/org/apache/avro/TestSchema.java?rev=1212611&r1=1212610&r2=1212611&view=diff ============================================================================== --- avro/trunk/lang/java/ipc/src/test/java/org/apache/avro/TestSchema.java (original) +++ avro/trunk/lang/java/ipc/src/test/java/org/apache/avro/TestSchema.java Fri Dec 9 20:27:29 2011 @@ -135,6 +135,9 @@ public class TestSchema { assertEquals(Schema.create(Type.FLOAT), Schema.parse("{\"type\":\"float\"}")); check("\"float\"", "1.1", new Float(1.1)); + checkDefault("\"float\"", "\"NaN\"", Float.NaN); + checkDefault("\"float\"", "\"Infinity\"", Float.POSITIVE_INFINITY); + checkDefault("\"float\"", "\"-Infinity\"", Float.NEGATIVE_INFINITY); } @Test @@ -143,6 +146,9 @@ public class TestSchema { assertEquals(Schema.create(Type.DOUBLE), Schema.parse("{\"type\":\"double\"}")); check("\"double\"", "1.2", new Double(1.2)); + checkDefault("\"double\"", "\"NaN\"", Double.NaN); + checkDefault("\"double\"", "\"Infinity\"", Double.POSITIVE_INFINITY); + checkDefault("\"double\"", "\"-Infinity\"", Double.NEGATIVE_INFINITY); } @Test