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

The following examples show how to use org.apache.avro.io.Decoder#arrayNext() . 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: Array_of_BOOLEAN_GenericDeserializer_5988037297456147388_5988037297456147388.java    From avro-util with BSD 2-Clause "Simplified" License 6 votes vote down vote up
public List<Boolean> deserialize(List<Boolean> reuse, Decoder decoder)
    throws IOException
{
    PrimitiveBooleanList array0 = null;
    long chunkLen0 = (decoder.readArrayStart());
    if (chunkLen0 > 0) {
        if ((reuse) instanceof PrimitiveBooleanList) {
            array0 = ((PrimitiveBooleanList)(reuse));
            array0 .clear();
        } else {
            array0 = new PrimitiveBooleanArrayList(((int) chunkLen0));
        }
        do {
            for (int counter0 = 0; (counter0 <chunkLen0); counter0 ++) {
                array0 .addPrimitive((decoder.readBoolean()));
            }
            chunkLen0 = (decoder.arrayNext());
        } while (chunkLen0 > 0);
    } else {
        array0 = new PrimitiveBooleanArrayList(((int) chunkLen0));
    }
    return array0;
}
 
Example 2
Source File: Array_of_LONG_GenericDeserializer_2055015354772118358_2055015354772118358.java    From avro-util with BSD 2-Clause "Simplified" License 6 votes vote down vote up
public List<Long> deserialize(List<Long> reuse, Decoder decoder)
    throws IOException
{
    PrimitiveLongList array0 = null;
    long chunkLen0 = (decoder.readArrayStart());
    if (chunkLen0 > 0) {
        if ((reuse) instanceof PrimitiveLongList) {
            array0 = ((PrimitiveLongList)(reuse));
            array0 .clear();
        } else {
            array0 = new PrimitiveLongArrayList(((int) chunkLen0));
        }
        do {
            for (int counter0 = 0; (counter0 <chunkLen0); counter0 ++) {
                array0 .addPrimitive((decoder.readLong()));
            }
            chunkLen0 = (decoder.arrayNext());
        } while (chunkLen0 > 0);
    } else {
        array0 = new PrimitiveLongArrayList(((int) chunkLen0));
    }
    return array0;
}
 
Example 3
Source File: Array_of_INT_GenericDeserializer_3343716480540445685_3343716480540445685.java    From avro-util with BSD 2-Clause "Simplified" License 6 votes vote down vote up
public List<Integer> deserialize(List<Integer> reuse, Decoder decoder)
    throws IOException
{
    PrimitiveIntList array0 = null;
    long chunkLen0 = (decoder.readArrayStart());
    if (chunkLen0 > 0) {
        if ((reuse) instanceof PrimitiveIntList) {
            array0 = ((PrimitiveIntList)(reuse));
            array0 .clear();
        } else {
            array0 = new PrimitiveIntArrayList(((int) chunkLen0));
        }
        do {
            for (int counter0 = 0; (counter0 <chunkLen0); counter0 ++) {
                array0 .addPrimitive((decoder.readInt()));
            }
            chunkLen0 = (decoder.arrayNext());
        } while (chunkLen0 > 0);
    } else {
        array0 = new PrimitiveIntArrayList(((int) chunkLen0));
    }
    return array0;
}
 
Example 4
Source File: Array_of_DOUBLE_GenericDeserializer_6064316435611861740_6064316435611861740.java    From avro-util with BSD 2-Clause "Simplified" License 6 votes vote down vote up
public List<Double> deserialize(List<Double> reuse, Decoder decoder)
    throws IOException
{
    PrimitiveDoubleList array0 = null;
    long chunkLen0 = (decoder.readArrayStart());
    if (chunkLen0 > 0) {
        if ((reuse) instanceof PrimitiveDoubleList) {
            array0 = ((PrimitiveDoubleList)(reuse));
            array0 .clear();
        } else {
            array0 = new PrimitiveDoubleArrayList(((int) chunkLen0));
        }
        do {
            for (int counter0 = 0; (counter0 <chunkLen0); counter0 ++) {
                array0 .addPrimitive((decoder.readDouble()));
            }
            chunkLen0 = (decoder.arrayNext());
        } while (chunkLen0 > 0);
    } else {
        array0 = new PrimitiveDoubleArrayList(((int) chunkLen0));
    }
    return array0;
}
 
