Java Code Examples for org.apache.avro.io.Decoder#mapNext()

The following examples show how to use org.apache.avro.io.Decoder#mapNext() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SparkValueReaders.java    From iceberg with Apache License 2.0 6 votes vote down vote up
@Override
public ArrayBasedMapData read(Decoder decoder, Object reuse) throws IOException {
  reusedKeyList.clear();
  reusedValueList.clear();

  long chunkLength = decoder.readMapStart();

  while (chunkLength > 0) {
    for (int i = 0; i < chunkLength; i += 1) {
      reusedKeyList.add(keyReader.read(decoder, null));
      reusedValueList.add(valueReader.read(decoder, null));
    }

    chunkLength = decoder.mapNext();
  }

  return new ArrayBasedMapData(
      new GenericArrayData(reusedKeyList.toArray()),
      new GenericArrayData(reusedValueList.toArray()));
}
 
Example 2
Source File: SparkValueReaders.java    From iceberg with Apache License 2.0 6 votes vote down vote up
@Override
public ArrayBasedMapData read(Decoder decoder, Object reuse) throws IOException {
  reusedKeyList.clear();
  reusedValueList.clear();

  long chunkLength = decoder.readMapStart();

  while (chunkLength > 0) {
    for (int i = 0; i < chunkLength; i += 1) {
      reusedKeyList.add(keyReader.read(decoder, null));
      reusedValueList.add(valueReader.read(decoder, null));
    }

    chunkLength = decoder.mapNext();
  }

  return new ArrayBasedMapData(
      new GenericArrayData(reusedKeyList.toArray()),
      new GenericArrayData(reusedValueList.toArray()));
}
 
Example 3
Source File: Map_of_UNION_GenericDeserializer_2087096002965517991_2087096002965517991.java    From avro-util with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public Map<Utf8, IndexedRecord> deserialize(Map<Utf8, IndexedRecord> reuse, Decoder decoder)
    throws IOException
{
    Map<Utf8, IndexedRecord> map0 = null;
    long chunkLen0 = (decoder.readMapStart());
    if (chunkLen0 > 0) {
        Map<Utf8, IndexedRecord> mapReuse0 = null;
        if ((reuse) instanceof Map) {
            mapReuse0 = ((Map)(reuse));
        }
        if (mapReuse0 != (null)) {
            mapReuse0 .clear();
            map0 = mapReuse0;
        } else {
            map0 = new HashMap<Utf8, IndexedRecord>();
        }
        do {
            for (int counter0 = 0; (counter0 <chunkLen0); counter0 ++) {
                Utf8 key0 = (decoder.readString(null));
                int unionIndex0 = (decoder.readIndex());
                if (unionIndex0 == 0) {
                    decoder.readNull();
                }
                if (unionIndex0 == 1) {
                    map0 .put(key0, deserializerecord0(null, (decoder)));
                }
            }
            chunkLen0 = (decoder.mapNext());
        } while (chunkLen0 > 0);
    } else {
        map0 = Collections.emptyMap();
    }
    return map0;
}
 
Example 4
Source File: Map_of_record_GenericDeserializer_2141121767969292399_2141121767969292399.java    From avro-util with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public Map<Utf8, IndexedRecord> deserialize(Map<Utf8, IndexedRecord> reuse, Decoder decoder)
    throws IOException
{
    Map<Utf8, IndexedRecord> map0 = null;
    long chunkLen0 = (decoder.readMapStart());
    if (chunkLen0 > 0) {
        Map<Utf8, IndexedRecord> mapReuse0 = null;
        if ((reuse) instanceof Map) {
            mapReuse0 = ((Map)(reuse));
        }
        if (mapReuse0 != (null)) {
            mapReuse0 .clear();
            map0 = mapReuse0;
        } else {
            map0 = new HashMap<Utf8, IndexedRecord>();
        }
        do {
            for (int counter0 = 0; (counter0 <chunkLen0); counter0 ++) {
                Utf8 key0 = (decoder.readString(null));
                map0 .put(key0, deserializerecord0(null, (decoder)));
            }
            chunkLen0 = (decoder.mapNext());
        } while (chunkLen0 > 0);
    } else {
        map0 = Collections.emptyMap();
    }
    return map0;
}
 
