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

The following examples show how to use org.apache.orc.TypeDescription#getPrecision() . 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: SparkOrcWriter.java    From iceberg with Apache License 2.0 5 votes vote down vote up
private static Converter buildConverter(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 BINARY:
      return new BytesConverter();
    case STRING:
    case CHAR:
    case VARCHAR:
      return new StringConverter();
    case DECIMAL:
      return schema.getPrecision() <= 18 ?
          new Decimal18Converter(schema) :
          new Decimal38Converter(schema);
    case TIMESTAMP_INSTANT:
      return new TimestampTzConverter();
    case STRUCT:
      return new StructConverter(schema);
    case LIST:
      return new ListConverter(schema);
    case MAP:
      return new MapConverter(schema);
  }
  throw new IllegalArgumentException("Unhandled type " + schema);
}
 
Example 3
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 4
Source File: SparkOrcWriter.java    From iceberg with Apache License 2.0 5 votes vote down vote up
private static Converter buildConverter(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 BINARY:
      return new BytesConverter();
    case STRING:
    case CHAR:
    case VARCHAR:
      return new StringConverter();
    case DECIMAL:
      return schema.getPrecision() <= 18
          ? new Decimal18Converter(schema)
          : new Decimal38Converter(schema);
    case TIMESTAMP:
      return new TimestampConverter();
    case STRUCT:
      return new StructConverter(schema);
    case LIST:
      return new ListConverter(schema);
    case MAP:
      return new MapConverter(schema);
  }
  throw new IllegalArgumentException("Unhandled type " + schema);
}
 
Example 5
Source File: GenericOrcWriter.java    From iceberg with Apache License 2.0 4 votes vote down vote up
private static Converter buildConverter(TypeDescription schema) {
  switch (schema.getCategory()) {
    case BOOLEAN:
      return new BooleanConverter();
    case BYTE:
      return new ByteConverter();
    case SHORT:
      return new ShortConverter();
    case DATE:
      return new DateConverter();
    case INT:
      return new IntConverter();
    case LONG:
      String longAttributeValue = schema.getAttributeValue(ORCSchemaUtil.ICEBERG_LONG_TYPE_ATTRIBUTE);
      ORCSchemaUtil.LongType longType = longAttributeValue == null ? ORCSchemaUtil.LongType.LONG :
          ORCSchemaUtil.LongType.valueOf(longAttributeValue);
      switch (longType) {
        case TIME:
          return new TimeConverter();
        case LONG:
          return new LongConverter();
        default:
          throw new IllegalStateException("Unhandled Long type found in ORC type attribute: " + longType);
      }
    case FLOAT:
      return new FloatConverter();
    case DOUBLE:
      return new DoubleConverter();
    case BINARY:
      String binaryAttributeValue = schema.getAttributeValue(ORCSchemaUtil.ICEBERG_BINARY_TYPE_ATTRIBUTE);
      ORCSchemaUtil.BinaryType binaryType = binaryAttributeValue == null ? ORCSchemaUtil.BinaryType.BINARY :
          ORCSchemaUtil.BinaryType.valueOf(binaryAttributeValue);
      switch (binaryType) {
        case UUID:
          return new UUIDConverter();
        case FIXED:
          return new FixedConverter();
        case BINARY:
          return new BytesConverter();
        default:
          throw new IllegalStateException("Unhandled Binary type found in ORC type attribute: " + binaryType);
      }
    case STRING:
    case CHAR:
    case VARCHAR:
      return new StringConverter();
    case DECIMAL:
      return schema.getPrecision() <= 18 ? new Decimal18Converter(schema) : new Decimal38Converter(schema);
    case TIMESTAMP:
      return new TimestampConverter();
    case TIMESTAMP_INSTANT:
      return new TimestampTzConverter();
    case STRUCT:
      return new StructConverter(schema);
    case LIST:
      return new ListConverter(schema);
    case MAP:
      return new MapConverter(schema);
  }
  throw new IllegalArgumentException("Unhandled type " + schema);
}
 
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();
}
 
Example 8
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 9
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();
}