Example 5
Source File: Array_of_LONG_GenericDeserializer_2055015354772118358_2055015354772118358.java    From avro-util with BSD 2-Clause "Simplified" License 6 votes vote down vote up
public List<Long> deserialize(List<Long> reuse, Decoder decoder)
    throws IOException
{
    PrimitiveLongList array0 = null;
    long chunkLen0 = (decoder.readArrayStart());
    if (chunkLen0 > 0) {
        if ((reuse) instanceof PrimitiveLongList) {
            array0 = ((PrimitiveLongList)(reuse));
            array0 .clear();
        } else {
            array0 = new PrimitiveLongArrayList(((int) chunkLen0));
        }
        do {
            for (int counter0 = 0; (counter0 <chunkLen0); counter0 ++) {
                array0 .addPrimitive((decoder.readLong()));
            }
            chunkLen0 = (decoder.arrayNext());
        } while (chunkLen0 > 0);
    } else {
        array0 = new PrimitiveLongArrayList(((int) chunkLen0));
    }
    return array0;
}
 
Example 6
Source File: Array_of_INT_GenericDeserializer_3343716480540445685_3343716480540445685.java    From avro-util with BSD 2-Clause "Simplified" License 6 votes vote down vote up
public List<Integer> deserialize(List<Integer> reuse, Decoder decoder)
    throws IOException
{
    PrimitiveIntList array0 = null;
    long chunkLen0 = (decoder.readArrayStart());
    if (chunkLen0 > 0) {
        if ((reuse) instanceof PrimitiveIntList) {
            array0 = ((PrimitiveIntList)(reuse));
            array0 .clear();
        } else {
            array0 = new PrimitiveIntArrayList(((int) chunkLen0));
        }
        do {
            for (int counter0 = 0; (counter0 <chunkLen0); counter0 ++) {
                array0 .addPrimitive((decoder.readInt()));
            }
            chunkLen0 = (decoder.arrayNext());
        } while (chunkLen0 > 0);
    } else {
        array0 = new PrimitiveIntArrayList(((int) chunkLen0));
    }
    return array0;
}
 
Example 7
Source File: SparkValueReaders.java    From iceberg with Apache License 2.0 6 votes vote down vote up
@Override
public GenericArrayData read(Decoder decoder, Object reuse) throws IOException {
  reusedList.clear();
  long chunkLength = decoder.readArrayStart();

  while (chunkLength > 0) {
    for (int i = 0; i < chunkLength; i += 1) {
      reusedList.add(elementReader.read(decoder, null));
    }

    chunkLength = decoder.arrayNext();
  }

  // this will convert the list to an array so it is okay to reuse the list
  return new GenericArrayData(reusedList.toArray());
}
 
Example 8
Source File: Array_of_DOUBLE_GenericDeserializer_6064316435611861740_6064316435611861740.java    From avro-util with BSD 2-Clause "Simplified" License 6 votes vote down vote up
public List<Double> deserialize(List<Double> reuse, Decoder decoder)
    throws IOException
{
    PrimitiveDoubleList array0 = null;
    long chunkLen0 = (decoder.readArrayStart());
    if (chunkLen0 > 0) {
        if ((reuse) instanceof PrimitiveDoubleList) {
            array0 = ((PrimitiveDoubleList)(reuse));
            array0 .clear();
        } else {
            array0 = new PrimitiveDoubleArrayList(((int) chunkLen0));
        }
        do {
            for (int counter0 = 0; (counter0 <chunkLen0); counter0 ++) {
                array0 .addPrimitive((decoder.readDouble()));
            }
            chunkLen0 = (decoder.arrayNext());
        } while (chunkLen0 > 0);
    } else {
        array0 = new PrimitiveDoubleArrayList(((int) chunkLen0));
    }
    return array0;
}
 