Example 5
Source File: Map_of_UNION_GenericDeserializer_2087096002965517991_2087096002965517991.java    From avro-util with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public Map<Utf8, IndexedRecord> deserialize(Map<Utf8, IndexedRecord> reuse, Decoder decoder)
    throws IOException
{
    Map<Utf8, IndexedRecord> map0 = null;
    long chunkLen0 = (decoder.readMapStart());
    if (chunkLen0 > 0) {
        Map<Utf8, IndexedRecord> mapReuse0 = null;
        if ((reuse) instanceof Map) {
            mapReuse0 = ((Map)(reuse));
        }
        if (mapReuse0 != (null)) {
            mapReuse0 .clear();
            map0 = mapReuse0;
        } else {
            map0 = new HashMap<Utf8, IndexedRecord>();
        }
        do {
            for (int counter0 = 0; (counter0 <chunkLen0); counter0 ++) {
                Utf8 key0 = (decoder.readString(null));
                int unionIndex0 = (decoder.readIndex());
                if (unionIndex0 == 0) {
                    decoder.readNull();
                }
                if (unionIndex0 == 1) {
                    map0 .put(key0, deserializerecord0(null, (decoder)));
                }
            }
            chunkLen0 = (decoder.mapNext());
        } while (chunkLen0 > 0);
    } else {
        map0 = Collections.emptyMap();
    }
    return map0;
}
 
Example 6
Source File: Map_of_record_GenericDeserializer_2141121767969292399_2141121767969292399.java    From avro-util with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public Map<Utf8, IndexedRecord> deserialize(Map<Utf8, IndexedRecord> reuse, Decoder decoder)
    throws IOException
{
    Map<Utf8, IndexedRecord> map0 = null;
    long chunkLen0 = (decoder.readMapStart());
    if (chunkLen0 > 0) {
        Map<Utf8, IndexedRecord> mapReuse0 = null;
        if ((reuse) instanceof Map) {
            mapReuse0 = ((Map)(reuse));
        }
        if (mapReuse0 != (null)) {
            mapReuse0 .clear();
            map0 = mapReuse0;
        } else {
            map0 = new HashMap<Utf8, IndexedRecord>();
        }
        do {
            for (int counter0 = 0; (counter0 <chunkLen0); counter0 ++) {
                Utf8 key0 = (decoder.readString(null));
                map0 .put(key0, deserializerecord0(null, (decoder)));
            }
            chunkLen0 = (decoder.mapNext());
        } while (chunkLen0 > 0);
    } else {
        map0 = Collections.emptyMap();
    }
    return map0;
}
 
Example 7
Source File: Map_of_UNION_GenericDeserializer_2087096002965517991_2087096002965517991.java    From avro-util with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public Map<Utf8, IndexedRecord> deserialize(Map<Utf8, IndexedRecord> reuse, Decoder decoder)
    throws IOException
{
    Map<Utf8, IndexedRecord> map0 = null;
    long chunkLen0 = (decoder.readMapStart());
    if (chunkLen0 > 0) {
        Map<Utf8, IndexedRecord> mapReuse0 = null;
        if ((reuse) instanceof Map) {
            mapReuse0 = ((Map)(reuse));
        }
        if (mapReuse0 != (null)) {
            mapReuse0 .clear();
            map0 = mapReuse0;
        } else {
            map0 = new HashMap<Utf8, IndexedRecord>();
        }
        do {
            for (int counter0 = 0; (counter0 <chunkLen0); counter0 ++) {
                Utf8 key0 = (decoder.readString(null));
                int unionIndex0 = (decoder.readIndex());
                if (unionIndex0 == 0) {
                    decoder.readNull();
                }
                if (unionIndex0 == 1) {
                    map0 .put(key0, deserializerecord0(null, (decoder)));
                }
            }
            chunkLen0 = (decoder.mapNext());
        } while (chunkLen0 > 0);
    } else {
        map0 = Collections.emptyMap();
    }
    return map0;
}
 
