Java Code Examples for org.apache.spark.sql.types.Decimal#apply()

The following examples show how to use org.apache.spark.sql.types.Decimal#apply() . These examples are extracted from open source projects. 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
@Override
final Decimal getDecimal(int rowId, int precision, int scale) {
  if (isNullAt(rowId)) {
    return null;
  }
  return Decimal.apply(accessor.getObject(rowId), precision, scale);
}
 
Example 2
Source Project: iceberg   File: ArrowVectorAccessors.java    License: Apache License 2.0 5 votes vote down vote up
@Override
final Decimal getDecimal(int rowId, int precision, int scale) {
  int dictId = offsetVector.get(rowId);
  if (cache[dictId] == null) {
    cache[dictId] = Decimal.apply(
        new BigInteger(parquetDictionary.decodeToBinary(dictId).getBytes()).longValue(),
        precision,
        scale);
  }
  return cache[dictId];
}
 
Example 3
Source Project: iceberg   File: ArrowVectorAccessors.java    License: Apache License 2.0 5 votes vote down vote up
@Override
final Decimal getDecimal(int rowId, int precision, int scale) {
  int dictId = offsetVector.get(rowId);
  if (cache[dictId] == null) {
    cache[dictId] = Decimal.apply(parquetDictionary.decodeToLong(dictId), precision, scale);
  }
  return cache[dictId];
}
 
Example 4
Source Project: iceberg   File: ArrowVectorAccessors.java    License: Apache License 2.0 5 votes vote down vote up
@Override
final Decimal getDecimal(int rowId, int precision, int scale) {
  int dictId = offsetVector.get(rowId);
  if (cache[dictId] == null) {
    cache[dictId] = Decimal.apply(parquetDictionary.decodeToInt(dictId), precision, scale);
  }
  return cache[dictId];
}
 
Example 5
Source Project: iceberg   File: RowDataReader.java    License: Apache License 2.0 5 votes vote down vote up
private static Object convertConstant(Type type, Object value) {
  if (value == null) {
    return null;
  }

  switch (type.typeId()) {
    case DECIMAL:
      return Decimal.apply((BigDecimal) value);
    case STRING:
      if (value instanceof Utf8) {
        Utf8 utf8 = (Utf8) value;
        return UTF8String.fromBytes(utf8.getBytes(), 0, utf8.getByteLength());
      }
      return UTF8String.fromString(value.toString());
    case FIXED:
      if (value instanceof byte[]) {
        return value;
      } else if (value instanceof GenericData.Fixed) {
        return ((GenericData.Fixed) value).bytes();
      }
      return ByteBuffers.toByteArray((ByteBuffer) value);
    case BINARY:
      return ByteBuffers.toByteArray((ByteBuffer) value);
    default:
  }
  return value;
}
 
Example 6
Source Project: iceberg   File: ArrowVectorAccessors.java    License: Apache License 2.0 4 votes vote down vote up
@Override
final Decimal getDecimal(int rowId, int precision, int scale) {
  return Decimal.apply(vector.getObject(rowId), precision, scale);
}
 
Example 7
Source Project: iceberg   File: SparkParquetReaders.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public Decimal read(Decimal ignored) {
  return Decimal.apply(column.nextInteger(), precision, scale);
}
 
Example 8
Source Project: iceberg   File: SparkParquetReaders.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public Decimal read(Decimal ignored) {
  return Decimal.apply(column.nextLong(), precision, scale);
}
 
Example 9
Source Project: iceberg   File: SparkValueReaders.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public Decimal read(Decoder decoder, Object reuse) throws IOException {
  byte[] bytes = bytesReader.read(decoder, null);
  return Decimal.apply(new BigDecimal(new BigInteger(bytes), scale));
}
 
Example 10
Source Project: iceberg   File: StructInternalRow.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public Decimal getDecimal(int ordinal, int precision, int scale) {
  return Decimal.apply(struct.get(ordinal, BigDecimal.class));
}
 
Example 11
Source Project: iceberg   File: SparkParquetReaders.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public Decimal read(Decimal ignored) {
  return Decimal.apply(column.nextInteger(), precision, scale);
}
 
Example 12
Source Project: iceberg   File: SparkParquetReaders.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public Decimal read(Decimal ignored) {
  return Decimal.apply(column.nextLong(), precision, scale);
}
 
Example 13
Source Project: iceberg   File: SparkValueReaders.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public Decimal read(Decoder decoder, Object reuse) throws IOException {
  byte[] bytes = bytesReader.read(decoder, null);
  return Decimal.apply(new BigDecimal(new BigInteger(bytes), scale));
}