avro-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cutt...@apache.org
Subject svn commit: r1141677 - in /avro/trunk: CHANGES.txt lang/java/avro/src/main/java/org/apache/avro/Schema.java lang/java/avro/src/main/java/org/apache/avro/file/DataFileStream.java lang/java/ipc/src/test/java/org/apache/avro/TestSchema.java
Date Thu, 30 Jun 2011 19:23:55 GMT
Author: cutting
Date: Thu Jun 30 19:23:55 2011
New Revision: 1141677

URL: http://svn.apache.org/viewvc?rev=1141677&view=rev
Log:
AVRO-838. Java: Permit invalid characters in record and field names of schemas read from data
files, for compatibility with 1.4.

Modified:
    avro/trunk/CHANGES.txt
    avro/trunk/lang/java/avro/src/main/java/org/apache/avro/Schema.java
    avro/trunk/lang/java/avro/src/main/java/org/apache/avro/file/DataFileStream.java
    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=1141677&r1=1141676&r2=1141677&view=diff
==============================================================================
--- avro/trunk/CHANGES.txt (original)
+++ avro/trunk/CHANGES.txt Thu Jun 30 19:23:55 2011
@@ -51,6 +51,10 @@ Avro 1.5.2 (unreleased)
     AVRO-826. C#: Add MD5 and hashcode functions to Protocol.
     (Dona Alvarez via cutting)
 
+    AVRO-838. Java: Permit invalid characters in record and field
+    names of schemas read from data files, for compatibility with
+    1.4. (cutting)
+
   BUG FIXES
 
     AVRO-818. C: Fix data file corruption bug in C library (dcreager)

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=1141677&r1=1141676&r2=1141677&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 Thu Jun 30 19:23:55
2011
@@ -909,6 +909,19 @@ public abstract class Schema {
     return parse(parseJson(jsonSchema), new Names());
   }
 
+  /** Construct a schema from <a href="http://json.org/">JSON</a> text.
+   * @param validate true if names should be validated, false if not.
+   */
+  public static Schema parse(String jsonSchema, boolean validate) {
+    boolean saved = validateNames.get();
+    try {
+      validateNames.set(validate);
+      return parse(jsonSchema);
+    } finally {
+      validateNames.set(saved);
+    }
+  }
+
   static final Map<String,Type> PRIMITIVES = new HashMap<String,Type>();
   static {
     PRIMITIVES.put("string",  Type.STRING);
@@ -956,7 +969,15 @@ public abstract class Schema {
     }
   }
   
+  private static ThreadLocal<Boolean> validateNames
+    = new ThreadLocal<Boolean>() {
+    @Override protected Boolean initialValue() {
+      return true;
+    }
+  };
+    
   private static String validateName(String name) {
+    if (!validateNames.get()) return name;        // not validating names
     int length = name.length();
     if (length == 0)
       throw new SchemaParseException("Empty name");

Modified: avro/trunk/lang/java/avro/src/main/java/org/apache/avro/file/DataFileStream.java
URL: http://svn.apache.org/viewvc/avro/trunk/lang/java/avro/src/main/java/org/apache/avro/file/DataFileStream.java?rev=1141677&r1=1141676&r2=1141677&view=diff
==============================================================================
--- avro/trunk/lang/java/avro/src/main/java/org/apache/avro/file/DataFileStream.java (original)
+++ avro/trunk/lang/java/avro/src/main/java/org/apache/avro/file/DataFileStream.java Thu Jun
30 19:23:55 2011
@@ -121,7 +121,7 @@ public class DataFileStream<D> implement
     
     // finalize the header
     header.metaKeyList = Collections.unmodifiableList(header.metaKeyList);
-    header.schema = Schema.parse(getMetaString(DataFileConstants.SCHEMA));
+    header.schema = Schema.parse(getMetaString(DataFileConstants.SCHEMA),false);
     this.codec = resolveCodec();
     reader.setSchema(header.schema);
   }

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=1141677&r1=1141676&r2=1141677&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 Thu Jun 30 19:23:55
2011
@@ -210,6 +210,12 @@ public class TestSchema {
                     +"{\"name\":\"f.g\",\"type\":\"int\"}]}");
   }
 
+  @Test public void testInvalidNameTolerance() {
+    Schema.parse("{\"type\":\"record\",\"name\":\"1X\",\"fields\":[]}", false);
+    Schema.parse("{\"type\":\"record\",\"name\":\"X-\",\"fields\":[]}", false);
+    Schema.parse("{\"type\":\"record\",\"name\":\"X$\",\"fields\":[]}", false);
+  }
+
   @Test
   public void testMapInRecord() throws Exception {
     String json = "{\"type\":\"record\", \"name\":\"Test\", \"fields\":"



Mime
View raw message