Skip to content

Commit

Permalink
Merge r935526 from trunk to 1.3 branch. Fixes: AVRO-517.
Browse files Browse the repository at this point in the history
git-svn-id: https://svn.apache.org/repos/asf/avro/branches/branch-1.3@951211 13f79535-47bb-0310-9956-ffa450edef68
  • Loading branch information
cutting committed Jun 3, 2010
1 parent c6564e1 commit 4e7eafa
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 1 deletion.
2 changes: 2 additions & 0 deletions CHANGES.txt
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ Avro 1.3.3 (Unreleased)
AVRO-548. Python client should handle CLIENT handshake match status
correctly. (hammer)

AVRO-517. Resolving Decoder fails in some cases. (thiru)

Avro 1.3.2 (31 March 2010)

IMPROVEMENTS
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,10 @@ public D read(D reuse, Decoder in) throws IOException {
if (resolver == null) {
resolver = ResolvingDecoder.resolve(actual, expected);
}
return (D) read(reuse, expected, new ResolvingDecoder(resolver, in));
ResolvingDecoder r = new ResolvingDecoder(resolver, in);
D result = (D) read(reuse, expected, r);
r.drain();
return result;
}

/** Called to read data.*/
Expand Down
19 changes: 19 additions & 0 deletions lang/java/src/java/org/apache/avro/io/ResolvingDecoder.java
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,25 @@ public final Schema.Field[] readFieldOrder() throws IOException {
return ((Symbol.FieldOrderAction) parser.advance(Symbol.FIELD_ACTION)).
fields;
}

/**
* Consume any more data that has been written by the writer but not
* needed by the reader so that the the underlying decoder is in proper
* shape for the next record. This situation happens when, for example,
* the writer writes a record with two fields and the reader needs only the
* first field.
*
* This function should be called after completely decoding an object but
* before next object can be decoded from the same underlying decoder
* either directly or through another resolving decoder. If the same resolving
* decoder is used for the next object as well, calling this method is
* optional; the state of this resolving decoder ensures that any leftover
* portions are consumed before the next object is decoded.
* @throws IOException
*/
public final void drain() throws IOException {
parser.processImplicitActions();
}

@Override
public long readLong() throws IOException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,16 @@ public static Collection<Object[]> data3() {
private static Object[][] dataForResolvingTests() {
// The mnemonics are the same as {@link TestValidatingIO#testSchemas}
return new Object[][] {
// Projection
{ "{\"type\":\"record\",\"name\":\"r\",\"fields\":["
+ "{\"name\":\"f1\", \"type\":\"string\"},"
+ "{\"name\":\"f2\", \"type\":\"string\"},"
+ "{\"name\":\"f3\", \"type\":\"int\"}]}", "S10S10IS10S10I",
new Object[] { "s1", "s2", 100, "t1", "t2", 200 },
"{\"type\":\"record\",\"name\":\"r\",\"fields\":["
+ "{\"name\":\"f1\", \"type\":\"string\" },"
+ "{\"name\":\"f2\", \"type\":\"string\"}]}", "RS10S10RS10S10",
new Object[] { "s1", "s2", "t1", "t2" } },
// Reordered fields
{ "{\"type\":\"record\",\"name\":\"r\",\"fields\":["
+ "{\"name\":\"f1\", \"type\":\"int\"},"
Expand Down

0 comments on commit 4e7eafa

Please sign in to comment.