/** * Called to read a record instance. Overridden to read a pig tuple. */ @Override protected Object readRecord(Object old, Schema expected, ResolvingDecoder in) throws IOException { // find out the order in which we will receive fields from the ResolvingDecoder Field[] readOrderedFields = in.readFieldOrder(); /* create an empty tuple */ Tuple tuple = TupleFactory.getInstance().newTuple(readOrderedFields.length); /* read fields and put in output order in tuple * The ResolvingDecoder figures out the writer schema to reader schema mapping for us */ for (Field f : readOrderedFields) { tuple.set(f.pos(), read(old, f.schema(), in)); } return tuple; }
@Override @SuppressWarnings("unchecked") protected Object readMap(Object old, Schema expected, ResolvingDecoder in) throws IOException { StatefulMap<Utf8, ?> map = (StatefulMap<Utf8, ?>) newMap(old, 0); Map<Utf8, State> tempStates = null; if (readDirtyBits) { tempStates = new HashMap<Utf8, State>(); int size = in.readInt(); for (int j = 0; j < size; j++) { Utf8 key = in.readString(null); State state = State.values()[in.readInt()]; tempStates.put(key, state); } } super.readMap(map, expected, in); map.clearStates(); if (readDirtyBits) { for (Entry<Utf8, State> entry : tempStates.entrySet()) { map.putState(entry.getKey(), entry.getValue()); } } return map; }
/** * Called to read a map instance. Overridden to read a pig map. */ protected Object readMap(Object old, Schema expected, ResolvingDecoder in) throws IOException { Schema eValue = expected.getValueType(); long l = in.readMapStart(); Object map = newMap(old, (int) l); if (l > 0) { do { for (int i = 0; i < l; i++) { addToMap(map, readString(null, AvroStorageUtils.StringSchema, in), read(null, eValue, in)); } } while ((l = in.mapNext()) > 0); } return map; }
@Override @SuppressWarnings("unchecked") public D read(final D reuse, final Decoder in) throws IOException { final ResolvingDecoder resolver = new ByteBufResolvingDecoder(Schema.applyAliases(this.getSchema(), this.getExpected()), this.getExpected(), in); final D result = (D) this.read(reuse, this.getExpected(), resolver); resolver.drain(); return result; }
protected ResolvingDecoder getResolvingDecoder(Decoder decoder) throws IOException { ResolvingDecoder resolvingDecoder = decoderCache.get(decoder); if(resolvingDecoder == null) { resolvingDecoder = new FakeResolvingDecoder(rootSchema, decoder); decoderCache.put(decoder, resolvingDecoder); } return resolvingDecoder; }
/** * Called to read a record instance. Overridden to read a pig tuple. */ @Override protected Object readRecord(Object old, Schema expected, ResolvingDecoder in) throws IOException { /* create an empty tuple */ Tuple tuple = (Tuple) newRecord(old, expected); for (Field f : in.readFieldOrder()) { tuple.append(read(null, f.schema(), in)); } return tuple; }
protected ResolvingDecoder createResolver(Schema writerSchema, Schema readerSchema) throws IOException { return DecoderFactory.get().resolvingDecoder( Schema.applyAliases(writerSchema, readerSchema), readerSchema, null); }
/** Call this whenever appropriate */ public void setResolver(ResolvingDecoder resolver) { this.resolver = resolver; }