avro-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cutt...@apache.org
Subject svn commit: r1141678 - in /avro/branches/branch-1.5: ./ 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:25:10 GMT
Author: cutting
Date: Thu Jun 30 19:25:09 2011
New Revision: 1141678

URL: http://svn.apache.org/viewvc?rev=1141678&view=rev
Log:
Merge -c 1141677 from trunk to 1.5 branch. Fixes: AVRO-838.

Modified:
    avro/branches/branch-1.5/   (props changed)
    avro/branches/branch-1.5/CHANGES.txt
    avro/branches/branch-1.5/lang/java/avro/src/main/java/org/apache/avro/Schema.java
    avro/branches/branch-1.5/lang/java/avro/src/main/java/org/apache/avro/file/DataFileStream.java
    avro/branches/branch-1.5/lang/java/ipc/src/test/java/org/apache/avro/TestSchema.java

Propchange: avro/branches/branch-1.5/
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Thu Jun 30 19:25:09 2011
@@ -1 +1 @@
-/avro/trunk:1075938,1075993,1078917,1079055,1079060,1079063,1083246,1085921,1086727,1086730,1086866,1087076,1087129,1087136,1087439-1087440,1087463,1087472,1087792,1089128,1089131,1089550,1094812,1095206-1095208,1095493,1095529,1095548,1095550,1096798,1097916,1097927,1097968,1097974,1099257,1102332,1102335,1124127,1124971,1129053,1129071,1129697-1129706,1129729,1130503,1136342
+/avro/trunk:1075938,1075993,1078917,1079055,1079060,1079063,1083246,1085921,1086727,1086730,1086866,1087076,1087129,1087136,1087439-1087440,1087463,1087472,1087792,1089128,1089131,1089550,1094812,1095206-1095208,1095493,1095529,1095548,1095550,1096798,1097916,1097927,1097968,1097974,1099257,1102332,1102335,1124127,1124971,1129053,1129071,1129697-1129706,1129729,1130503,1136342,1141677

Modified: avro/branches/branch-1.5/CHANGES.txt
URL: http://svn.apache.org/viewvc/avro/branches/branch-1.5/CHANGES.txt?rev=1141678&r1=1141677&r2=1141678&view=diff
==============================================================================
--- avro/branches/branch-1.5/CHANGES.txt (original)
+++ avro/branches/branch-1.5/CHANGES.txt Thu Jun 30 19:25:09 2011
@@ -26,6 +26,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/branches/branch-1.5/lang/java/avro/src/main/java/org/apache/avro/Schema.java
URL: http://svn.apache.org/viewvc/avro/branches/branch-1.5/lang/java/avro/src/main/java/org/apache/avro/Schema.java?rev=1141678&r1=1141677&r2=1141678&view=diff
==============================================================================
--- avro/branches/branch-1.5/lang/java/avro/src/main/java/org/apache/avro/Schema.java (original)
+++ avro/branches/branch-1.5/lang/java/avro/src/main/java/org/apache/avro/Schema.java Thu
Jun 30 19:25:09 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/branches/branch-1.5/lang/java/avro/src/main/java/org/apache/avro/file/DataFileStream.java
URL: http://svn.apache.org/viewvc/avro/branches/branch-1.5/lang/java/avro/src/main/java/org/apache/avro/file/DataFileStream.java?rev=1141678&r1=1141677&r2=1141678&view=diff
==============================================================================
--- avro/branches/branch-1.5/lang/java/avro/src/main/java/org/apache/avro/file/DataFileStream.java
(original)
+++ avro/branches/branch-1.5/lang/java/avro/src/main/java/org/apache/avro/file/DataFileStream.java
Thu Jun 30 19:25:09 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/branches/branch-1.5/lang/java/ipc/src/test/java/org/apache/avro/TestSchema.java
URL: http://svn.apache.org/viewvc/avro/branches/branch-1.5/lang/java/ipc/src/test/java/org/apache/avro/TestSchema.java?rev=1141678&r1=1141677&r2=1141678&view=diff
==============================================================================
--- avro/branches/branch-1.5/lang/java/ipc/src/test/java/org/apache/avro/TestSchema.java (original)
+++ avro/branches/branch-1.5/lang/java/ipc/src/test/java/org/apache/avro/TestSchema.java Thu
Jun 30 19:25:09 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