Java Code Examples for org.apache.parquet.io.api.Binary#toByteBuffer()
The following examples show how to use
org.apache.parquet.io.api.Binary#toByteBuffer() .
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: NullableFixedByteAlignedReaders.java From Bats with Apache License 2.0 | 6 votes |
@Override protected void readField(long recordsToReadInThisPass) { this.bytebuf = pageReader.pageData; if (usingDictionary) { NullableVarBinaryVector.Mutator mutator = valueVec.getMutator(); Binary currDictValToWrite; for (int i = 0; i < recordsToReadInThisPass; i++) { currDictValToWrite = pageReader.dictionaryValueReader.readBytes(); ByteBuffer buf = currDictValToWrite.toByteBuffer(); mutator.setSafe(valuesReadInCurrentPass + i, buf, buf.position(), currDictValToWrite.length()); } // Set the write Index. The next page that gets read might be a page that does not use dictionary encoding // and we will go into the else condition below. The readField method of the parent class requires the // writer index to be set correctly. int writerIndex = castedBaseVector.getBuffer().writerIndex(); castedBaseVector.getBuffer().setIndex(0, writerIndex + (int) readLength); } else { super.readField(recordsToReadInThisPass); // TODO - replace this with fixed binary type in drill // for now we need to write the lengths of each value int byteLength = dataTypeLengthInBits / 8; for (int i = 0; i < recordsToReadInThisPass; i++) { valueVec.getMutator().setValueLengthSafe(valuesReadInCurrentPass + i, byteLength); } } }
Example 2
Source File: NullableFixedByteAlignedReaders.java From dremio-oss with Apache License 2.0 | 6 votes |
@Override protected void readField(long recordsToReadInThisPass) { this.bytebuf = pageReader.pageData; if (usingDictionary) { Binary currDictValToWrite; for (int i = 0; i < recordsReadInThisIteration; i++){ currDictValToWrite = pageReader.dictionaryValueReader.readBytes(); ByteBuffer buf = currDictValToWrite.toByteBuffer(); valueVec.setSafe(valuesReadInCurrentPass + i, buf, buf.position(), currDictValToWrite.length()); } // Set the write Index. The next page that gets read might be a page that does not use dictionary encoding // and we will go into the else condition below. The readField method of the parent class requires the // writer index to be set correctly. long writerIndex = valueVec.getDataBuffer().writerIndex(); valueVec.getDataBuffer().setInt(0, LargeMemoryUtil.checkedCastToInt(writerIndex + readLength)); } else { super.readField(recordsToReadInThisPass); // TODO - replace this with fixed binary type in Dremio // for now we need to write the lengths of each value int byteLength = dataTypeLengthInBits / 8; for (int i = 0; i < recordsToReadInThisPass; i++) { valueVec.setValueLengthSafe(valuesReadInCurrentPass + i, byteLength); } } }
Example 3
Source File: SparkParquetReaders.java From iceberg with Apache License 2.0 | 5 votes |
@Override public UTF8String read(UTF8String ignored) { Binary binary = column.nextBinary(); ByteBuffer buffer = binary.toByteBuffer(); if (buffer.hasArray()) { return UTF8String.fromBytes( buffer.array(), buffer.arrayOffset() + buffer.position(), buffer.remaining()); } else { return UTF8String.fromBytes(binary.getBytes()); } }
Example 4
Source File: SparkParquetReaders.java From iceberg with Apache License 2.0 | 5 votes |
@Override public UTF8String read(UTF8String ignored) { Binary binary = column.nextBinary(); ByteBuffer buffer = binary.toByteBuffer(); if (buffer.hasArray()) { return UTF8String.fromBytes( buffer.array(), buffer.arrayOffset() + buffer.position(), buffer.remaining()); } else { return UTF8String.fromBytes(binary.getBytes()); } }
Example 5
Source File: FixedLenBytesColumnReader.java From flink with Apache License 2.0 | 5 votes |
private long heapBinaryToLong(Binary binary) { ByteBuffer buffer = binary.toByteBuffer(); byte[] bytes = buffer.array(); int start = buffer.arrayOffset() + buffer.position(); int end = buffer.arrayOffset() + buffer.limit(); long unscaled = 0L; for (int i = start; i < end; i++) { unscaled = (unscaled << 8) | (bytes[i] & 0xff); } int bits = 8 * (end - start); return (unscaled << (64 - bits)) >> (64 - bits); }
Example 6
Source File: NanoTime.java From parquet-mr with Apache License 2.0 | 5 votes |
public static NanoTime fromBinary(Binary bytes) { Preconditions.checkArgument(bytes.length() == 12, "Must be 12 bytes"); ByteBuffer buf = bytes.toByteBuffer(); buf.order(ByteOrder.LITTLE_ENDIAN); long timeOfDayNanos = buf.getLong(); int julianDay = buf.getInt(); return new NanoTime(julianDay, timeOfDayNanos); }
Example 7
Source File: PrimitiveStringifier.java From parquet-mr with Apache License 2.0 | 5 votes |
@Override String stringifyNotNull(Binary value) { ByteBuffer buffer = value.toByteBuffer(); StringBuilder builder = new StringBuilder(2 + buffer.remaining() * 2); builder.append(BINARY_HEXA_PREFIX); for (int i = buffer.position(), n = buffer.limit(); i < n; ++i) { byte b = buffer.get(i); builder.append(digits[(b >>> 4) & 0x0F]); builder.append(digits[b & 0x0F]); } return builder.toString(); }
Example 8
Source File: DecimalUtils.java From parquet-mr with Apache License 2.0 | 5 votes |
public static BigDecimal binaryToDecimal(Binary value, int precision, int scale) { /* * Precision <= 18 checks for the max number of digits for an unscaled long, * else treat with big integer conversion */ if (precision <= 18) { ByteBuffer buffer = value.toByteBuffer(); byte[] bytes = buffer.array(); int start = buffer.arrayOffset() + buffer.position(); int end = buffer.arrayOffset() + buffer.limit(); long unscaled = 0L; int i = start; while ( i < end ) { unscaled = ( unscaled << 8 | bytes[i] & 0xff ); i++; } int bits = 8*(end - start); long unscaledNew = (unscaled << (64 - bits)) >> (64 - bits); if (unscaledNew <= -pow(10,18) || unscaledNew >= pow(10,18)) { return new BigDecimal(unscaledNew); } else { return BigDecimal.valueOf(unscaledNew / pow(10,scale)); } } else { return new BigDecimal(new BigInteger(value.getBytes()), scale); } }
Example 9
Source File: ParquetConverter.java From pentaho-hadoop-shims with Apache License 2.0 | 5 votes |
static BigDecimal binaryToDecimal( Binary value, int precision, int scale ) { /* * Precision <= 18 checks for the max number of digits for an unscaled long, * else treat with big integer conversion */ if ( precision <= 18 ) { ByteBuffer buffer = value.toByteBuffer(); byte[] bytes = buffer.array(); int start = buffer.arrayOffset() + buffer.position(); int end = buffer.arrayOffset() + buffer.limit(); long unscaled = 0L; int i = start; while ( i < end ) { unscaled = ( unscaled << 8 | bytes[ i ] & 0xff ); i++; } int bits = 8 * ( end - start ); long unscaledNew = ( unscaled << ( 64 - bits ) ) >> ( 64 - bits ); if ( unscaledNew <= -pow( 10, 18 ) || unscaledNew >= pow( 10, 18 ) ) { return new BigDecimal( unscaledNew ); } else { return BigDecimal.valueOf( unscaledNew / pow( 10, scale ) ); } } else { return new BigDecimal( new BigInteger( value.getBytes() ), scale ); } }
Example 10
Source File: BinaryColumnIndexBuilder.java From parquet-mr with Apache License 2.0 | 4 votes |
private static ByteBuffer convert(Binary value) { return value.toByteBuffer(); }