Java Code Examples for org.apache.parquet.io.api.Binary#fromConstantByteArray()

The following examples show how to use org.apache.parquet.io.api.Binary#fromConstantByteArray() . 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: DeltaByteArrayReader.java    From parquet-mr with Apache License 2.0 6 votes vote down vote up
@Override
public Binary readBytes() {
  int prefixLength = prefixLengthReader.readInteger();
  // This does not copy bytes
  Binary suffix = suffixReader.readBytes();
  int length = prefixLength + suffix.length();

  // NOTE: due to PARQUET-246, it is important that we
  // respect prefixLength which was read from prefixLengthReader,
  // even for the *first* value of a page. Even though the first
  // value of the page should have an empty prefix, it may not
  // because of PARQUET-246.

  // We have to do this to materialize the output
  if(prefixLength != 0) {
    byte[] out = new byte[length];
    System.arraycopy(previous.getBytesUnsafe(), 0, out, 0, prefixLength);
    System.arraycopy(suffix.getBytesUnsafe(), 0, out, prefixLength, suffix.length());
    previous =  Binary.fromConstantByteArray(out);
  } else {
    previous = suffix;
  }
  return previous;
}
 
Example 2
Source File: FixedBinaryTestUtils.java    From parquet-mr with Apache License 2.0 6 votes vote down vote up
public static Binary getFixedBinary(int length, BigInteger bigInt) {
  byte[] array = bigInt.toByteArray();
  if (array.length == length) {
    return Binary.fromConstantByteArray(array);
  } else if (array.length < length) {
    byte[] padded = new byte[length];
    int paddingLength = length - array.length;
    if (bigInt.signum() < 0) {
      Arrays.fill(padded, 0, paddingLength, (byte) 0xFF);
    } else {
      Arrays.fill(padded, 0, paddingLength, (byte) 0x00);
    }
    System.arraycopy(array, 0, padded, paddingLength, array.length);
    return Binary.fromConstantByteArray(padded);
  } else {
    throw new IllegalArgumentException(
        "Specified BigInteger (" + bigInt + ") is too long for fixed bytes (" + array.length + '>' + length + ')');
  }
}
 
Example 3
Source File: FixedLenBytesColumnReader.java    From flink with Apache License 2.0 5 votes vote down vote up
private Binary readDataBinary(int len) {
	ByteBuffer buffer = readDataBuffer(len);
	if (buffer.hasArray()) {
		return Binary.fromConstantByteArray(
				buffer.array(), buffer.arrayOffset() + buffer.position(), len);
	} else {
		byte[] bytes = new byte[len];
		buffer.get(bytes);
		return Binary.fromConstantByteArray(bytes);
	}
}
 
Example 4
Source File: FixedBinaryTestUtils.java    From parquet-mr with Apache License 2.0 5 votes vote down vote up
public static Binary getFixedBinary(PrimitiveType type, BigInteger bigInt) {
  switch (type.getPrimitiveTypeName()) {
  case FIXED_LEN_BYTE_ARRAY:
    return getFixedBinary(type.getTypeLength(), bigInt);
  case INT96:
    return getFixedBinary(12, bigInt);
  case BINARY:
    return Binary.fromConstantByteArray(bigInt.toByteArray());
  default:
    throw new IllegalArgumentException("Type " + type + " cannot be represented by a Binary");
  }
}
 
Example 5
Source File: TestPrimitiveStringifier.java    From parquet-mr with Apache License 2.0 5 votes vote down vote up
private Binary toBinary(int...bytes) {
  byte[] array = new byte[bytes.length];
  for (int i = 0; i < array.length; ++i) {
    array[i] = (byte) bytes[i];
  }
  return Binary.fromConstantByteArray(array);
}
 
Example 6
Source File: AvroWriteSupport.java    From parquet-mr with Apache License 2.0 5 votes vote down vote up
private Binary fromUUIDString(Object value) {
  byte[] data = new byte[UUIDLogicalTypeAnnotation.BYTES];
  UUID uuid = UUID.fromString(value.toString());
  writeLong(data, 0, uuid.getMostSignificantBits());
  writeLong(data, Long.BYTES, uuid.getLeastSignificantBits());
  return Binary.fromConstantByteArray(data);
}
 
Example 7
Source File: DeltaByteArrayReader.java    From parquet-mr with Apache License 2.0 4 votes vote down vote up
public DeltaByteArrayReader() {
  this.prefixLengthReader = new DeltaBinaryPackingValuesReader();
  this.suffixReader = new DeltaLengthByteArrayValuesReader();
  this.previous = Binary.fromConstantByteArray(new byte[0]);
}
 
Example 8
Source File: TestValuesReaderImpl.java    From parquet-mr with Apache License 2.0 4 votes vote down vote up
@Override
public Binary readBytes() {
  return Binary.fromConstantByteArray(data);
}
 
Example 9
Source File: TestValuesReaderImpl.java    From parquet-mr with Apache License 2.0 4 votes vote down vote up
@Override
public Binary readBytes() {
  return Binary.fromConstantByteArray(data);
}
 
Example 10
Source File: TestColumnIndexBuilder.java    From parquet-mr with Apache License 2.0 4 votes vote down vote up
private static Binary decimalBinary(String num) {
  return Binary.fromConstantByteArray(new BigDecimal(num).unscaledValue().toByteArray());
}
 
Example 11
Source File: BinaryWritable.java    From parquet-mr with Apache License 2.0 4 votes vote down vote up
@Override
public void readFields(DataInput input) throws IOException {
  byte[] bytes = new byte[input.readInt()];
  input.readFully(bytes);
  binary = Binary.fromConstantByteArray(bytes);
}
 
Example 12
Source File: ProtoWriteSupport.java    From parquet-mr with Apache License 2.0 4 votes vote down vote up
@Override
final void writeRawValue(Object value) {
  ByteString byteString = (ByteString) value;
  Binary binary = Binary.fromConstantByteArray(byteString.toByteArray());
  recordConsumer.addBinary(binary);
}