Example 9
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.readArrayStart();

  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.arrayNext();
  }

  return new ArrayBasedMapData(
      new GenericArrayData(reusedKeyList.toArray()),
      new GenericArrayData(reusedValueList.toArray()));
}
 
Example 10
Source File: ByteBufferBackedPrimitiveFloatList.java    From avro-util with BSD 2-Clause "Simplified" License 6 votes vote down vote up
/**
 * Instantiate (or re-use) and populate a {@link ByteBufferBackedPrimitiveFloatList} from a {@link org.apache.avro.io.Decoder}.
 *
 * N.B.: the caller must ensure the data is of the appropriate type by calling {@link #isFloatArray(Schema)}.
 *
 * @param old old {@link ByteBufferBackedPrimitiveFloatList} to reuse
 * @param in {@link org.apache.avro.io.Decoder} to read new list from
 * @return a {@link ByteBufferBackedPrimitiveFloatList} with data, possibly the old argument reused
 * @throws IOException on io errors
 */
public static Object readPrimitiveFloatArray(Object old, Decoder in) throws IOException {
  long length = in.readArrayStart();
  long totalLength = 0;

  if (length > 0) {
    ByteBufferBackedPrimitiveFloatList array = (ByteBufferBackedPrimitiveFloatList) newPrimitiveFloatArray(old);
    int index = 0;

    do {
      long byteSize = length * FLOAT_SIZE;
      ByteBuffer byteBuffer = array.byteBuffer.allocate(index++, (int)byteSize);
      in.readFixed(byteBuffer.array(), 0, (int)byteSize);
      totalLength += length;
      length = in.arrayNext();
    } while (length > 0);

    array.byteBuffer.setByteBufferCount(index);
    setupElements(array, (int)totalLength);
    return array;
  } else {
    return new ByteBufferBackedPrimitiveFloatList(0);
  }
}
 
Example 11
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.readArrayStart();

  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.arrayNext();
  }

  return new ArrayBasedMapData(
      new GenericArrayData(reusedKeyList.toArray()),
      new GenericArrayData(reusedValueList.toArray()));
}
 
Example 12
Source File: Array_of_UNION_GenericDeserializer_585074122056792963_585074122056792963.java    From avro-util with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public List<IndexedRecord> deserialize(List<IndexedRecord> reuse, Decoder decoder)
    throws IOException
{
    List<IndexedRecord> array0 = null;
    long chunkLen0 = (decoder.readArrayStart());
    if (chunkLen0 > 0) {
        if ((reuse) instanceof List) {
            array0 = ((List)(reuse));
            array0 .clear();
        } else {
            array0 = new org.apache.avro.generic.GenericData.Array<IndexedRecord>(((int) chunkLen0), readerSchema);
        }
        do {
            for (int counter0 = 0; (counter0 <chunkLen0); counter0 ++) {
                Object arrayArrayElementReuseVar0 = null;
                if ((reuse) instanceof GenericArray) {
                    arrayArrayElementReuseVar0 = ((GenericArray)(reuse)).peek();
                }
                int unionIndex0 = (decoder.readIndex());
                if (unionIndex0 == 0) {
                    decoder.readNull();
                }
                if (unionIndex0 == 1) {
                    array0 .add(deserializerecord0(arrayArrayElementReuseVar0, (decoder)));
                }
            }
            chunkLen0 = (decoder.arrayNext());
        } while (chunkLen0 > 0);
    } else {
        array0 = new org.apache.avro.generic.GenericData.Array<IndexedRecord>(((int) chunkLen0), readerSchema);
    }
    return array0;
}
 
