avro-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cutt...@apache.org
Subject svn commit: r777718 - in /hadoop/avro/trunk: CHANGES.txt src/java/org/apache/avro/Schema.java src/test/java/org/apache/avro/TestDataFile.java src/test/java/org/apache/avro/TestSchema.java
Date Fri, 22 May 2009 21:31:32 GMT
Author: cutting
Date: Fri May 22 21:31:32 2009
New Revision: 777718

URL: http://svn.apache.org/viewvc?rev=777718&view=rev
Log:
AVRO-22.  When parsing schemas in Java, do not permit anonymous.

Modified:
    hadoop/avro/trunk/CHANGES.txt
    hadoop/avro/trunk/src/java/org/apache/avro/Schema.java
    hadoop/avro/trunk/src/test/java/org/apache/avro/TestDataFile.java
    hadoop/avro/trunk/src/test/java/org/apache/avro/TestSchema.java

Modified: hadoop/avro/trunk/CHANGES.txt
URL: http://svn.apache.org/viewvc/hadoop/avro/trunk/CHANGES.txt?rev=777718&r1=777717&r2=777718&view=diff
==============================================================================
--- hadoop/avro/trunk/CHANGES.txt (original)
+++ hadoop/avro/trunk/CHANGES.txt Fri May 22 21:31:32 2009
@@ -63,3 +63,6 @@
 
     AVRO-12. Fix recursive schemas in Java so that equals() and
     hashCode() do not cause a stack overflow.  (cutting)
+
+    AVRO-22. When parsing schemas in Java, do not permit anonymous.
+    (cutting)

Modified: hadoop/avro/trunk/src/java/org/apache/avro/Schema.java
URL: http://svn.apache.org/viewvc/hadoop/avro/trunk/src/java/org/apache/avro/Schema.java?rev=777718&r1=777717&r2=777718&view=diff
==============================================================================
--- hadoop/avro/trunk/src/java/org/apache/avro/Schema.java (original)
+++ hadoop/avro/trunk/src/java/org/apache/avro/Schema.java Fri May 22 21:31:32 2009
@@ -626,6 +626,8 @@
         name = nameNode != null ? nameNode.getTextValue() : null;
         JsonNode spaceNode = schema.get("namespace");
         space = spaceNode!=null?spaceNode.getTextValue():names.space();
+        if (name == null)
+          throw new SchemaParseException("No name in schema: "+schema);
       }
       if (type.equals("record") || type.equals("error")) { // record
         LinkedHashMap<String,Field> fields = new LinkedHashMap<String,Field>();

Modified: hadoop/avro/trunk/src/test/java/org/apache/avro/TestDataFile.java
URL: http://svn.apache.org/viewvc/hadoop/avro/trunk/src/test/java/org/apache/avro/TestDataFile.java?rev=777718&r1=777717&r2=777718&view=diff
==============================================================================
--- hadoop/avro/trunk/src/test/java/org/apache/avro/TestDataFile.java (original)
+++ hadoop/avro/trunk/src/test/java/org/apache/avro/TestDataFile.java Fri May 22 21:31:32
2009
@@ -46,7 +46,7 @@
   private static final long SEED = System.currentTimeMillis();
 
   private static final String SCHEMA_JSON =
-    "{\"type\": \"record\", \"fields\": ["
+    "{\"type\": \"record\", \"name\": \"Test\", \"fields\": ["
     +"{\"name\":\"stringField\", \"type\":\"string\"},"
     +"{\"name\":\"longField\", \"type\":\"long\"}]}";
   private static final Schema SCHEMA = Schema.parse(SCHEMA_JSON);

Modified: hadoop/avro/trunk/src/test/java/org/apache/avro/TestSchema.java
URL: http://svn.apache.org/viewvc/hadoop/avro/trunk/src/test/java/org/apache/avro/TestSchema.java?rev=777718&r1=777717&r2=777718&view=diff
==============================================================================
--- hadoop/avro/trunk/src/test/java/org/apache/avro/TestSchema.java (original)
+++ hadoop/avro/trunk/src/test/java/org/apache/avro/TestSchema.java Fri May 22 21:31:32 2009
@@ -99,24 +99,25 @@
 
   @Test
   public void testRecord() throws Exception {
-    String recordJson = 
-      "{\"type\":\"record\",\"fields\":[{\"name\":\"f\", \"type\":\"long\"}]}";
+    String recordJson = "{\"type\":\"record\", \"name\":\"Test\", \"fields\":"
+      +"[{\"name\":\"f\", \"type\":\"long\"}]}";
     Schema schema = Schema.parse(recordJson);
     GenericData.Record record = new GenericData.Record(schema);
     record.put("f", 11L);
-    check(recordJson, "{\"f\":11}", record);
+    check(recordJson, "{\"f\":11}", record, false);
   }
 
   @Test
   public void testEnum() throws Exception {
-    check("{\"type\": \"enum\", \"symbols\": [\"A\", \"B\"]}", "\"B\"", "B",
+    check("{\"type\":\"enum\", \"name\":\"Test\","
+          +"\"symbols\": [\"A\", \"B\"]}", "\"B\"", "B",
           false);
   }
 
   @Test
   public void testFixed() throws Exception {
-    check("{\"type\": \"fixed\", \"size\": 1}", "\"a\"",
-          new GenericData.Fixed(new byte[]{(byte)'a'}));
+    check("{\"type\": \"fixed\", \"name\":\"Test\", \"size\": 1}", "\"a\"",
+          new GenericData.Fixed(new byte[]{(byte)'a'}), false);
   }
 
   @Test
@@ -210,12 +211,13 @@
   }
 
   private static final Schema ACTUAL =            // an empty record schema
-    Schema.createRecord(new LinkedHashMap<String,Field>());
+    Schema.parse("{\"type\":\"record\", \"name\":\"Foo\", \"fields\":[]}");
 
   @SuppressWarnings(value="unchecked")
   private static void checkDefault(String schemaJson, String defaultJson,
                                    Object defaultValue) throws Exception {
-    String recordJson = "{\"type\":\"record\",\"fields\":[{\"name\":\"f\", "
+    String recordJson =
+      "{\"type\":\"record\", \"name\":\"Foo\", \"fields\":[{\"name\":\"f\", "
     +"\"type\":"+schemaJson+", "
     +"\"default\":"+defaultJson+"}]}";
     Schema expected = Schema.parse(recordJson);



Mime
View raw message