Top Description Fields Constructors Methods
org.apache.avro.io

public Class ResolvingDecoder

extends ValidatingDecoder
Class Inheritance
Imports
java.io.IOException, java.nio.ByteBuffer, java.nio.charset.StandardCharsets, java.util.Objects, org.apache.avro.AvroTypeException, .Schema, org.apache.avro.io.parsing.ResolvingGrammarGenerator, .Symbol, org.apache.avro.util.Utf8

Decoder that performs type-resolution between the reader's and writer's schemas.

When resolving schemas, this class will return the values of fields in _writer's_ order, not the reader's order. (However, it returns _only_ the reader's fields, not any extra fields the writer may have written.) To help clients handle fields that appear to be coming out of order, this class defines the method readFieldOrder.

See the parser documentation for information on how this works.

Field Summary

Modifier and TypeField and Description
private Decoder
Inherited from org.apache.avro.io.ValidatingDecoder:
in

Constructor Summary

AccessConstructor and Description
pack-priv
ResolvingDecoder(Schema writer, Schema reader, Decoder in)

private
ResolvingDecoder(Object
The resolver to use.
resolver
,
Decoder
The underlying decoder.
in
)

Constructs a ResolvingDecoder using the given resolver.

Method Summary

Modifier and TypeMethod and Description
public Symbol
doAction(Symbol
The input symbol from the caller of advance
input
,
Symbol
The symbol at the top the stack.
top
)

Overrides org.apache.avro.io.ValidatingDecoder.doAction.

Implements org.apache.avro.io.parsing.Parser.ActionHandler.doAction.

Handle the action symbol top when the input is sought to be taken off the stack.
public final void
drain()

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.

public ByteBuffer
public double
public int
readEnum()

Overrides org.apache.avro.io.ValidatingDecoder.readEnum.

Reads an enumeration.
public final Schema.Field[]
readFieldOrder()

Returns the actual order in which the reader's fields will be returned to the reader.

public final Schema.Field[]
readFieldOrderIfDiff()

Same as readFieldOrder except that it returns null if there was no reordering of fields, i.e., if the correct thing for the reader to do is to read (all) of its fields in the order specified by its own schema (useful for optimizations).

public float
public int
readIndex()

Overrides org.apache.avro.io.ValidatingDecoder.readIndex.

Reads the tag of a union written by Encoder#writeIndex.
public long
public Utf8
public String
public static Object

Returns:

The opaque resolver.
resolve
(Schema
The writer's schema. Cannot be null.
writer
,
Schema
The reader's schema. Cannot be null.
reader
)

Produces an opaque resolver that can be used to construct a new ResolvingDecoder#ResolvingDecoder(Object, Decoder).

public void
public void
skipBytes()

Overrides org.apache.avro.io.ValidatingDecoder.skipBytes.

Discards a byte-string written by Encoder#writeBytes.
public void
Inherited from org.apache.avro.io.ValidatingDecoder:
arrayNextconfiguremapNextreadArrayStartreadBooleanreadFixedreadIntreadMapStartreadNullskipArrayskipFixedskipFixedskipMap

Field Detail

backupback to summary
private Decoder backup

Constructor Detail

ResolvingDecoderback to summary
pack-priv ResolvingDecoder(Schema writer, Schema reader, Decoder in) throws IOException
ResolvingDecoderback to summary
private ResolvingDecoder(Object resolver, Decoder in) throws IOException

Constructs a ResolvingDecoder using the given resolver. The resolver must have been returned by a previous call to resolve(Schema, Schema).

Parameters
resolver:Object

The resolver to use.

in:Decoder

The underlying decoder.

Method Detail

doActionback to summary
public Symbol doAction(Symbol input, Symbol top) throws IOException

Overrides org.apache.avro.io.ValidatingDecoder.doAction.

Implements org.apache.avro.io.parsing.Parser.ActionHandler.doAction.

Doc from org.apache.avro.io.parsing.Parser.ActionHandler.doAction.

Handle the action symbol top when the input is sought to be taken off the stack.

Parameters
input:Symbol

The input symbol from the caller of advance

top:Symbol

The symbol at the top the stack.

Returns:Symbol

null if advance() is to continue processing the stack. If not null the return value will be returned by advance().

Annotations
@Override
drainback to summary
public final void drain() throws IOException

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.

readBytesback to summary
public ByteBuffer readBytes(ByteBuffer old) throws IOException

Overrides org.apache.avro.io.ValidatingDecoder.readBytes.

Doc from org.apache.avro.io.Decoder.readBytes.

Reads a byte-string written by Encoder#writeBytes. if old is not null and has sufficient capacity to take in the bytes being read, the bytes are returned in old.

Annotations
@Override
readDoubleback to summary
public double readDouble() throws IOException

Overrides org.apache.avro.io.ValidatingDecoder.readDouble.

Doc from org.apache.avro.io.Decoder.readDouble.

Reads a double written by Encoder#writeDouble.

Annotations
@Override
readEnumback to summary
public int readEnum() throws IOException

Overrides org.apache.avro.io.ValidatingDecoder.readEnum.

Doc from org.apache.avro.io.Decoder.readEnum.

Reads an enumeration.

Returns:int

The enumeration's value.

Annotations
@Override
readFieldOrderback to summary
public final Schema.Field[] readFieldOrder() throws IOException

Returns the actual order in which the reader's fields will be returned to the reader. This method is useful because ResolvingDecoder returns values in the order written by the writer, rather than the order expected by the reader. This method allows readers to figure out what fields to expect. Let's say the reader is expecting a three-field record, the first field is a long, the second a string, and the third an array. In this case, a typical usage might be as follows:

  Schema.Fields[] fieldOrder = in.readFieldOrder();
  for (int i = 0; i < 3; i++) {
    switch (fieldOrder[i].pos()) {
    case 1:
      foo(in.readLong());
      break;
    case 2:
      someVariable = in.readString();
      break;
    case 3:
      bar(in); // The code of "bar" will read an array-of-int
      break;
    }
Note that ResolvingDecoder will return only the fields expected by the reader, not other fields that may have been written by the writer. Thus, the iteration-count of "3" in the above loop will always be correct. Throws a runtime exception if we're not just about to read the first field of a record. (If the client knows the order of incoming fields, then the client does not need to call this method but rather can just start reading the field values.)
Exceptions
AvroTypeException:
If we're not starting a new record
readFieldOrderIfDiffback to summary
public final Schema.Field[] readFieldOrderIfDiff() throws IOException

Same as readFieldOrder except that it returns null if there was no reordering of fields, i.e., if the correct thing for the reader to do is to read (all) of its fields in the order specified by its own schema (useful for optimizations).

readFloatback to summary
public float readFloat() throws IOException

Overrides org.apache.avro.io.ValidatingDecoder.readFloat.

Doc from org.apache.avro.io.Decoder.readFloat.

Reads a float written by Encoder#writeFloat.

Annotations
@Override
readIndexback to summary
public int readIndex() throws IOException

Overrides org.apache.avro.io.ValidatingDecoder.readIndex.

Doc from org.apache.avro.io.Decoder.readIndex.

Reads the tag of a union written by Encoder#writeIndex.

Annotations
@Override
readLongback to summary
public long readLong() throws IOException

Overrides org.apache.avro.io.ValidatingDecoder.readLong.

Doc from org.apache.avro.io.Decoder.readLong.

Reads a long written by Encoder#writeLong.

Annotations
@Override
readStringback to summary
public Utf8 readString(Utf8 old) throws IOException

Overrides org.apache.avro.io.ValidatingDecoder.readString.

Doc from org.apache.avro.io.Decoder.readString.

Reads a char-string written by Encoder#writeString.

Annotations
@Override
readStringback to summary
public String readString() throws IOException

Overrides org.apache.avro.io.ValidatingDecoder.readString.

Doc from org.apache.avro.io.Decoder.readString.

Reads a char-string written by Encoder#writeString.

Annotations
@Override
resolveback to summary
public static Object resolve(Schema writer, Schema reader) throws IOException

Produces an opaque resolver that can be used to construct a new ResolvingDecoder#ResolvingDecoder(Object, Decoder). The returned Object is immutable and hence can be simultaneously used in many ResolvingDecoders. This method is reasonably expensive, the users are encouraged to cache the result.

Parameters
writer:Schema

The writer's schema. Cannot be null.

reader:Schema

The reader's schema. Cannot be null.

Returns:Object

The opaque resolver.

Exceptions
NullPointerException:
if writer or reader is null
skipActionback to summary
public void skipAction() throws IOException

Overrides org.apache.avro.io.ParsingDecoder.skipAction.

Implements org.apache.avro.io.parsing.SkipParser.SkipHandler.skipAction.

Doc from org.apache.avro.io.parsing.SkipParser.SkipHandler.skipAction.

Skips the action at the top of the stack.

Annotations
@Override
skipBytesback to summary
public void skipBytes() throws IOException

Overrides org.apache.avro.io.ValidatingDecoder.skipBytes.

Doc from org.apache.avro.io.Decoder.skipBytes.

Discards a byte-string written by Encoder#writeBytes.

Annotations
@Override
skipStringback to summary
public void skipString() throws IOException

Overrides org.apache.avro.io.ValidatingDecoder.skipString.

Doc from org.apache.avro.io.Decoder.skipString.

Discards a char-string written by Encoder#writeString.

Annotations
@Override