Skip to content

Commit

Permalink
AVRO-1929: Java: SchemaCompatibility fails to recognize string<->byte…
Browse files Browse the repository at this point in the history
…s promotion. Contributed by Anders Sundelin.
  • Loading branch information
cutting committed Oct 6, 2016
1 parent ef0e1a1 commit 0a74e1e
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 5 deletions.
3 changes: 3 additions & 0 deletions CHANGES.txt
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,9 @@ Trunk (not yet released)
AVRO-1860: Java: Field#DefaultVal() returns Ints for Long fields.
(Gabor Szadovszky via cutting)

AVRO-1929: Java: SchemaCompatibility fails to recognize
string<->bytes promotion. (Anders Sundelin via cutting)

Avro 1.8.1 (14 May 2016)

INCOMPATIBLE CHANGES
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -379,8 +379,17 @@ private SchemaCompatibilityType calculateCompatibility(
? SchemaCompatibilityType.COMPATIBLE
: SchemaCompatibilityType.INCOMPATIBLE;
}
case BYTES: return SchemaCompatibilityType.INCOMPATIBLE;
case STRING: return SchemaCompatibilityType.INCOMPATIBLE;
case BYTES: {
return (writer.getType() == Type.STRING)
? SchemaCompatibilityType.COMPATIBLE
: SchemaCompatibilityType.INCOMPATIBLE;
}
case STRING: {
return (writer.getType() == Type.BYTES)
? SchemaCompatibilityType.COMPATIBLE
: SchemaCompatibilityType.INCOMPATIBLE;
}

case ARRAY: return SchemaCompatibilityType.INCOMPATIBLE;
case MAP: return SchemaCompatibilityType.INCOMPATIBLE;
case FIXED: return SchemaCompatibilityType.INCOMPATIBLE;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@
*/
package org.apache.avro;

import static junit.framework.Assert.assertEquals;
import static org.apache.avro.SchemaCompatibility.checkReaderWriterCompatibility;
import static org.junit.Assert.assertEquals;

import java.io.ByteArrayOutputStream;
import java.util.ArrayList;
Expand Down Expand Up @@ -352,6 +352,10 @@ public void testUnionReaderWriterSubsetIncompatibility() {

new ReaderWriter(ENUM1_AB_SCHEMA, ENUM1_AB_SCHEMA),
new ReaderWriter(ENUM1_ABC_SCHEMA, ENUM1_AB_SCHEMA),

// String-to/from-bytes, introduced in Avro 1.7.7
new ReaderWriter(STRING_SCHEMA, BYTES_SCHEMA),
new ReaderWriter(BYTES_SCHEMA, STRING_SCHEMA),

// Tests involving unions:
new ReaderWriter(EMPTY_UNION_SCHEMA, EMPTY_UNION_SCHEMA),
Expand Down Expand Up @@ -412,11 +416,9 @@ public void testUnionReaderWriterSubsetIncompatibility() {

new ReaderWriter(STRING_SCHEMA, BOOLEAN_SCHEMA),
new ReaderWriter(STRING_SCHEMA, INT_SCHEMA),
new ReaderWriter(STRING_SCHEMA, BYTES_SCHEMA),

new ReaderWriter(BYTES_SCHEMA, NULL_SCHEMA),
new ReaderWriter(BYTES_SCHEMA, INT_SCHEMA),
new ReaderWriter(BYTES_SCHEMA, STRING_SCHEMA),

new ReaderWriter(INT_ARRAY_SCHEMA, LONG_ARRAY_SCHEMA),
new ReaderWriter(INT_MAP_SCHEMA, INT_ARRAY_SCHEMA),
Expand Down

0 comments on commit 0a74e1e

Please sign in to comment.