コード例 #1
0
ファイル: UnsafeArrayData.java プロジェクト: nkeywal/spark
 @Override
 public CalendarInterval getInterval(int ordinal) {
   assertIndexIsValid(ordinal);
   final int offset = getElementOffset(ordinal);
   if (offset < 0) return null;
   final int months = (int) PlatformDependent.UNSAFE.getLong(baseObject, baseOffset + offset);
   final long microseconds = PlatformDependent.UNSAFE.getLong(baseObject, baseOffset + offset + 8);
   return new CalendarInterval(months, microseconds);
 }
コード例 #2
0
ファイル: UnsafeArrayData.java プロジェクト: nkeywal/spark
 @Override
 public long getLong(int ordinal) {
   assertIndexIsValid(ordinal);
   final int offset = getElementOffset(ordinal);
   if (offset < 0) return 0;
   return PlatformDependent.UNSAFE.getLong(baseObject, baseOffset + offset);
 }
コード例 #3
0
ファイル: UTF8String.java プロジェクト: rdeepa/spark
 /** Returns a 64-bit integer that can be used as the prefix used in sorting. */
 public long getPrefix() {
   // Since JVMs are either 4-byte aligned or 8-byte aligned, we check the size of the string.
   // If size is 0, just return 0.
   // If size is between 0 and 4 (inclusive), assume data is 4-byte aligned under the hood and
   // use a getInt to fetch the prefix.
   // If size is greater than 4, assume we have at least 8 bytes of data to fetch.
   // After getting the data, we use a mask to mask out data that is not part of the string.
   long p;
   long mask = 0;
   if (byteOrder == ByteOrder.LITTLE_ENDIAN) {
     if (numBytes >= 8) {
       p = PlatformDependent.UNSAFE.getLong(base, offset);
     } else if (numBytes > 4) {
       p = PlatformDependent.UNSAFE.getLong(base, offset);
       mask = (1L << (8 - numBytes) * 8) - 1;
     } else if (numBytes > 0) {
       p = (long) PlatformDependent.UNSAFE.getInt(base, offset);
       mask = (1L << (8 - numBytes) * 8) - 1;
     } else {
       p = 0;
     }
     p = java.lang.Long.reverseBytes(p);
   } else {
     // byteOrder == ByteOrder.BIG_ENDIAN
     if (numBytes >= 8) {
       p = PlatformDependent.UNSAFE.getLong(base, offset);
     } else if (numBytes > 4) {
       p = PlatformDependent.UNSAFE.getLong(base, offset);
       mask = (1L << (8 - numBytes) * 8) - 1;
     } else if (numBytes > 0) {
       p = ((long) PlatformDependent.UNSAFE.getInt(base, offset)) << 32;
       mask = (1L << (8 - numBytes) * 8) - 1;
     } else {
       p = 0;
     }
   }
   p &= ~mask;
   return p;
 }
コード例 #4
0
ファイル: UnsafeArrayData.java プロジェクト: nkeywal/spark
  @Override
  public Decimal getDecimal(int ordinal, int precision, int scale) {
    assertIndexIsValid(ordinal);
    final int offset = getElementOffset(ordinal);
    if (offset < 0) return null;

    if (precision <= Decimal.MAX_LONG_DIGITS()) {
      final long value = PlatformDependent.UNSAFE.getLong(baseObject, baseOffset + offset);
      return Decimal.apply(value, precision, scale);
    } else {
      final byte[] bytes = getBinary(ordinal);
      final BigInteger bigInteger = new BigInteger(bytes);
      final BigDecimal javaDecimal = new BigDecimal(bigInteger, scale);
      return Decimal.apply(new scala.math.BigDecimal(javaDecimal), precision, scale);
    }
  }