Java Code Examples for org.apache.orc.TypeDescription#getScale()

The following examples show how to use org.apache.orc.TypeDescription#getScale() . 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: ORCSchemaUtil.java    From iceberg with Apache License 2.0 6 votes vote down vote up
private static Optional<TypeDescription> getPromotedType(Type icebergType,
                                                         TypeDescription originalOrcType) {
  TypeDescription promotedOrcType = null;
  if (Type.TypeID.LONG.equals(icebergType.typeId()) &&
      TypeDescription.Category.INT.equals(originalOrcType.getCategory())) {
    // Promote: int to long
    promotedOrcType = TypeDescription.createLong();
  } else if (Type.TypeID.DOUBLE.equals(icebergType.typeId()) &&
      TypeDescription.Category.FLOAT.equals(originalOrcType.getCategory())) {
    // Promote: float to double
    promotedOrcType = TypeDescription.createDouble();
  } else if (Type.TypeID.DECIMAL.equals(icebergType.typeId()) &&
      TypeDescription.Category.DECIMAL.equals(originalOrcType.getCategory())) {
    // Promote: decimal(P, S) to decimal(P', S) if P' > P
    Types.DecimalType newDecimal = (Types.DecimalType) icebergType;
    if (newDecimal.scale() == originalOrcType.getScale() &&
        newDecimal.precision() > originalOrcType.getPrecision()) {
      promotedOrcType = TypeDescription.createDecimal()
          .withScale(newDecimal.scale())
          .withPrecision(newDecimal.precision());
    }
  }
  return Optional.ofNullable(promotedOrcType);
}
 
Example 2
Source File: SparkOrcReader.java    From iceberg with Apache License 2.0 5 votes vote down vote up
static Converter buildConverter(BufferHolder holder, TypeDescription schema) {
  switch (schema.getCategory()) {
    case BOOLEAN:
      return new BooleanConverter();
    case BYTE:
      return new ByteConverter();
    case SHORT:
      return new ShortConverter();
    case DATE:
    case INT:
      return new IntConverter();
    case LONG:
      return new LongConverter();
    case FLOAT:
      return new FloatConverter();
    case DOUBLE:
      return new DoubleConverter();
    case TIMESTAMP:
      return new TimestampConverter();
    case DECIMAL:
      if (schema.getPrecision() <= Decimal.MAX_LONG_DIGITS()) {
        return new Decimal18Converter(schema.getPrecision(), schema.getScale());
      } else {
        return new Decimal38Converter(schema.getPrecision(), schema.getScale());
      }
    case BINARY:
    case STRING:
    case CHAR:
    case VARCHAR:
      return new BinaryConverter(holder);
    case STRUCT:
      return new StructConverter(holder, schema);
    case LIST:
      return new ListConverter(holder, schema);
    case MAP:
      return new MapConverter(holder, schema);
    default:
      throw new IllegalArgumentException("Unhandled type " + schema);
  }
}
 
Example 3
Source File: GenericOrcWriter.java    From iceberg with Apache License 2.0 4 votes vote down vote up
Decimal18Converter(TypeDescription schema) {
  this.scale = schema.getScale();
}
 
Example 4
Source File: SparkOrcWriter.java    From iceberg with Apache License 2.0 4 votes vote down vote up
Decimal18Converter(TypeDescription schema) {
  precision = schema.getPrecision();
  scale = schema.getScale();
}
 
Example 5
Source File: SparkOrcWriter.java    From iceberg with Apache License 2.0 4 votes vote down vote up
Decimal38Converter(TypeDescription schema) {
  precision = schema.getPrecision();
  scale = schema.getScale();
}
 
Example 6
Source File: SparkOrcWriter.java    From iceberg with Apache License 2.0 4 votes vote down vote up
Decimal18Converter(TypeDescription schema) {
  precision = schema.getPrecision();
  scale = schema.getScale();
}
 
Example 7
Source File: SparkOrcWriter.java    From iceberg with Apache License 2.0 4 votes vote down vote up
Decimal38Converter(TypeDescription schema) {
  precision = schema.getPrecision();
  scale = schema.getScale();
}