Example 8
Source File: Map_of_record_GenericDeserializer_2141121767969292399_2141121767969292399.java    From avro-util with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public Map<Utf8, IndexedRecord> deserialize(Map<Utf8, IndexedRecord> reuse, Decoder decoder)
    throws IOException
{
    Map<Utf8, IndexedRecord> map0 = null;
    long chunkLen0 = (decoder.readMapStart());
    if (chunkLen0 > 0) {
        Map<Utf8, IndexedRecord> mapReuse0 = null;
        if ((reuse) instanceof Map) {
            mapReuse0 = ((Map)(reuse));
        }
        if (mapReuse0 != (null)) {
            mapReuse0 .clear();
            map0 = mapReuse0;
        } else {
            map0 = new HashMap<Utf8, IndexedRecord>();
        }
        do {
            for (int counter0 = 0; (counter0 <chunkLen0); counter0 ++) {
                Utf8 key0 = (decoder.readString(null));
                map0 .put(key0, deserializerecord0(null, (decoder)));
            }
            chunkLen0 = (decoder.mapNext());
        } while (chunkLen0 > 0);
    } else {
        map0 = Collections.emptyMap();
    }
    return map0;
}
 
Example 9
Source File: ValueReaders.java    From iceberg with Apache License 2.0 4 votes vote down vote up
@Override
@SuppressWarnings("unchecked")
public Map<K, V> read(Decoder decoder, Object reuse) throws IOException {
  if (reuse instanceof Map) {
    this.lastMap = (Map<?, ?>) reuse;
  } else {
    this.lastMap = null;
  }

  Map<K, V> resultMap;
  if (lastMap != null) {
    lastMap.clear();
    resultMap = (Map<K, V>) lastMap;
  } else {
    resultMap = Maps.newLinkedHashMap();
  }

  long chunkLength = decoder.readMapStart();
  Iterator<Map.Entry<?, ?>> kvIter = lastMap != null ?
      lastMap.entrySet().iterator() :
      emptyIterator();

  while (chunkLength > 0) {
    for (long i = 0; i < chunkLength; i += 1) {
      K key;
      V value;
      if (kvIter.hasNext()) {
        Map.Entry<?, ?> last = kvIter.next();
        key = keyReader.read(decoder, last.getKey());
        value = valueReader.read(decoder, last.getValue());
      } else {
        key = keyReader.read(decoder, null);
        value = valueReader.read(decoder, null);
      }
      resultMap.put(key, value);
    }

    chunkLength = decoder.mapNext();
  }

  return resultMap;
}
 
Example 10
Source File: ValueReaders.java    From iceberg with Apache License 2.0 4 votes vote down vote up
@Override
@SuppressWarnings("unchecked")
public Map<K, V> read(Decoder decoder, Object reuse) throws IOException {
  if (reuse instanceof Map) {
    this.lastMap = (Map<?, ?>) reuse;
  } else {
    this.lastMap = null;
  }

  Map<K, V> resultMap;
  if (lastMap != null) {
    lastMap.clear();
    resultMap = (Map<K, V>) lastMap;
  } else {
    resultMap = Maps.newLinkedHashMap();
  }

  long chunkLength = decoder.readMapStart();
  Iterator<Map.Entry<?, ?>> kvIter = lastMap != null ?
      lastMap.entrySet().iterator() :
      emptyIterator();

  while (chunkLength > 0) {
    for (long i = 0; i < chunkLength; i += 1) {
      K key;
      V value;
      if (kvIter.hasNext()) {
        Map.Entry<?, ?> last = kvIter.next();
        key = keyReader.read(decoder, last.getKey());
        value = valueReader.read(decoder, last.getValue());
      } else {
        key = keyReader.read(decoder, null);
        value = valueReader.read(decoder, null);
      }
      resultMap.put(key, value);
    }

    chunkLength = decoder.mapNext();
  }

  return resultMap;
}