Example 13
Source File: Array_of_record_GenericDeserializer_1629046702287533603_1629046702287533603.java    From avro-util with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public List<IndexedRecord> deserialize(List<IndexedRecord> reuse, Decoder decoder)
    throws IOException
{
    List<IndexedRecord> array0 = null;
    long chunkLen0 = (decoder.readArrayStart());
    if (chunkLen0 > 0) {
        if ((reuse) instanceof List) {
            array0 = ((List)(reuse));
            array0 .clear();
        } else {
            array0 = new org.apache.avro.generic.GenericData.Array<IndexedRecord>(((int) chunkLen0), readerSchema);
        }
        do {
            for (int counter0 = 0; (counter0 <chunkLen0); counter0 ++) {
                Object arrayArrayElementReuseVar0 = null;
                if ((reuse) instanceof GenericArray) {
                    arrayArrayElementReuseVar0 = ((GenericArray)(reuse)).peek();
                }
                array0 .add(deserializerecord0(arrayArrayElementReuseVar0, (decoder)));
            }
            chunkLen0 = (decoder.arrayNext());
        } while (chunkLen0 > 0);
    } else {
        array0 = new org.apache.avro.generic.GenericData.Array<IndexedRecord>(((int) chunkLen0), readerSchema);
    }
    return array0;
}
 
Example 14
Source File: Array_of_record_GenericDeserializer_1629046702287533603_1629046702287533603.java    From avro-util with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public List<IndexedRecord> deserialize(List<IndexedRecord> reuse, Decoder decoder)
    throws IOException
{
    List<IndexedRecord> array0 = null;
    long chunkLen0 = (decoder.readArrayStart());
    if (chunkLen0 > 0) {
        if ((reuse) instanceof List) {
            array0 = ((List)(reuse));
            array0 .clear();
        } else {
            array0 = new org.apache.avro.generic.GenericData.Array<IndexedRecord>(((int) chunkLen0), readerSchema);
        }
        do {
            for (int counter0 = 0; (counter0 <chunkLen0); counter0 ++) {
                Object arrayArrayElementReuseVar0 = null;
                if ((reuse) instanceof GenericArray) {
                    arrayArrayElementReuseVar0 = ((GenericArray)(reuse)).peek();
                }
                array0 .add(deserializerecord0(arrayArrayElementReuseVar0, (decoder)));
            }
            chunkLen0 = (decoder.arrayNext());
        } while (chunkLen0 > 0);
    } else {
        array0 = new org.apache.avro.generic.GenericData.Array<IndexedRecord>(((int) chunkLen0), readerSchema);
    }
    return array0;
}
 
Example 15
Source File: Array_of_UNION_GenericDeserializer_585074122056792963_585074122056792963.java    From avro-util with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public List<IndexedRecord> deserialize(List<IndexedRecord> reuse, Decoder decoder)
    throws IOException
{
    List<IndexedRecord> array0 = null;
    long chunkLen0 = (decoder.readArrayStart());
    if (chunkLen0 > 0) {
        if ((reuse) instanceof List) {
            array0 = ((List)(reuse));
            array0 .clear();
        } else {
            array0 = new org.apache.avro.generic.GenericData.Array<IndexedRecord>(((int) chunkLen0), readerSchema);
        }
        do {
            for (int counter0 = 0; (counter0 <chunkLen0); counter0 ++) {
                Object arrayArrayElementReuseVar0 = null;
                if ((reuse) instanceof GenericArray) {
                    arrayArrayElementReuseVar0 = ((GenericArray)(reuse)).peek();
                }
                int unionIndex0 = (decoder.readIndex());
                if (unionIndex0 == 0) {
                    decoder.readNull();
                }
                if (unionIndex0 == 1) {
                    array0 .add(deserializerecord0(arrayArrayElementReuseVar0, (decoder)));
                }
            }
            chunkLen0 = (decoder.arrayNext());
        } while (chunkLen0 > 0);
    } else {
        array0 = new org.apache.avro.generic.GenericData.Array<IndexedRecord>(((int) chunkLen0), readerSchema);
    }
    return array0;
}
 
