This is an automated email from the ASF dual-hosted git repository.

dkulp pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/avro.git


The following commit(s) were added to refs/heads/master by this push:
     new 1c679b1  [AVRO-2368] Provide a Field.hasDefaultValue() method to 
determine if a default value it set or not
1c679b1 is described below

commit 1c679b12bab24c315a3547efa0aee1fd7838bbba
Author: Daniel Kulp <[email protected]>
AuthorDate: Fri Apr 5 08:53:24 2019 -0400

    [AVRO-2368] Provide a Field.hasDefaultValue() method to determine if a 
default value it set or not
---
 .../avro/src/main/java/org/apache/avro/Schema.java | 23 +++++++++++-----
 .../java/org/apache/avro/SchemaCompatibility.java  | 32 +++++++++++-----------
 pom.xml                                            |  1 +
 3 files changed, 33 insertions(+), 23 deletions(-)

diff --git a/lang/java/avro/src/main/java/org/apache/avro/Schema.java 
b/lang/java/avro/src/main/java/org/apache/avro/Schema.java
index 0c39b85..374917c 100644
--- a/lang/java/avro/src/main/java/org/apache/avro/Schema.java
+++ b/lang/java/avro/src/main/java/org/apache/avro/Schema.java
@@ -352,7 +352,7 @@ public abstract class Schema extends JsonProperties {
 
   /**
    * Render this as <a href="http://json.org/";>JSON</a>.
-   * 
+   *
    * @param pretty if true, pretty-print JSON.
    */
   public String toString(boolean pretty) {
@@ -542,6 +542,15 @@ public abstract class Schema extends JsonProperties {
       return doc;
     }
 
+    /**
+     * @return true if this Field has a default value set. Can be used to 
determine
+     *         if a "null" return from defaultVal() is due to that being the 
default
+     *         value or just not set.
+     */
+    public boolean hasDefaultValue() {
+      return defaultValue != null;
+    }
+
     JsonNode defaultValue() {
       return defaultValue;
     }
@@ -913,7 +922,7 @@ public abstract class Schema extends JsonProperties {
         f.schema().toJson(names, gen);
         if (f.doc() != null)
           gen.writeStringField("doc", f.doc());
-        if (f.defaultValue() != null) {
+        if (f.hasDefaultValue()) {
           gen.writeFieldName("default");
           gen.writeTree(f.defaultValue());
         }
@@ -1347,7 +1356,7 @@ public abstract class Schema extends JsonProperties {
   /**
    * Constructs a Schema object from JSON schema file <tt>file</tt>. The 
contents
    * of <tt>file</tt> is expected to be in UTF-8 format.
-   * 
+   *
    * @param file The file to read the schema from.
    * @return The freshly built Schema.
    * @throws IOException if there was trouble reading the contents or they are
@@ -1362,7 +1371,7 @@ public abstract class Schema extends JsonProperties {
   /**
    * Constructs a Schema object from JSON schema stream <tt>in</tt>. The 
contents
    * of <tt>in</tt> is expected to be in UTF-8 format.
-   * 
+   *
    * @param in The input stream to read the schema from.
    * @return The freshly built Schema.
    * @throws IOException if there was trouble reading the contents or they are
@@ -1376,7 +1385,7 @@ public abstract class Schema extends JsonProperties {
 
   /**
    * Construct a schema from <a href="http://json.org/";>JSON</a> text.
-   * 
+   *
    * @deprecated use {@link Schema.Parser} instead.
    */
   @Deprecated
@@ -1386,7 +1395,7 @@ public abstract class Schema extends JsonProperties {
 
   /**
    * Construct a schema from <a href="http://json.org/";>JSON</a> text.
-   * 
+   *
    * @param validate true if names should be validated, false if not.
    * @deprecated use {@link Schema.Parser} instead.
    */
@@ -1849,7 +1858,7 @@ public abstract class Schema extends JsonProperties {
   /**
    * No change is permitted on LockableArrayList once lock() has been called on
    * it.
-   * 
+   *
    * @param <E>
    */
 
diff --git 
a/lang/java/avro/src/main/java/org/apache/avro/SchemaCompatibility.java 
b/lang/java/avro/src/main/java/org/apache/avro/SchemaCompatibility.java
index 76e12f1..c576116 100644
--- a/lang/java/avro/src/main/java/org/apache/avro/SchemaCompatibility.java
+++ b/lang/java/avro/src/main/java/org/apache/avro/SchemaCompatibility.java
@@ -52,7 +52,7 @@ public class SchemaCompatibility {
   /**
    * Validates that the provided reader schema can be used to decode avro data
    * written with the provided writer schema.
-   * 
+   *
    * @param reader schema to check.
    * @param writer schema to check.
    * @return a result object identifying any compatibility errors.
@@ -216,7 +216,7 @@ public class SchemaCompatibility {
      * <p>
      * Memoizes the compatibility results.
      * </p>
-     * 
+     *
      * @param referenceToken The equivalent JSON pointer reference token
      *                       representation of the schema node being visited.
      * @param reader         Reader schema to test.
@@ -402,7 +402,7 @@ public class SchemaCompatibility {
           // Reader field does not correspond to any field in the writer 
record schema, so
           // the
           // reader field must have a default value.
-          if (readerField.defaultValue() == null) {
+          if (!readerField.hasDefaultValue()) {
             // reader field has no default value. Check for the enum default 
value
             if (readerField.schema().getType() == Type.ENUM && 
readerField.schema().getEnumDefault() != null) {
               result = result
@@ -543,7 +543,7 @@ public class SchemaCompatibility {
 
     /**
      * Returns a details object representing a compatible schema pair.
-     * 
+     *
      * @return a SchemaCompatibilityDetails object with COMPATIBLE
      *         SchemaCompatibilityType, and no other state.
      */
@@ -554,7 +554,7 @@ public class SchemaCompatibility {
     /**
      * Returns a details object representing a state indicating that recursion 
is in
      * progress.
-     * 
+     *
      * @return a SchemaCompatibilityDetails object with RECURSION_IN_PROGRESS
      *         SchemaCompatibilityType, and no other state.
      */
@@ -565,7 +565,7 @@ public class SchemaCompatibility {
     /**
      * Returns a details object representing an incompatible schema pair, 
including
      * error details.
-     * 
+     *
      * @return a SchemaCompatibilityDetails object with INCOMPATIBLE
      *         SchemaCompatibilityType, and state representing the violating 
part.
      */
@@ -579,7 +579,7 @@ public class SchemaCompatibility {
 
     /**
      * Returns the SchemaCompatibilityType, always non-null.
-     * 
+     *
      * @return a SchemaCompatibilityType instance, always non-null
      */
     public SchemaCompatibilityType getCompatibility() {
@@ -589,7 +589,7 @@ public class SchemaCompatibility {
     /**
      * If the compatibility is INCOMPATIBLE, returns {@link Incompatibility
      * Incompatibilities} found, otherwise an empty list.
-     * 
+     *
      * @return a list of {@link Incompatibility Incompatibilities}, may be 
empty,
      *         never null.
      */
@@ -653,7 +653,7 @@ public class SchemaCompatibility {
 
     /**
      * Returns the SchemaIncompatibilityType.
-     * 
+     *
      * @return a SchemaIncompatibilityType instance.
      */
     public SchemaIncompatibilityType getType() {
@@ -662,7 +662,7 @@ public class SchemaCompatibility {
 
     /**
      * Returns the fragment of the reader schema that failed compatibility 
check.
-     * 
+     *
      * @return a Schema instance (fragment of the reader schema).
      */
     public Schema getReaderFragment() {
@@ -671,7 +671,7 @@ public class SchemaCompatibility {
 
     /**
      * Returns the fragment of the writer schema that failed compatibility 
check.
-     * 
+     *
      * @return a Schema instance (fragment of the writer schema).
      */
     public Schema getWriterFragment() {
@@ -681,7 +681,7 @@ public class SchemaCompatibility {
     /**
      * Returns a human-readable message with more details about what failed. 
Syntax
      * depends on the SchemaIncompatibilityType.
-     * 
+     *
      * @see #getType()
      * @return a String with details about the incompatibility.
      */
@@ -694,7 +694,7 @@ public class SchemaCompatibility {
      * <a 
href="https://tools.ietf.org/html/draft-ietf-appsawg-json-pointer-08";>JSON
      * Pointer</a> describing the node location within the schema's JSON 
document
      * tree where the incompatibility was encountered.
-     * 
+     *
      * @return JSON Pointer encoded as a string.
      */
     public String getLocation() {
@@ -800,7 +800,7 @@ public class SchemaCompatibility {
 
     /**
      * Constructs a new instance.
-     * 
+     *
      * @param result      The result of the compatibility check.
      * @param reader      schema that was validated.
      * @param writer      schema that was validated.
@@ -815,7 +815,7 @@ public class SchemaCompatibility {
 
     /**
      * Gets the type of this result.
-     * 
+     *
      * @return the type of this result.
      */
     public SchemaCompatibilityType getType() {
@@ -825,7 +825,7 @@ public class SchemaCompatibility {
     /**
      * Gets more details about the compatibility, in particular if getType() is
      * INCOMPATIBLE.
-     * 
+     *
      * @return the details of this compatibility check.
      */
     public SchemaCompatibilityResult getResult() {
diff --git a/pom.xml b/pom.xml
index 9754cae..95aee66 100644
--- a/pom.xml
+++ b/pom.xml
@@ -368,6 +368,7 @@
                 <exclude>lang/js/test/mocha.opts</exclude>
                 <exclude>lang/csharp/TestResult.xml</exclude>
                 <exclude>lang/csharp/src/apache/*/obj/**</exclude>
+                <exclude>lang/csharp/**/bin/Release/**/Avro.xml</exclude>
                 <exclude>lang/js/coverage/**</exclude>
                 <!-- text documentation files -->
                 <exclude>CHANGES.txt</exclude>

Reply via email to