Java Code Examples for parquet.io.api.Binary#getBytes()

The following examples show how to use parquet.io.api.Binary#getBytes() . 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: ParquetConverter.java    From pentaho-hadoop-shims with Apache License 2.0 6 votes vote down vote up
private static long dateFromInt96( Binary value ) {
  byte[] readBuffer = value.getBytes();
  if ( readBuffer.length != 12 ) {
    throw new RuntimeException( "Invalid byte array length for INT96" );
  }

  long timeOfDayNanos =
    ( ( (long) readBuffer[ 7 ] << 56 ) + ( (long) ( readBuffer[ 6 ] & 255 ) << 48 )
      + ( (long) ( readBuffer[ 5 ] & 255 ) << 40 ) + ( (long) ( readBuffer[ 4 ] & 255 ) << 32 )
      + ( (long) ( readBuffer[ 3 ] & 255 ) << 24 ) + ( ( readBuffer[ 2 ] & 255 ) << 16 )
      + ( ( readBuffer[ 1 ] & 255 ) << 8 ) + ( readBuffer[ 0 ] & 255 ) );

  int julianDay =
    ( (int) ( readBuffer[ 11 ] & 255 ) << 24 ) + ( ( readBuffer[ 10 ] & 255 ) << 16 )
      + ( ( readBuffer[ 9 ] & 255 ) << 8 ) + ( readBuffer[ 8 ] & 255 );

  return ( julianDay - ParquetSpec.JULIAN_DAY_OF_EPOCH ) * 24L * 60L * 60L * 1000L + timeOfDayNanos / 1000000;
}
 
Example 2
Source File: SimpleRecordConverter.java    From parquet-tools with Apache License 2.0 6 votes vote down vote up
@Override
public void addBinary(Binary value) {
  byte[] data = value.getBytes();
  if (data == null) {
    record.add(name, null);
    return;
  }

  if (data != null) {
    try {
      CharBuffer buffer = UTF8_DECODER.decode(value.toByteBuffer());
      record.add(name, buffer.toString());
      return;
    } catch (Throwable th) {
    }
  }

  record.add(name, value.getBytes());
}
 
Example 3
Source File: ParquetConverter.java    From pentaho-hadoop-shims with Apache License 2.0 5 votes vote down vote up
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 4
Source File: DumpCommand.java    From parquet-tools with Apache License 2.0 5 votes vote down vote up
public static String binaryToString(Binary value) {
    byte[] data = value.getBytes();
    if (data == null) return null;

    try {
        CharBuffer buffer = UTF8_DECODER.decode(value.toByteBuffer());
        return buffer.toString();
    } catch (Throwable th) {
    }

    return "<bytes...>";
}
 
Example 5
Source File: DumpCommand.java    From parquet-tools with Apache License 2.0 4 votes vote down vote up
public static BigInteger binaryToBigInteger(Binary value) {
    byte[] data = value.getBytes();
    if (data == null) return null;

    return new BigInteger(data);
}