Example 16
Source File: ValueReaders.java    From iceberg with Apache License 2.0 5 votes vote down vote up
@Override
@SuppressWarnings("unchecked")
public Collection<T> read(Decoder decoder, Object reused) throws IOException {
  LinkedList<T> resultList;
  if (lastList != null) {
    lastList.clear();
    resultList = (LinkedList<T>) lastList;
  } else {
    resultList = Lists.newLinkedList();
  }

  if (reused instanceof LinkedList) {
    this.lastList = (LinkedList<?>) reused;
  } else {
    this.lastList = null;
  }

  long chunkLength = decoder.readArrayStart();
  Iterator<?> elIter = lastList != null ? lastList.iterator() : emptyIterator();

  while (chunkLength > 0) {
    for (long i = 0; i < chunkLength; i += 1) {
      Object lastValue = elIter.hasNext() ? elIter.next() : null;
      resultList.addLast(elementReader.read(decoder, lastValue));
    }

    chunkLength = decoder.arrayNext();
  }

  return resultList;
}
 
Example 17
Source File: ValueReaders.java    From iceberg with Apache License 2.0 5 votes vote down vote up
@Override
@SuppressWarnings("unchecked")
public Collection<T> read(Decoder decoder, Object reused) throws IOException {
  Deque<T> resultList;
  if (lastList != null) {
    lastList.clear();
    resultList = (LinkedList<T>) lastList;
  } else {
    resultList = Lists.newLinkedList();
  }

  if (reused instanceof LinkedList) {
    this.lastList = (LinkedList<?>) reused;
  } else {
    this.lastList = null;
  }

  long chunkLength = decoder.readArrayStart();
  Iterator<?> elIter = lastList != null ? lastList.iterator() : emptyIterator();

  while (chunkLength > 0) {
    for (long i = 0; i < chunkLength; i += 1) {
      Object lastValue = elIter.hasNext() ? elIter.next() : null;
      resultList.addLast(elementReader.read(decoder, lastValue));
    }

    chunkLength = decoder.arrayNext();
  }

  return resultList;
}
 
Example 18
Source File: Array_of_record_GenericDeserializer_1629046702287533603_1629046702287533603.java    From avro-util with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public List<IndexedRecord> deserialize(List<IndexedRecord> reuse, Decoder decoder)
    throws IOException
{
    List<IndexedRecord> array0 = null;
    long chunkLen0 = (decoder.readArrayStart());
    if (chunkLen0 > 0) {
        if ((reuse) instanceof List) {
            array0 = ((List)(reuse));
            array0 .clear();
        } else {
            array0 = new org.apache.avro.generic.GenericData.Array<IndexedRecord>(((int) chunkLen0), readerSchema);
        }
        do {
            for (int counter0 = 0; (counter0 <chunkLen0); counter0 ++) {
                Object arrayArrayElementReuseVar0 = null;
                if ((reuse) instanceof GenericArray) {
                    arrayArrayElementReuseVar0 = ((GenericArray)(reuse)).peek();
                }
                array0 .add(deserializerecord0(arrayArrayElementReuseVar0, (decoder)));
            }
            chunkLen0 = (decoder.arrayNext());
        } while (chunkLen0 > 0);
    } else {
        array0 = new org.apache.avro.generic.GenericData.Array<IndexedRecord>(((int) chunkLen0), readerSchema);
    }
    return array0;
}
 
Example 19
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.readArrayStart();
  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.arrayNext();
  }

  return resultMap;
}
 
Example 20
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.readArrayStart();
  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.arrayNext();
  }

  return resultMap;
}